# Transformation Problem

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

## 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 on other sites
Haven't used Managed DirectX so not sure about the code part, but try converting your angles to radians. If I'm not wrong, DirectX uses radians for the rotation functions.

I didn't understand why you are multiplying with the ballPostition translation. Are you translating the entire cue to the position of the ball? You are already translating the cue to the cue.Position in the Matrix.Transformation function. Maybe I've it wrong....

##### Share on other sites
My angles are in radians, as far as I can tell. Also, I'm multiplying by the ball position because the cue is in cue-ball coordinates. I'm then multiplying by the actual cue coordinates.

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 12
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633723
• Total Posts
3013545
×