# Rotating each point of 3d model without Matricies

Hi Forumers,

I am trying to utilize my Geometry knowledge and use it to study 3d engines.

I want to, all in wire-frame,
-Load a 3d model (done)
-Draw a 3d model (done)
-Rotate a 3d model around its own origin

My problem is after I load a model (faces and verts), and I want to rotate it using math the whole thing rotates. As in, it moves in a circle around the center of the world and the model itself doesn’t rotate.

So, I think I would have to shift the points individually with their own Sin() and Cos() functions, however I try this and still, the whole model just moves in a circle around the worlds origin.

For now, I am just trying to rotate around the Z axis.

(moves in circle around world origin)
x += System.Math.Cos((ObjectRotZ * Math.PI / 180))
y += System.Math.Sin((ObjectRotZ * Math.PI / 180))

(Shrinks the whole object to nothing)
x *= System.Math.Cos((ObjectRotZ * Math.PI / 180))
y *= System.Math.Sin((ObjectRotZ * Math.PI / 180))

ObjectRotZ being a variable that changes according to Left and Right key-presses.

Anyone have an idea?

I can feel its something obvious, I just hate that feeling.

To do step 3, you need to:

1. Translate the model origin to the coordinate origin (0,0,0)
2. Rotate around the coordinate origin
3. Translate the coordinate origin back to the model origin

(moves in circle around world origin)
x += System.Math.Cos((ObjectRotZ * Math.PI / 180))
y += System.Math.Sin((ObjectRotZ * Math.PI / 180))

Since you’re focusing on the math side, recall what the definition of cosine and sine functions are. Unit circle centered on the coordinate origin (0,0,0) in the XY plane.

So if you want a circle centered on a different point, you conceptually have to move it to (0,0,0) first to use cos/sin to define it. Then shift it back.

Hope this makes sense.

The model never moves from the origin. That’s what doesn’t make sense to me.
If it helps:
the above is part of the draw point function. (I’m drawing verts to see if they rotate correctly) when I draw, like I said they all just move togeather. This function is passed a point. It’s rotated at origin then drawed.

Hey! All points will be added to the same numbers which explains why they move togeather. Considering rotate ( for the model) is same for each vertex.

Guess it wasn’t simple. How in the world do I fix this? Since i have x,y moving by degrees rather than degrees creating x and y points?

Simplified, my function needs to :
get the 2 points
rotates them around origon by degrees
returns the new points

( if it was 1 point it would work. but it won’t for multiple) guess each point might need it’s own degree+model degree?

Anyone have an idea? This has been killing me.

You aren’t using the correct equations to rotate your vertices.

You need to do something like:

``````
ang = ObjectRotZ * PI / 180.0;  //ObjectRotZ is CCW rotation in degrees.
x_rot = x * cos (ang) - y * sin (ang);
y_rot = y * cos (ang) + x * sin (ang);

``````