Rotating triangle in opengl from one point - opengl

Can someone please advise how to rotate a triangle from its top vertice?
I want to make multiple triangles in a fan to make a circle with a common middle point, the top vertice of the triangle.

You can rotate around a point by first translating with its inverse coordinate to the origin, then rotate by your angle and translate back to the reference point.
If you want to draw a circle consider using a triangle fan instead.

Related

opengl 3d object picking - raycast

I have a program displaying planes of cubes, like levels in a house, I have the planes displayed so that the display angle is consistent to the viewport projection plane. I would like to be able to allow the user to select them.
First I draw them relative to each other with the first square drawn at {0,0,0}
then I translate and rotate them, each plane has it's own rotate and translate.
Thanks to this this page I have code that can cast a ray using the user's last touch. If you notice in the picture above, there is a green square and blue square, this is debug graphic displaying the ray intersecting the near and far planes in the projection matrix after clicking in the centre (with z of zero in order to display them), so it appears to be working.
I can get a bounding box of the cube, but it's coordinates will think they are still up in the left corner.
My question is how do I use my ray to check intersections with the objects after they have been rotated and translated? I'm very confused as I once had this working when I was translating and rotating the whole grid as one, now each plane is being moved separately I can't work out how to do it.

finding axis rotation angles to go from one direction vector to another in directX/c++

I am working on building a game in c++ with directX, and I am trying to make my flashlight geometry rotate in the direction of the camera. Getting the light to rotate is easy because I can change the direction vector for the light equations.
I have the current direction vector the flashlight is is pointing, and the new direction vector for the way the camera is pointing. I need to be able to rotate the geometry to this direction.
How can I use the two direction vectors to calculate the amount of rotation around each axis necessary to get my flashlight to the correct orientation?
Thanks,
-Jake

Parallel plane in openGL

I'm working with OpenGL, I need to draw a plane in front of a triangle in the three dimensional space. So if one of the triangle points changes, the plane also changes
I have the 3 points, and using cross product, I can get the normal vector, so, to draw the plane, I only need to translate the triangle to the origin of the world in reference of one of the triangle points, translate a distance over the normal, rotate the normal angles in X, Y and Z, and draw the plane.
I need to know how to translate over the normal, and how to rotate the new plane, so, when one of the vertex changes, the normal changes, and the plane also changes.
As I understand, I can use the normal vector in glRotatef(angle, normal[x, y, z]), with angle =0. But the plane doesn't change when I change one of the triangle vertex.
OpenGl is not a scene graph. It will not deal with transforming objects for you. All OpenGL does is render what you tell it to render.
If you tell it to render a vertex (which YOU changed), and do not tell it to change the way it draws the plane, then of course the plane will not change.
Look into scene graphs, and how to do matrix and vector math. A simple scene graph is relatively easy to create.

Determining Point From Edge With Rotation

I'm writing a screensaver with a bouncing ball (x and y, does not bounce in Z) in C++ using OpenGL. When this ball touches the edges of the screen, a small patch of damage will appear on the ball. (When the ball is damaged enough, it will explode.) Finding the part of the ball to damage is the easy part when the ball isn't rotating.
The algorithm I decided for this is that I'm keeping the position left most, right most, top most and bottom most vertex. For every collision, I obviously need to know which screen edge it hit. Before the ball could roll, when it touches a screen edge, if it hit the left screen edge, I know the left-most vertex is the point on the ball that took a hit. From there, I get all vertices that are within d distance from that point. I don't need the actual vertex that was hit, just the point on the ball's surface.
Doing this, I don't need to read all vertices, translate them by the x,y position of the ball and see which are off-screen. Doing this would solve all my problems but would be slow as hell.
Currently, the ball's rotation is controlled by pitch, yaw and roll. The problem is, what point on the ball's outer surface has touched the edge of the screen given my yaw, pitch and roll angles? I've looked into keeping an up, right and direction vector but I'm totally new to this and as someone might notice, totally lost. I've read the rotation matrix article on Wikipedia several times and still drawing a blank. If I got rid of one rotation angle it would be much simpler but I would prefer not to.
If you have your rotation angles then you can recreate the model view matrix in your code. With that matrix you can apply the rotation to the vertices of the mesh (simply by multiplication) and then find the left most (or whatever) vertex as you did before.
This article explains how to construct the rotation matrix with the angles you have.

OpenGL rotate around a spot

I want to rotate a gluSphere around a fixed point in a circular motion, like a planet going around the sun.
Would it be best to use glRotatef or glTranslate? If so, in which order should I call them?
You'll have to do a little of both:
Make sure the gluSphere is "facing" the fixed point, so that translating forward with respect to the sphere puts you closer to the center of its orbit
glTranslatef the gluSphere forward to the point around which you want it to rotate
glRotatef the direction you want the sphere to orbit
glTranslatef backwards just as far as you went forward
That way, your sphere stays the same distance from the center, but gets translated "around" in a nice orbit.
Translate away from the center and then rotate all the way
glRotatef will multiply the current matrix by a rotation matrix. This can (given the right vector) do what you are attempting.
glTranslatef will multiply the current matrix by a translation matrix, which would effectively "move" the object, not rotate it, so it will not be what you want.