MCPcopy Create free account
hub / github.com/cocos/cocos-engine / transformReflectionCamera

Method transformReflectionCamera

native/cocos/scene/ReflectionProbe.cpp:126–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124}
125
126void ReflectionProbe::transformReflectionCamera(const Camera* sourceCamera) {
127 float offset = Vec3::dot(_node->getWorldPosition(), _node->getUp());
128 _cameraWorldPos = reflect(sourceCamera->getNode()->getWorldPosition(), _node->getUp(), offset);
129 _cameraNode->setWorldPosition(_cameraWorldPos);
130
131 _forward = Vec3::FORWARD;
132 _forward.transformQuat(sourceCamera->getNode()->getWorldRotation());
133 _forward = reflect(_forward, _node->getUp(), 0);
134 _forward.normalize();
135 _forward *= -1;
136
137 _up = Vec3::UNIT_Y;
138 _up.transformQuat(sourceCamera->getNode()->getWorldRotation());
139 _up = reflect(_up, _node->getUp(), 0);
140 _up.normalize();
141
142 Quaternion::fromViewUp(_forward, _up, &_cameraWorldRotation);
143 _cameraNode->setWorldRotation(_cameraWorldRotation);
144 _camera->update(true);
145
146 // Transform the plane from world space to reflection camera space use the inverse transpose matrix
147 Vec4 viewSpaceProbe{ _node->getUp().x, _node->getUp().y, _node->getUp().z, -Vec3::dot(_node->getUp(), _node->getWorldPosition())};
148 Mat4 matView = _camera->getMatView();
149 matView.inverse();
150 matView.transpose();
151 matView.transformVector(&viewSpaceProbe);
152 _camera->calculateObliqueMat(viewSpaceProbe);
153}
154
155Vec3 ReflectionProbe::reflect(const Vec3& point, const Vec3& normal, float offset) {
156 Vec3 n = normal;

Callers

nothing calls this directly

Calls 15

getWorldPositionMethod · 0.80
getUpMethod · 0.80
getWorldRotationMethod · 0.80
transformVectorMethod · 0.80
getNodeMethod · 0.65
updateMethod · 0.65
dotFunction · 0.50
reflectFunction · 0.50
setWorldPositionMethod · 0.45
transformQuatMethod · 0.45
normalizeMethod · 0.45
setWorldRotationMethod · 0.45

Tested by

no test coverage detected