Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From a quick glance, it would be best to create your Quaternions using a static create method such as <code>Quaternion.CreateFromAxisAngle(Vector3. UnitY, rotation)</code>. The values of X,Y,Z and W of a Quaternion do not relate to position in any way. The handy static methods take care of the tricky math.</p> <p>In your situation it appears as though you want to keep the frustum pointing at the same side of the box as the box rotates, therefore rotating the frustum about the box. This requires a slightly different approach to the translation done in your draw method.</p> <p>In order to rotate an object about another, you first need to translate the object so that the centre of the desired rotation is at the origin. Then rotate the object and translate it back by the same amount as the first step.</p> <p>So in you situation, something like this should do it (untested example code to follow);</p> <pre><code>// Construct the objects boxObject.Position = new Vector3(10, 10, 10); boxObject.Rotation = 45.0f; frustumObject.Position = new Vector3(0, 0, 50f); // Note: this will be relative to the box (makes the math a bit simpler) frustumObject.TargetPosition = boxObject.Position; frustumObject.ModelRotation = Quaternion.CreateFromAxisAngle(Vector3. UnitY, boxObject.Rotation); // Note: this rotation angle may need to be in radians. // Box Draw() // Draw the box at its position, rotated about its centre. myEffect.World = transforms[myMesh.ParentBone.Index] * Matrix.CreateTranslation(Position) * Matrix.CreateRotationY(Rotation); // Frustum Draw() // Draw the frustum facing the box and rotated about the boxes centre. myEffect.World = transforms[myMesh.ParentBone.Index] * Matrix.CreateTranslation(Position) * Matrix.CreateFromQuaternion(ModelRotation) * Matrix.CreateTranslation(TargetPosition); </code></pre> <p><em>Assumptions:</em></p> <ul> <li><em>The box rotates about its own centre</em></li> <li><em>The frustum stays facing the box and rotates around the boxes centre</em></li> </ul> <p>Hope this helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload