# 3d - z rotation question!

**URL:** https://forum.kirupa.com/t/3d-z-rotation-question/183157
**Category:** flash
**Created:** [March 24, 2006, 7:56am UTC](https://forum.kirupa.com/t/3d-z-rotation-question/183157 "2006-03-24T07:56:02Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![aBnest](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/abnest/32/2177_2.png) [@aBnest](https://forum.kirupa.com/u/aBnest)
#### Post date: [March 24, 2006, 7:56am UTC](https://forum.kirupa.com/t/3d-z-rotation-question/183157/1 "2006-03-24T07:56:02Z")

</div>

i’ve been working with Senocular’s tutorial for 3D scripting :  
[http://www.kirupa.com/developer/actionscript/faces\_depths.htm](http://www.kirupa.com/developer/actionscript/faces_depths.htm)

//great work, by the way  
I made a drag function for it :)… My question is how to change the code  
to actualy rotate on the z axis of the cube …  
In his tutorial the cube rotates around the z axis of the stage no matter how other axis are rotated.  
I think the part of the code that needs to be changed in order to simulate a more realistic rotation on z axis is :  
// perform the rotations around each axis  
// rotation around x  
xy = cx_y - sx_z;  
xz = sx_y + cx_z;  
// rotation around y  
yz = cy_xz - sy_x;  
yx = sy_xz + cy_x;  
// rotation around z  
zx = cz_yx - sz_xy;  
zy = sz_yx + cz_xy;  
but i never been very good with trigonometry ! and I AM a newbe!:crazy:  
Can anyone help me with this please!:esmirk: [SIZE=2][/SIZE][SIZE=2]**[SIZE=3][/SIZE]**[/SIZE]

---

<div class="post-metadata">

### Author: ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)
#### Post date: [March 24, 2006, 8:33am UTC](https://forum.kirupa.com/t/3d-z-rotation-question/183157/2 "2006-03-24T08:33:43Z")

</div>

rotation around z-axis:  
 ![](http://img145.imageshack.us/img145/502/zaxisrotation3gy.gif)

That’s assuming that the z-axis isn’t rotated, the ideas discussed here take into acount the rotation of the axis  
[http://www.kirupa.com/developer/actionscript/trig\_multiple\_axis.htm](http://www.kirupa.com/developer/actionscript/trig_multiple_axis.htm)

The code you posted also takes into account the rotation of the z-axis, excpet in those movies the z-axis is never rotated - add this code to the onEnterFrame function to rotate the z-axis with the up/down arrow keys:

```auto
cubeAxisRotations.z += (Key.isDown(Key.UP) - Key.isDown(Key.DOWN)) * 0.1;

```

---

<div class="post-metadata">

### Author: ![aBnest](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/abnest/32/2177_2.png) [@aBnest](https://forum.kirupa.com/u/aBnest)
#### Post date: [March 24, 2006, 9:02am UTC](https://forum.kirupa.com/t/3d-z-rotation-question/183157/3 "2006-03-24T09:02:59Z")

</div>

thanks but that does not help me! … already dit it … what i need is to rotate the z axis with the cube … in the tutorial the z axis is alwasy normal to the stage … my question is how to rotate the z axis ?

---

<div class="post-metadata">

### Author: ![aBnest](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/abnest/32/2177_2.png) [@aBnest](https://forum.kirupa.com/u/aBnest)
#### Post date: [March 24, 2006, 9:03am UTC](https://forum.kirupa.com/t/3d-z-rotation-question/183157/4 "2006-03-24T09:03:29Z")

</div>

thanks but that does not help me! … already dit it … what i need is to rotate the z axis with the cube … in the tutorial the z axis is alwasy normal to the stage … my question is how to rotate the z axis  
(my fault …wasn’t very clear in the first place!)

by the way : this is a nice place to lose some time [http://ghost.aesthetic.ru/index.htm](http://ghost.aesthetic.ru/index.htm)

so can you help me with this…?:pleased:

---

<div class="post-metadata">

### Author: ![aBnest](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/abnest/32/2177_2.png) [@aBnest](https://forum.kirupa.com/u/aBnest)
#### Post date: [March 24, 2006, 3:22pm UTC](https://forum.kirupa.com/t/3d-z-rotation-question/183157/5 "2006-03-24T15:22:01Z")

</div>

can someone PLEASE help… i tried the kirupa tutorial but i just don’t have enough trigonometry knowledge to this:

the code is something like this: (part of it…  
x = points\*.x;  
y = points\*.y;  
z = points\*.z;

```
    // perform the rotations around each axis
    // rotation around x
    xy = cx*y - sx*z;
    xz = sx*y + cx*z;
    // rotation around y
    yz = cy*xz - sy*x;
    yx = sy*xz + cy*x;
    // rotation around z
    zx = cz*yx - sz*xy;
    zy = sz*yx + cz*xy;

    // now determine perspective scaling factor
    // yz was the last calculated z value so its the
    // final value for z depth
    scaleRatio = focalLength/(focalLength + yz);
    // assign the new x, y and z
    x = zx*scaleRatio;
    y = zy*scaleRatio;
    // create transformed 2D point with the calculated values
    // adding it to the array holding all 2D points
    TransformedPointsArray* = make3DPoint(x, y, z);
}

```

but the z axis is ALWAYS perpendicular to the stage… i would realy apreciate if someone could help me ajust the code so that the z axis spins with the cube, because in some point i need to roate around the z axis

PLEASE… PLEASE HELP

---

<div class="post-metadata">

### Author: ![SiK](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@SiK](https://forum.kirupa.com/u/SiK)
#### Post date: [April 6, 2006, 1:18pm UTC](https://forum.kirupa.com/t/3d-z-rotation-question/183157/6 "2006-04-06T13:18:45Z")

</div>

I’m bumping into the same problem. What have you tried already?  
I spend at least one day on this problem. No luck so far.

---

<div class="post-metadata">

### Author: ![gvozden](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/gvozden/32/1084_2.png) [@gvozden](https://forum.kirupa.com/u/gvozden)
#### Post date: [April 6, 2006, 1:36pm UTC](https://forum.kirupa.com/t/3d-z-rotation-question/183157/7 "2006-04-06T13:36:49Z")

</div>

as far as I can see you don’t want then to rotate cube (you want to rotate AXIS) so basicly you want to rotate camera, not objects

---

<div class="post-metadata">

### Author: ![SiK](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@SiK](https://forum.kirupa.com/u/SiK)
#### Post date: [April 6, 2006, 1:49pm UTC](https://forum.kirupa.com/t/3d-z-rotation-question/183157/8 "2006-04-06T13:49:05Z")

</div>

Ok, but that means you have to move the camera too if you want to keep the camera focussed on the object.
