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

Method GetPerObjectData

trinity/Eve/SpaceObject/Children/EveChildCloud.cpp:362–418  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

360}
361
362Tr2PerObjectData* EveChildCloud::GetPerObjectData( ITriRenderBatchAccumulator* accumulator )
363{
364 EveChildCloudPerObjectData* data = accumulator->Allocate<EveChildCloudPerObjectData>();
365
366 if( !data )
367 {
368 return NULL;
369 }
370
371 data->m_data.m_world = Transpose( m_worldTransform );
372
373 Matrix worldView = m_worldTransform * Tr2Renderer::GetViewTransform();
374 data->m_data.m_worldView = Transpose( worldView );
375
376 Matrix worldViewProjection = m_worldTransform * Tr2Renderer::GetViewTransform() * Tr2Renderer::GetProjectionTransform();
377
378 Matrix worldViewTransposed = Transpose( worldView );
379 Vector4 nearPlane( 0.f, 0.f, -1.f, -Tr2Renderer::GetFrontClip() );
380 data->m_data.m_nearPlaneLocal = Transform( nearPlane, worldViewTransposed );
381
382 Matrix worldViewInv = Inverse( worldView );
383 data->m_data.m_worldViewInv = Transpose( worldViewInv );
384 data->m_data.m_eyePosLocal = TransformCoord( Vector3( 0.f, 0.f, 0.f ), worldViewInv );
385
386 const float fakeNearPlane = 500;
387 // We modify the original projection matrix by changing clip planes to avoid precision problems
388 Matrix fakeProjection = Tr2Renderer::GetProjectionTransform();
389 fakeProjection._33 = -1;
390 fakeProjection._43 = -fakeNearPlane * 2;
391 data->m_data.m_projectionInv = Transpose( Inverse( fakeProjection ) );
392
393 data->m_data.m_screenDepth = TransformCoord( Vector3( 0.f, 0.f, 0.f ), worldViewProjection ).z;
394
395 AxisAlignedBoundingBox box;
396 GetProjectedCubeBounds( box, m_worldTransform * Tr2Renderer::GetViewTransform(), fakeProjection, 1, m_min, m_max );
397
398 data->m_data.m_screenSize.x = box.m_min.x;
399 data->m_data.m_screenSize.y = box.m_min.y;
400 data->m_data.m_screenSize.z = box.m_max.x;
401 data->m_data.m_screenSize.w = box.m_max.y;
402
403 unsigned w, h;
404 Tr2Renderer::GetBackBufferDimensions( w, h );
405 float x = ( box.m_max.x - box.m_min.x ) * w;
406 float y = ( box.m_max.y - box.m_min.y ) * w;
407 float size = std::max( x, y ) / m_preTesselationLevel;
408 size /= m_lastLodFactor;
409
410 m_currentIB = 0;
411 while( size < m_cellScreenSize && m_currentIB + 1 < m_indexBuffers.size() )
412 {
413 size *= 2;
414 m_currentIB += 1;
415 }
416
417 return data;
418}
419

Callers

nothing calls this directly

Calls 7

TransposeFunction · 0.85
GetViewTransformFunction · 0.85
GetProjectionTransformFunction · 0.85
GetFrontClipFunction · 0.85
GetProjectedCubeBoundsFunction · 0.85
sizeMethod · 0.80
Vector3Class · 0.50

Tested by

no test coverage detected