I have a square on
screen (2 triangles), and I'm experimenting with rotating the thing.
Rotating about the x and y axis works as expected (the thing spins
horizontally and vertically), but when I rotate it about the z-axis, it
goes up and down, deforms a bit, and just looks weird.
As for how I'm doing it right now, I'm using Matrix.RotationYawPitchRoll(x, y, z) to get my rotation matrix.

Rotation about the z-axis...
Steve Pontello
We need to see your Perpective Matrix setting and your View Matrix Setting
Maybe you are in orthogonal mode...
Pomi
Brian Laws
Are you using transformed co-ordinates My mistake, I see that you are, unless it’s a miss-type. You don’t need to mess world and view matrices, since it’s already in screen space, the top left corner of the screen is (0,0), just like using Window’s co-ordinates system. Try the PositionTextured instead, leave the transformed stuff for backdrops and the like.
BennyBunny
Thomas089
I would say it’s when you’re trying to centre your object. You want to factor this value into the translation at the end. For now forget the scaling and rotation and play with translating, then start adjusting the values you pass for translating to find the centre, the bottom centre, etc… It won’t take long and after combine the rotation and scaling.
The thing to keep in mind is about space. You have the object’s space, it has it’s own (x,y,z) co-ordinates, but the actual object itself can be off-centre to these. Then you have the world space which is where you’re placing the object’s (x,y,z), it’s these co-ordinates that you’re adjusting to bring the object into line with the world. Then you have the view space, which orients the world with respect to the viewer. The thing with this space is that the viewer is always in the centre and it’s the world that moves around it. Think of it this way, if your heads the viewer (camera) and your out-stretched hand is the world, if you want to move the view to the left in reality you’re moving the world to the right. Then you have the screen space (projection), which basically squishes everything to fit nicely on the screen.
Antonio_Taganini
Alex Krawarik
You could try to let DirectX handle the matrix transformations by setting your matrix on the device as the world matrx, by calling d.Transform.World = getMatrix(); This call will replace the temp transformation of the original geometry and you can just have it draw your original geometry vertices in the DrawUserPrimitives call (which will remain unchanged by this). I'm not entirely sure why you would want to apply the transformation yourself, but by letting DirectX handle it you can at least verify that the matrix itself is correct.
Other than that, you could try using the * operator instead of the Multiply() method to multiply the matrices, like this:
return center * rotation * translation * scaling;
It shouldn't make a difference, but I've seen some strange things with this before, so it might be worth a shot. If all else fails, you could also try applying only the rotation matrix to verify if the problem is caused by that one or by another matrix. I noticed you're using height / 2 etc, which may be an int/int fraction and cause undesired results (99/100=0 for example) so using one float term ( height / 2f ) might be a safer approach.
Hope this helps :)
valef
balajikoturu
public Matrix getMatrix()
{
Matrix center = Matrix.Translation(-width/2, -height/2, 0);
Matrix scaling = Matrix.Scaling(scale, scale, scale);
Matrix rotation = Matrix.RotationYawPitchRoll(yaw, pitch, roll);
Matrix translation = Matrix.Translation(pos_x, pos_y, pos_z);
return center * scaling * rotation * translation;
}
public void draw(Device d)
{
d.SetTransform(TransformType.World, getMatrix());
d.SetTexture(0, texture);
d.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, geometry);
}
Am I doing something really, really wrong here or something
rmicro1
Seriously, I'm starting to lose hope here. How hard can it be to have 2 polygons rotate... T_T
RabJ
mike2281
micTronic
A K
public Matrix getMatrix()
{
Matrix matrix;
Matrix center = Matrix.Translation((float)(-width / 2), (float)(-height / 2), 0);
Matrix rotation = Matrix.RotationYawPitchRoll(rotation_x, rotation_y, rotation_z);
Matrix translation = Matrix.Translation(pos_x + width / 2, pos_y + height / 2, pos_z);
Matrix scaling = Matrix.Scaling(scale, scale, scale);
matrix = Matrix.Multiply(center, rotation);
matrix = Matrix.Multiply(matrix, translation);
matrix = Matrix.Multiply(matrix, scaling);
return matrix;
}
I think the variables are named relevantly enough for you guys to know what I'm doing.
My draw method looks like this (and I'm sure there's better ways to do this):
public void Draw(Device d)
{
CustomVertex.TransformedTextured[] temp_geometry = new CustomVertex.TransformedTextured[geometry.Length];
geometry.CopyTo(temp_geometry, 0);
// set geometry position, scale and orientation
Matrix m = getMatrix();
for(int i = 0; i < temp_geometry.Length; i++)
{
temp_geometry
temp_geometry
temp_geometry
temp_geometry
temp_geometry
temp_geometry
temp_geometry
temp_geometry
temp_geometry
}
d.SetTexture(0, texture);
d.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, temp_geometry);
}