• ### What is your GameDev Story?

#### Archived

This topic is now archived and is closed to further replies.

# Please Cure My Imminent Baldness

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

## Recommended Posts

Can anyone help a newbie with a hair-tearing-out problem? I have a series of vertices stored as ''local'' co-ords i.e. relative to some point in 3D space. I can rotate these points about their local origin etc and translate them about my viewpoint (fixed at 0,0,0) but can''t seem to rotate them about the viewpoint The points are stored in a struct like so float x, y , z; // co-ordinates relative to..... float gx, gy, gz // the position in 3D space So one vertex might be at (x,y,z) (-100, -100, 0) relative to the ''objects'' global position (gx,gy,gz) (1000, 2000, 3000). so translating is just a case of moving the ''local origin'' (i.e. global position) gx,gy,gz. I can ''X rotate'' the object around it''s local origin using... tempy = polyface[n].vert[loop].y * cosval - polyface[n].vert[loop].z * sinval; tempz = polyface[n].vert[loop].y * sinval + polyface[n].vert[loop].z * cosval; etc but can''t seem to X rotate around the viewpoint. My brain tells me to add the position of the object to each local co-ordinate to obtain an ''absolute value'', roate that around (0,0,0), rotate the local origin by the same amount then subtract the new position from each vertex to obtain the new relative position. Is this the way to go or am I missing something really basic? Each time I try this method I end up with some sort of ''precession'' or wobbling around an axis. Help! I''m going bald! TIA Paul

##### Share on other sites
This would be helpful to me too, I guess the question is how do you change an object's rotational axis. I know that there's a DXutility function, but does anybody know how to chnage a matrix's rotation axis?

Edited by - Chrono999 on February 17, 2001 4:14:31 PM

##### Share on other sites
Chrono

Well this is what I''ve got...
An ''object'' at world co-ordinates say 0,0,1000 (ox,oy,oz)
The camera at 0,0,0 (x,y,z)
Vertices of the object (vx,vy,vz) stored relative to (ox,oy,oz) e.g. (-50,-50,-50)
To do x axis rotation of the object itself (i.e. around it''s own origin is just...

tempy = vy*cos(angle) - vz*sin(angle);
tempz = vz*cos(angle) - vy*sin(angle);
vy = tempy;
vz = tempz;

No problems there Now, if I moved my viewpoint down the object should rotate upwards (over my head as it were) i.e. around the x axis. I figured converting each vertex co-ord to a world co-ord then rotating should do the trick like so...

wy = oy + vy;
wz = oz + vz;

tempy = wy*cos(angle) - wz*sin(angle);
tempz = wz*cos(angle) - wy*sin(angle);
wy = tempy;
wz = tempz;

wy and wz are the new world co-ords of the vertex but they need to be converted back to object co-ords and this is the problem! One thing I haven''t done there is rotate the objects world position (it''s origin) so I can do that now using the same formula. Right, I now have the objects position and each vertex''s position in world co-ords. To convert to object co-ords surely I just subtract the object''s world position from each co-ord? e.g. if a vertex is now at 25,12,1010 and the object is at 0,8,1020 the object co-ord must be ... 25, 4, -10. Problem is it doesn''t appear to work Arrgghhhh!!

Paul

##### Share on other sites
Tensai,

(transform a)
If you want to rotate objects around their origin in world space first rotate your objects vertices around the origin in local space then transform them to the world (by adding the location of the object's origin in world space to each rotated vertex).

(transform b)
If you want to rotate objects around the camera (as if you are looking around), perform any local rotations that are required (eg. transform a), then convert the objects vertices from world space to camera space. This is done by (1) subtracting the camera position from the vertices (2) Taking the camera's current orientation (eg. yaw, pitch, roll) and rotating your object's vertices by the inverse of this. The reason it is the inverse is that if you rotate the camera to the right (which represents an increase in yaw) you want your objects to rotate in the opposite direction.

Tell me if you need further explanation.
Paulcoz.

Edited by - paulcoz on February 20, 2001 1:35:47 AM

##### Share on other sites
Hi paulcoz!

Thanks for that. It looks like i''m doing the right sort of thing - I think I have a gremlin somewhere though - if I perform a full 360 deg camera centred rotation objects are coming back into view at strange orientations Just need to track it down.....

BTW maybe you can help with another small problem? My normals don''t seem to be working quite right (!) I understand I need vertices in anti-clock order but which way is that in a surface parallel to the z-x plane?? Do I take anticlock looking towards the object''s centre (local origin) or looking from the object''s centre? (It can''t be from the camera if the surface is ''edge on'' can it?

Thanks again

Paul.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 9
• 9
• 34
• 16
• ### Forum Statistics

• Total Topics
634123
• Total Posts
3015654
×