| | 79 | #region Camera override stuff |
|---|
| | 80 | private Libx42.Tag cameraTag; |
|---|
| | 81 | public Libx42.Tag CameraTag |
|---|
| | 82 | { |
|---|
| | 83 | get { return cameraTag; } |
|---|
| | 84 | set |
|---|
| | 85 | { |
|---|
| | 86 | if( value != null && value.Owner != model.Model ) |
|---|
| | 87 | throw new ArgumentException( "Tag belongs to a different model." ); |
|---|
| | 88 | |
|---|
| | 89 | if( value == cameraTag ) |
|---|
| | 90 | return; |
|---|
| | 91 | |
|---|
| | 92 | cameraTag = value; |
|---|
| | 93 | |
|---|
| | 94 | pn3DCamera.Enabled = cameraTag == null; |
|---|
| | 95 | UpdateCameraModeMenu(); |
|---|
| | 96 | |
|---|
| | 97 | pn3D.Invalidate(); |
|---|
| | 98 | } |
|---|
| | 99 | } |
|---|
| | 100 | |
|---|
| | 101 | private void GetCameraMatrices( out Matrix view, out Matrix projection ) |
|---|
| | 102 | { |
|---|
| | 103 | if( cameraTag == null ) |
|---|
| | 104 | { |
|---|
| | 105 | view = pn3DCamera.ViewMatrix; |
|---|
| | 106 | projection = pn3DCamera.ProjectionMatrix; |
|---|
| | 107 | } |
|---|
| | 108 | else |
|---|
| | 109 | { |
|---|
| | 110 | Libx42.Math.Affine tagMat = modelDXData.Pose.TagMatrices[cameraTag.Index]; |
|---|
| | 111 | |
|---|
| | 112 | Vector3 o = Helpers.ConvertToDX( tagMat.TransformPoint( new Libx42.Math.Vector3( 0 ) ) ); |
|---|
| | 113 | Vector3 x = Helpers.ConvertToDX( tagMat.TransformPoint( new Libx42.Math.Vector3( 1, 0, 0 ) ) ); |
|---|
| | 114 | Vector3 y = Helpers.ConvertToDX( tagMat.TransformPoint( new Libx42.Math.Vector3( 0, 1, 0 ) ) ); |
|---|
| | 115 | Vector3 z = Helpers.ConvertToDX( tagMat.TransformPoint( new Libx42.Math.Vector3( 0, 0, 1 ) ) ); |
|---|
| | 116 | |
|---|
| | 117 | view = Matrix.LookAtRH( o, -x, y ); |
|---|
| | 118 | |
|---|
| | 119 | float zf = pn3DCamera.ZFar; |
|---|
| | 120 | float zn = pn3DCamera.ZNear; |
|---|
| | 121 | float aspect = pn3DCamera.AspectRatio; |
|---|
| | 122 | |
|---|
| | 123 | const float defFov = 45; |
|---|
| | 124 | const float DegToRad = (float)(Math.PI / 180.0); |
|---|
| | 125 | |
|---|
| | 126 | float fovX = defFov * Helpers.Clamp( Libx42.Math.Vector3.Length( tagMat.GetColumn( 2 ) ), 0.1F, 179.0F / defFov ); |
|---|
| | 127 | float fovY = defFov * Helpers.Clamp( Libx42.Math.Vector3.Length( tagMat.GetColumn( 1 ) ), 0.1F, 179.0F / defFov ); |
|---|
| | 128 | |
|---|
| | 129 | fovX *= DegToRad; |
|---|
| | 130 | fovY *= DegToRad; |
|---|
| | 131 | |
|---|
| | 132 | projection.M11 = 1.0F / ((float)Math.Tan( 0.5F * fovX ) * aspect); |
|---|
| | 133 | projection.M12 = 0; |
|---|
| | 134 | projection.M13 = 0; |
|---|
| | 135 | projection.M14 = 0; |
|---|
| | 136 | |
|---|
| | 137 | projection.M21 = 0; |
|---|
| | 138 | projection.M22 = 1.0F / (float)Math.Tan( 0.5F * fovY ); |
|---|
| | 139 | projection.M23 = 0; |
|---|
| | 140 | projection.M24 = 0; |
|---|
| | 141 | |
|---|
| | 142 | projection.M31 = 0; |
|---|
| | 143 | projection.M32 = 0; |
|---|
| | 144 | projection.M33 = zf / (zn - zf); |
|---|
| | 145 | projection.M34 = -1; |
|---|
| | 146 | |
|---|
| | 147 | projection.M41 = 0; |
|---|
| | 148 | projection.M42 = 0; |
|---|
| | 149 | projection.M43 = zn * zf / (zn - zf); |
|---|
| | 150 | projection.M44 = 0; |
|---|
| | 151 | |
|---|
| | 152 | //projection = Matrix.PerspectiveFovRH( 90, 1, pn3DCamera.ZNear, pn3DCamera.ZFar ); |
|---|
| | 153 | } |
|---|
| | 154 | } |
|---|
| | 155 | #endregion |
|---|
| | 156 | |
|---|