Archived

This topic is now archived and is closed to further replies.

pozi

Determining the centre of 3d object

Recommended Posts

I render 3d object (thousands of polygons) using display list. I want to implement rotating of this object (with mouse). Problem is to determine the centre of object (aroud which I want to rotate). Is possible to determine aproximated centre of rendered scene with some OpenGL function? Or is possible to determine minimum and maximum x,y,z coordinates of the scene? thx

Share this post


Link to post
Share on other sites
This isn''t terribly efficient, but you could step through each vertex and average the x coords, average the y coords, and average the z coords together. It wouldn''t be fast, but you could do it at load time, and I think it''ll work.


My 3D Pirate Game is in need of a better name, want to help?

Share this post


Link to post
Share on other sites
No, that would treat the area with the most polys as the most important. Maybee average the biggest and littlest x,y, and z. Although uneven objects would have more mass on one side, it would work fairly quickly if you figured out min and max while rendering.

Share this post


Link to post
Share on other sites
But, I have also problem to determine max. x,y,z coordinates.

For example, this simple object (3 conected cylinders):

gluCylinder(...,...,height,...,...);
glTranslatef(0,0, height);
glRotatef(some angle, some vector);
gluCylinder(...,...,height,...,...);
glTranslatef(0,0, height);
glRotatef(some angle, some vector);
gluCylinder(...,...,height,...,...);

Simply, every time I draw new cylinder, I''am on coordinates (0,0,0) so I cannot store this coordinates...

What can I do? I must to do it so, I can not change this concept of rendering, whole application is dependent on it.


Share this post


Link to post
Share on other sites
But how can I determine coordinates of vertexes?

I must determine it after whole object is rendered. Reason for this is explained in my other reply...

Share this post


Link to post
Share on other sites
Ignoring the problem of getting the verticies for the moment, you can find a simple center of an object by taking the bounding box of every vertex. Loop through every vertex and if the vertex x is lower than the min low, min low equals x, opposite for max and do that for y and z. Take the (max-min)/2+min for every axis and you have the center.
To get verticies for objects generated using quadric methods, like gluCylinder, the simple answer is you can't. The longer answer is you have to do all the calculations yourself to generate the object, because if you generate the object manually then you have all the data at which point you can loop and find the center.
There may a way to use OpenGL calls to get vertex data, in fact I'm sure there is one but I can't think of anything right now.
To generate the cylinder coords just use cos and sin over one axis-aligned plane and a depth funciton along the last axis. If you don't understand that, get some graph paper out and fiddle with sin and cos. Hope you solve your problem! GL!

[edited by - Venerable Vampire on April 22, 2004 8:55:06 PM]

Share this post


Link to post
Share on other sites