MCPcopy Create free account
hub / github.com/carbonengine/trinity / PrepareRender

Method PrepareRender

trinity/Eve/EveLensflare.cpp:192–266  ·  view source on GitHub ↗

-------------------------------------------------------------------------------- Description: Is a lot like ::Update but needs the current frame's frustum! Basiclly calculates the transform for the billboard geomtry to become a 2d sprite. Calculation itself is a little bit strange, but totally EVE legacy! Arguments: frustum - the current view frustum of the current frame --------------------------

Source from the content-addressed store, hash-verified

190// frustum - the current view frustum of the current frame
191// --------------------------------------------------------------------------------
192void EveLensflare::PrepareRender( const TriFrustum& frustum )
193{
194 // debug
195 if( !m_display )
196 {
197 return;
198 }
199
200 // calc direction to the sun (usually normalized m_position)
201 if( LengthSq( m_position ) == 0.f )
202 {
203 Vector3 curPos( 0.f, 0.f, 0.f );
204 curPos -= frustum.m_viewPos;
205 m_direction = Normalize( curPos );
206 }
207 else
208 {
209 Vector3 invPos = -m_position;
210 m_direction = Normalize( invPos );
211 }
212
213 Vector3 cameraSpacePos = frustum.m_viewDir * ( -1.f * m_cameraFactor );
214 cameraSpacePos += frustum.m_viewPos;
215
216 // build the matrix that will rotate the flares into position
217 // by using the position of the camera and the direction to the world pos
218 Vector3 negDirVec = -m_direction;
219 TriMatrixArcFromForward( &m_transform, &negDirVec );
220 m_transform._41 = cameraSpacePos.x;
221 m_transform._42 = cameraSpacePos.y;
222 m_transform._43 = cameraSpacePos.z;
223 m_transform._44 = 1.0f;
224
225 // pass important data to shader
226 m_directionVar = Vector4( m_direction, m_sunSize );
227
228 Vector4 direction( m_direction.x, m_direction.y, m_direction.z, 0 );
229 direction = Transform( direction, Tr2Renderer::GetViewTransform() );
230 direction = Transform( direction, frustum.m_projectionMatrix );
231 direction.x /= direction.w;
232 direction.y /= direction.w;
233 float distanceToEdge = 1 - std::min( 1 - std::abs( direction.x ), 1 - std::abs( direction.y ) );
234 float distanceToCenter = Length( *reinterpret_cast<Vector2*>( &direction ) );
235 float radialAngle = atan2( direction.y, direction.x ) + TRI_PI;
236
237 for( auto it = m_distanceToEdgeCurves.begin(); it != m_distanceToEdgeCurves.end(); ++it )
238 {
239 ( *it )->UpdateValue( distanceToEdge );
240 }
241
242 for( auto it = m_distanceToCenterCurves.begin(); it != m_distanceToCenterCurves.end(); ++it )
243 {
244 ( *it )->UpdateValue( distanceToCenter );
245 }
246
247 for( auto it = m_radialAngleCurves.begin(); it != m_radialAngleCurves.end(); ++it )
248 {
249 ( *it )->UpdateValue( radialAngle );

Callers 1

BeginRenderMethod · 0.80

Calls 9

LengthSqFunction · 0.85
TriMatrixArcFromForwardFunction · 0.85
GetViewTransformFunction · 0.85
LengthFunction · 0.85
Vector4Class · 0.50
beginMethod · 0.45
endMethod · 0.45
UpdateValueMethod · 0.45
CopyValueMethod · 0.45

Tested by

no test coverage detected