# Cannot get the correct pivot point

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

## Recommended Posts

Hello,
I get a weird result when using vertices and when using vertices and indices. Let me tell it with an example:

I used a cube to check the results. When i am using:

real verts[] = {        1,1,-1, -1,1,-1, -1,1,1, 1,1,1,        1,-1,1, -1,-1,1, -1,-1,-1, 1,-1,-1,        1,1,1, -1,1,1, -1,-1,1, 1,-1,1,        1,-1,-1, -1,-1,-1, -1,1,-1, 1,1,-1,        -1,1,1, -1,1,-1, -1,-1,-1, -1,-1, 1,        1,1,-1, 1,1,1, 1,-1,1, 1,-1,-1    };    vbo = dour::HardwareBufferManager::Instance().createVertexBuffer(sizeof(real) * 3 * 24, 0, verts, false);//Rendervbo->Bind();glDrawArrays(GL_QUADS, 0, 24);vbo->Unbind();

I get pivot point at the center of the cube.

But when using:

real verts[] = { 0,0,0, 0,1,0, 0,1,0, 0,1,1, 1,0,0, 1,0,1, 1,1,0, 1,1,1};    uint indices[] = { 1,7,5, 1,3,7, 1,4,3, 1,2,4, 3,8,7, 3,4,8, 5,7,8, 5,8,6, 1,5,6, 1,6,2, 2,6,8, 2,8,4 };    vbo = dour::HardwareBufferManager::Instance().createVertexBuffer(sizeof(real) * 132, 0, verts, false);    ibo = dour::HardwareBufferManager::Instance().createIndexBuffer(sizeof(uint) * 36, 0, indices, false);//Rendervbo->Bind();ibo->Bind();glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);ibo->Unbind();vbo->Unbind();

I get pivot point at the lower-left-front vertex of cube.

When using vbo, ibo (triangles)

The red dot is the pivot point.

Thanks,
Kasya

##### Share on other sites
Quote:
 Original post by KasyaI get a weird result when using vertices and when using vertices and indices. Let me tell it with an example:

Uhhmmm... well, these are the absolutly correct results. In your first example you are drawing a cube with coords within [-1..1] whereas in your second example you are drawing only vertices with coords within [0..1]. This has nothing to do with using indicies. Use the correct coords and you will see a correct result :-)

##### Share on other sites
Ok. But its just a cube. What if I am drawing a complex mesh? Do i have to clamp them in [-1,1] interval? Or is there other way of doing it? And is that possible to pre-scale object or i need to scale it during matrix multiplications etc?

Thanks,
Kasya

[Edited by - Kasya on July 5, 2010 3:27:37 AM]

##### Share on other sites
Quote:
 Original post by KasyaOk. But its just a cube. What if I am drawing a complex mesh? Do i have to clamp them in [-1,1] interval? Or is there other way of doing it?
Clamping: No (or at least not necessarily); other way: Yes!

The vertices of a model are given with respect to the local co-ordinate space of the model. At default, the local co-ordinate space origin is coincident with the global co-ordinate space origin (you remember what that measn?). So either guarantee that the vertices are arranged "concentric" around the local origin (Ashaman73 has hinted in that direction) or else make the desired pivot point temporarily the local origin. Remember that you can shift the origin as in
C * M * C-1
where C denotes the translation matrix of the said origin (using column matrices as is usual for OpenGL).

##### Share on other sites
Oh, an editing happened in the meanwhile ...
Quote:
 Original post by KasyaAnd is that possible to pre-scale object or i need to scale it during matrix multiplications etc?
When you look at the aforementioned transformation and consider the vertex position, too, then you get something like
( C * M * C-1 ) * v
where v denotes the said vertex position. Regardless what transformation C exactly is, you'll get the same result if you alter the parantheses like here
C * M * ( C-1 * v )

So yes, you can apply the parts that are left to the vertex position to the model directly, yielding in a new model
v' := C-1 * v
with which the transformation pipleline would be shorter:
C * M * v'

EDIT: This can be done even for a longer part of the transformation and, as said, for any particular kind of transformation. However, it must be ever a part that directly starts at the vertex position. E.g.
v'' := M * C-1 * v
would be possible, too.

##### Share on other sites
Thanks for the help. The problem fixed. Problem was *.3ds transform error while importing to blender. So, when I exported as *.obj the pivot point was outside the mesh.

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633694
• Total Posts
3013372
×