moving and rotating vertices
Hi. I've been writing a simple animation program which works by moving different groups of an obj object. Currently I have it putting each group in a display list and then moving it the required amount with glRotate and glTranslate. This has the problem that as parts move, they leave huge gaps.
To get round this problem, I decided to instead load the vertices into an array and when it's time to draw, change the vertex positions and then draw the faces in immediate mode.
I would like to know what the best method for moving these vertices is. Is there a nice, simple way to do it, or am I going to have to learn all that matric stuff and manually implement all the functions? If it is the latter, does anyone have any pointers on how to get started?
Thanks.
To get round this problem, I decided to instead load the vertices into an array and when it's time to draw, change the vertex positions and then draw the faces in immediate mode.
I would like to know what the best method for moving these vertices is. Is there a nice, simple way to do it, or am I going to have to learn all that matric stuff and manually implement all the functions? If it is the latter, does anyone have any pointers on how to get started?
Thanks.
I'm not sure what's happening in your code  you might post some of it for us. In any case, transformations can be tricky. You have to do them in the right order and with the appropriate inversions or negations to get the results you expect. It can be kind of counterintuitive.
You should be able to do what you're trying to do through OpenGL without getting into the matrix math yourself  you probably just have something backwards or in the wrong order. If you're serious about it, though, you'll want to get up to speed on that stuff. A fairly good book is '3D Math Primer for graphics and game development', which you should be able to find fairly easily.
If you still haven't solved your problem, post some code and I'm sure it'll get sorted out.
You should be able to do what you're trying to do through OpenGL without getting into the matrix math yourself  you probably just have something backwards or in the wrong order. If you're serious about it, though, you'll want to get up to speed on that stuff. A fairly good book is '3D Math Primer for graphics and game development', which you should be able to find fairly easily.
If you still haven't solved your problem, post some code and I'm sure it'll get sorted out.
No, I'm certain it's not to do with the order of statements. I want to manually set the position of these vertices. At current, the code uses display lists for each group, and as such looks hideous when moving pieces of it.
The code to do the drawing of this model will probably look something like:
That's just off the top of my head, so it might not work quite right, but that's basically what I plan to do at drawing time. I can't see any way that this would be possible using glRotate and such.
The code to do the drawing of this model will probably look something like:
Code:
int i, j, k;
Vertex3D *frameVertices;
Vertex3D *frameNormals;
frameVertices = malloc(sizeof(Vertex3D) * nVertices);
frameNormals = malloc(sizeof(Vertex3D) * nVertices);
for (i = 0; i < nVertices; i++) {
frameVertices[i] = vertices[i];
frameNormals[i] = normals[i];
vertexUsed[i] = NO;
}
for (i = 0; i < nGroups; i++) {
for (j = 0; j < groups[i].nFaces; j++) {
vertex[0] = groups[i].vertex[0];
vertex[1] = groups[i].vertex[1];
vertex[2] = groups[i].vertex[2];
vertex[3] = groups[i].vertex[3];
for (k = 0; k < 4; k++) {
if (!vertexUsedgroups[[i].face[j].vertex[k]]) {
translateX(frameVertices[groups[i].face[j].vertex[k]],
groups[i].keyFrames[currentFrame].transX,
groups[i].keyFrames[nextFrame].transX,
timeSinceLastFrame);
translateY(frameVertices[groups[i].face[j].vertex[k]],
groups[i].keyFrames[currentFrame].transY,
groups[i].keyFrames[nextFrame].transY,
timeSinceLastFrame);
translateZ(frameVertices[groups[i].face[j].vertex[k]]
groups[i].keyFrames[currentFrame].transZ,
groups[i].keyFrames[nextFrame].transZ,
timeSinceLastFrame);
rotateX(frameVertices[groups[i].face[j].vertex[k]],
groups[i].keyFrames[currentFrame].rotX,
groups[i].keyFrames[nextFrame].rotX,
timeSinceLastFrame);
rotateY(frameVertices[groups[i].face[j].vertex[k]],
groups[i].keyFrames[currentFrame].rotY,
groups[i].keyFrames[nextFrame].rotY,
timeSinceLastFrame);
rotateZ(frameVertices[groups[i].face[j].vertex[k]]
groups[i].keyFrames[currentFrame].rotZ,
groups[i].keyFrames[nextFrame].rotZ,
timeSinceLastFrame);
translateX(frameNormals[groups[i].face[j].vertex[k]],
groups[i].keyFrames[currentFrame].transX,
groups[i].keyFrames[nextFrame].transX,
timeSinceLastFrame);
translateY(frameNormals[groups[i].face[j].vertex[k]],
groups[i].keyFrames[currentFrame].transY,
groups[i].keyFrames[nextFrame].transY,
timeSinceLastFrame);
translateZ(frameNormals[groups[i].face[j].vertex[k]]
groups[i].keyFrames[currentFrame].transZ,
groups[i].keyFrames[nextFrame].transZ,
timeSinceLastFrame);
rotateX(frameNormals[groups[i].face[j].vertex[k]],
groups[i].keyFrames[currentFrame].rotX,
groups[i].keyFrames[nextFrame].rotX,
timeSinceLastFrame);
rotateY(frameNormals[groups[i].face[j].vertex[k]],
groups[i].keyFrames[currentFrame].rotY,
groups[i].keyFrames[nextFrame].rotY,
timeSinceLastFrame);
rotateZ(frameNormals[groups[i].face[j].vertex[k]]
groups[i].keyFrames[currentFrame].rotZ,
groups[i].keyFrames[nextFrame].rotZ,
timeSinceLastFrame);
vertexUsed[groups[i]. face[j].vertex[k]] = YES;
}
}
glBegin(GL_QUADS); {
for (k = 0; k < 4; k++) {
glNormal3f(frameNormals[groups[i].face[j].vertex[k]].x,
frameNormals[groups[i].face[j].vertex[k]].y,
frameNormals[groups[i].face[j].vertex[k]].z);
glVertex3f(frameVertices[groups[i].face[j].vertex[k]].x,
frameVertices[groups[i].face[j].vertex[k]].y,
frameVertices[groups[i].face[j].vertex[k]].z);
}
} glEnd();
}
}
free(frameNormals);
free(frameVertices);
That's just off the top of my head, so it might not work quite right, but that's basically what I plan to do at drawing time. I can't see any way that this would be possible using glRotate and such.
You will almost certainly want to change the doX/doY/doZ groups to a single translation function and an angle/axis (quaternion) rotation function. Also, why do you have 2 sets of translate and rotate calls with identical parameters? (edit: Sorry, I didn't notice one set was for the normals.)
You could use GL feedback mode to do the transformations too.
You could use GL feedback mode to do the transformations too.
The translate() and rotate(0 functions don't exist yet. That's the problem. GL feedback mode looks exactly like what I'm looking for. Thanks.
No wait, it isn't. After doing a little testing, I've discovered that it in fact will only tell you of the coordinates in the window (why didn't I just read the whole manual to begin with). From the looks of it I'm just going to have to bite the bullet and learn how to do all the matrix transforms and such by hand. Does anyone know of a good website with tutorials on this nature?
I'm using feedback mode to render animated models myself, so, yes, it's possible
You do get full 3D coordinates out of feedback mode, but they are in window space. You just have to transform them back to world space by setting up an orthogonal projection and applying simple transformations to fix any remaining differences (e.g. the Z value will probably need changing).
You do get full 3D coordinates out of feedback mode, but they are in window space. You just have to transform them back to world space by setting up an orthogonal projection and applying simple transformations to fix any remaining differences (e.g. the Z value will probably need changing).
Feedback doesn't return a point if it gets clipped by the projection, which makes it useless for some operations.
You can get the same results for vertex position by using gluProject, without clipping. Doesn't help if you want the lit color, etc.
You can get the same results for vertex position by using gluProject, without clipping. Doesn't help if you want the lit color, etc.
You're not going to see anything you draw in feedback mode, so you can make any changes you want to the viewport and projection matrix to prevent anything being clipped.
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
Origin problems  rotating shapes  frances_farmer  1  2,851 
Feb 10, 2007 08:08 AM Last Post: unknown 

Rotating a point in 3D  Joseph Duchesne  1  2,877 
Dec 19, 2006 12:43 PM Last Post: unknown 

Rescaling vertices?  WhatMeWorry  3  2,667 
May 19, 2006 12:55 PM Last Post: WhatMeWorry 

rotating objects  ferum  11  4,491 
Dec 19, 2005 02:28 PM Last Post: ferum 

rotating...  MACnus  4  4,032 
Mar 25, 2005 07:46 PM Last Post: phydeaux 