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

Method CalculateProjectionMatrix

trinity/Eve/EveCamera.cpp:602–639  ·  view source on GitHub ↗

------------------------------------------------------------- Description: Sets up and assigns the desired projection to the matrix provided and passes it on to the projection if it's provided. Arguments: mat - the transform matrix that stores the result aspectRatio - the aspect ratio for this projection matrix fov - the desired field of view centerOffset - camera projection offset(horizontal offs

Source from the content-addressed store, hash-verified

600// projection - the TriProjection matrix to store the resulting matrix
601// -------------------------------------------------------------
602void EveCamera::CalculateProjectionMatrix( Matrix* mat, float aspectRatio, float fov, float offsetX, float offsetY, float front, float back, TriProjection* projection )
603{
604 if( !aspectRatio || !IsFinite( aspectRatio ) )
605 {
606 aspectRatio = 1;
607 }
608 if( !fov || !IsFinite( fov ) )
609 {
610 fov = 1;
611 }
612
613 // TODO: update TriProjection to do all this for us, having the aspect ratio correction as a value on the
614 // TriProjection itself rather than transmogrifying the matrix here.
615 float dX = aspectRatio * front * tan( fov / 2 );
616 float dY = front * tan( fov / 2 );
617
618 if( aspectRatio > 1.6f )
619 {
620 // The field of view in x is now too warped so we switch things around and
621 // adjust the matrix so that the fov in x doesn't go beyond what it would be
622 // at a 1.6 aspect ratio. Note that 1920/1200 = 1.6.
623 float adjustment = aspectRatio / 1.6f;
624 dX /= adjustment;
625 dY /= adjustment;
626 }
627 float left = -dX + dX * offsetX;
628 float right = dX + dX * offsetX;
629 float top = dY + dY * offsetY;
630 float bottom = -dY + dY * offsetY;
631 *mat = PerspectiveOffCenterMatrix( left, right, bottom, top, front, back );
632
633 if( projection )
634 {
635 // TODO: as per comment at the top here. Should call something like
636 // projection->OffCenterAspectAdjust(left, right, -dy, dy, front, back, aspectClamp(1.6 in this case))
637 projection->CustomProjection( (Matrix)*mat );
638 }
639}
640
641
642// -------------------------------------------------------------

Callers

nothing calls this directly

Calls 2

IsFiniteFunction · 0.85
CustomProjectionMethod · 0.80

Tested by

no test coverage detected