Jump to content
  • Advertisement
Sign in to follow this  
medis

rotation more times

This topic is 2608 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,
I'm new in 3D and i've got problem with rotation in SlimDX, Direct3D9, C#. I've got a cube and i rotate it (90 degree) with A key around x axle, S key around y axle and D key around z axle.
It works when i rotate the cube only around one axle(anyone), but after that i rotate around another axle it works strange. For example when i press A, it rotate around X axle 90 degree (good), then a press S, it rotate around Y axle 90 degree (good), then i press D, it rotate again Y around -90 degree (bad) and not around Z.
Here is my test:
(it need to be) -> (it was)

x y z -> x y -y
x z y -> x -y y
y x z -> y -z -y
y z x -> y x -z
z x y -> z x y
z y x -> z y -z

I've got a cube class with rotcubx, rotcuby, rotcubz attributes in degree.

I use them is world matrix with YawPitchRoll.


some codes:


if (e.KeyCode == Keys.A) {
rotcub[0] = 1;
rotcubanim[0] = 100;
}

In Render function



if (rotcub[0] == 1){
if (rotcubanim[0] == 0) {
rotcub[0] = 0;
}
else{
cube.setrotx(0.9f);
rotcubanim[0] = rotcubanim[0] - 1;
}
}

world = Matrix.RotationYawPitchRoll(cube.getroty() * rad, cube.getrotx() * rad, cube.getrotz() * rad) *
Matrix.Translation(cube.getpos());

In cube class:

public void setrotx(float x) {
rotcubx += x;
}



I can't understand why it work so strange, can anybody help me?
Sorry my english.

medis

Share this post


Link to post
Share on other sites
Advertisement
If I'm understanding what you want correctly, you'll need to ditch Euler angles and use another method to handle the rotations.

If the objective is to be able to rotate a cube about the world x, y, or z axis (relative to the cube's current orientation) at any time in 90-degree increments, then the method I recommend is as follows. Create an array (or similar container) that stores all 24 unique axis-aligned orientations, and then create a mapping that maps each orientation to its neighbor orientations as determined by rotation axis and rotation direction. You can then determine the new orientation for the cube in a deterministic fashion without having to worry about accumulated numerical error or anything like that.

Share this post


Link to post
Share on other sites

If I'm understanding what you want correctly, you'll need to ditch Euler angles and use another method to handle the rotations.

If the objective is to be able to rotate a cube about the world x, y, or z axis (relative to the cube's current orientation) at any time in 90-degree increments, then the method I recommend is as follows. Create an array (or similar container) that stores all 24 unique axis-aligned orientations, and then create a mapping that maps each orientation to its neighbor orientations as determined by rotation axis and rotation direction. You can then determine the new orientation for the cube in a deterministic fashion without having to worry about accumulated numerical error or anything like that.



What do you mean "[color="#1C2837"]24 unique axis-aligned orientations". x,y,z are 3, but why multiply with 8? The tip of cube?

Share this post


Link to post
Share on other sites

What do you mean "[color="#1C2837"]24 unique axis-aligned orientations". x,y,z are 3, but why multiply with 8? The tip of cube?

I mean that there are 24 ways you can orient a cube and still have it be axis-aligned.

Imagine a die or some other cubical object for which each face is visually distinct. Now imagine it positioned at the origin and axis-aligned (that is, its edges are parallel to the cardinal x, y, and z axes).

Clearly there are multiple orientations that meet these constraints. In fact, it can be shown that there are exactly 24 such orientations. These are the orientations to which I'm referring.

Share this post


Link to post
Share on other sites
Thx, the number of 24 was the key. When i rotate x than y is not equal rotate y than x, but in my version these was the same.

I was not solve the problem with Euler, just made two list, and add them the rotation (axel name and -1 or 1), then a repeat everything again with a for period.
I know, this is not the best way, but it works:)

the code for it:

Matrix rotat = Matrix.Identity;

for (int i = 0; i < cube.getMerre2().Count; i++)
{
if (cube.getMerre(i) == "x") { rotat = rotat * Matrix.RotationX(90 * cube.getIrany(i) * rad); }
if (cube.getMerre(i) == "y") { rotat = rotat * Matrix.RotationY(90 * cube.getIrany(i) * rad); }
if (cube.getMerre(i) == "z") { rotat = rotat * Matrix.RotationZ(90 * cube.getIrany(i) * rad); }
}

if (rotcub[0] == 1)
{
if (rotcubanim[0] == 0)
{
cube.addMerre("x");
cube.addIrany(1);
}
else
{
float g = 101 - rotcubanim[0];
rotat = rotat * Matrix.RotationX(0.9f*rad*g);
}

world = rotat * Matrix.Translation(cube.getpos());


Thanks for all.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!