# Dot product of world coordinates?

Hi!
Since this is my first post I might as well introduce myself. I’m currently in the third year of a master’s program in media technology at the University of Linköping, Sweden. I’ve been programming for a couple of years, and right now I’m in the middle of creating some base classes for upcoming simulation projects.

So, the problem is this:
Currently I’ve set up a scene with a plane with a cube hovering over it. What I’d like to do is to calculate the dot product of the center of the cube and the plane’s normal. Both the plane and the cube are derived from a Shape-class. I want to implement the ‘getWorldCoordinates()’ for the shapes (or something like it). But I can’t get my head around how to do it. Since I don’t really know what I want myself, I found it hard to search any forums for it. I’m guessing it has to do with transforming to/from GL_MODELVIEW_MATRIX or something like it.

I appreciate any help!
Thanks!

Marcus

Best (and for OpenGL 3 the only way) is using your own matrix class for all matrix operations and only uploading them to OpenGL via glLoadMatrix calls.
Using this approach you have full control over your matricies and going from object to world space is as easy as a single matrix multiplication as you built the transform matricies for your objects yourself.

Since I don’t really know what I want myself

It is a shame, We can’t help you until you have well formulated your question.

What I’d like to do is to calculate the dot product of the center of the cube and the plane’s normal

dot product is calculated with 2 vectors. What is the “cube center” for you? The cube center position? In which space?

satan:
I guess that’s the best way to do. Just curious though, I’m not that familiar with 3.0 but what did they remove in order to make it the only way?

dot product is calculated with 2 vectors. What is the “cube center” for you? The cube center position? In which space?

Yes, that I am aware of. The cube is a unit cube with a center in (0,0,0)’. I want to be able to calculate the dot product so I know the distance between them in order to do some basic collision detection.

``````Cube c;
Plane p;

// Camera
glRotatef(5, 1, 0, 0);
glTranslatef(0,0,-5);

// Animation
glRotatef(t, 0,1,0);

// Draw the plane
glPushMatrix();
glTranslatef(0, -2, 0);
p.draw();
glPopMatrix();

// Draw the cube
glPushMatrix();
glScalef(0.5,0.5,0.5);
glTranslatef(0, 2, 0);
c.draw();
glPopMatrix();
``````

Since, Opengl 3.0 all fixed functions for vertex processing were removed and you have to program a vertex shader instead. So you need for example to set vertex data through vertex arrays and manage transformation matrices yourself.

Check out the OpenGL 3.0 spec for more details about that, especially the “Deprecation model” section, Appendix E, page 403.

Thanks for the tip! I’ll look into it!