• Advertisement
Sign in to follow this  

Transformation Problem

This topic is 4738 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, guys. I'm using C# and Managed DX. Right now I'm making a pool game. However, I'm having trouble drawing the cue stick. A stick is a cylinder that runs along the Z-axis. The coordinates of the stick are in cue-ball coordinates. Cue.Position is where the butt of the cue is. Cue.Stick is a vector along the axis of the stick, from the butt to the tip. Of course, I'll have to rotate the Z-axis-aligned cylinder along a vector that is perpendicular to the cue.Stick vector that is projected on the ground. Hence
Vector3 axis = Vector3.Cross(cue.Stick,new Vector3(cue.Stick.X,cue.Stick.Y,0));
Next, how much do we rotate it by?
     /|
    / |
   /  |
  /   |
 /    |
-------
The diagonal is the cue. The height is cue.Position.Z. The length is cue.Stick.Length(). If theta is the bottom-left corner, theta = arcsin(cue.Position.Z/cue.Stick.Length()) because sin(theta) = opp/hyp. Then the angle of the top corner (which is the one I'm trying to rotate by is pi/2 - theta.
float angle = (float)Math.PI/2 - (float)Math.Asin(cue.Position.Z/cue.Stick.Length());
Now all that's left is to transform the cue Mesh, which is initially Z-aligned.
device.Transform.World = Matrix.Identity * Matrix.Translation(ballPosition) * 
				Matrix.Transformation(new Vector3(),new Quaternion(),
                                                      new Vector3(),new Vector3,
				                      Quaternion.RotationAxis(axis,angle),
                                                      cue.Position);
However, I can't even see the cue when I do this. I can't tell what I'm doing wrong. I mean I expect a couple mistakes in my math, but I can't see any part of the cue. I tried to simply draw a vertical cue and that works so I know my rendering code is OK. It's the transformation that's screwing it up. I can't tell for the life of me what's wrong with it. Please help. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
"A stick is a cylinder that runs along the Z-axis."
"Cue.Stick is a vector along the axis of the stick, from the butt to the tip."

so cue.Stick = <0.0, 0.0, 1.0> before any transforms right?

"Of course, I'll have to rotate the Z-axis-aligned cylinder along a vector that is perpendicular to the cue.Stick vector that is projected on the ground. Hence
Vector3 axis = Vector3.Cross(cue.Stick,new Vector3(cue.Stick.X,cue.Stick.Y,0));"

so axis = Vector3.Cross(<0.0, 0.0, 1.0>, <0.0, 0.0, 0.0>)?
something fishy there. give us some sample values if i misunderstood.

Share this post


Link to post
Share on other sites
I'm sorry, I wasn't very clear. Cue.Stick represents the cue as I want it to look, not as it is. So I want to transform the Z-aligned cylinder mesh to what is represented by Cue.Stick, basically.

For example, let's say that the butt of the cue is at (-5,2,6). I also have a readonly member called float length. Cue.Stick is a vector from (-5,2,6) to the point of impact, scaled to be of length length. Now I have to draw the cylinder and somehow transform it so it looks like it goes from (-5,2,6) towards the impactPoint.

[Edited by - yaroslavd on March 8, 2005 9:36:10 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement