PDA

View Full Version : How to group objects together?



jing_ntu
09-03-2007, 12:31 AM
I have a number of objects which belong to the same group.

I want do some manipulation on the group, i.e. translate, rotate, scale.

How can I get it done?

what changes are needed if I want to know the status of individual objects also, i.e. position.

thanks for anyone who can help.

Zengar
09-03-2007, 01:39 AM
OpenGL doesn't operate with notions of "objects", it renders primitives. An "object" is what your application makes of it. Similar, it is teh task of your application to set up and maintain state for this objects. Usually you want to keep some data (position, orientation) associated with an object and set the corresponding modelview matrix (via glTranslate, glRotate etc.) when rendering it. Same goes for groups of objects. You could do it like this:



1. Apply group transformations
2. For each object:
2a) glPushMatrix()
2b) apply it's local transformation
2c) render
2d) glPopMatrix
3. Do the same for all other groups

Trenki
09-03-2007, 02:44 AM
Zengar is right; OpenGL only renders primitives you send it. You have to group those primitives to form objects yourself. In the upcomming OpenGL 3 the OpenGL matrix stack will be removed so you don't have glRotate/glTranlate glPush/Pop any more and have to roll your own. Please correct me if I'm wrong here.

[ www.trenki.net (http://www.trenki.net) | vector_math (3d math library) (http://www.trenki.net/content/view/16/36/) | software renderer (http://www.trenki.net/content/view/18/38/) ]

Seth Hoffert
09-03-2007, 07:20 AM
Originally posted by Trenki:
In the upcomming OpenGL 3 the OpenGL matrix stack will be removed so you don't have glRotate/glTranlate glPush/Pop any more and have to roll your own. Please correct me if I'm wrong here. The matrix stack will most likely be moved into a utility library (such as GLU) instead of being the driver's responsibility.

Jedimaster
09-04-2007, 09:49 PM
It's fully a application's stuff, you can use C++ STL to manage your all meshes in your scene, write some class/struct to keep your information, such as translation matrix etc.

Jedimaster
09-04-2007, 09:51 PM
PS:
In my programming, I pass the WorldTransMatrix into Texture Matrix 1, so, in my VS, I can simply get its world position:

vec4 WorldPos = gl_Vertex*gl_TexureMatrix[1];

use shader smart,you can get everying.

jing_ntu
09-04-2007, 10:16 PM
Thanks for the replies.

the actual application is a bit more complicated than this. I am afraid I didn't state it clearly enough.

Here is an example scenario.

there will be 3 spheres in scene; one at origin; the other two as a group.

what I need to do is, to control transformation of the "two spheres" group using mouse.
( is it a good idea to use a display list? since there are 10s to 100s spheres in actual application.)

The problem i am facing now is how to group "two spheres" together. It really is a silly question, but I am beginner~. :$

further questions after sphere group transformation are like, how to get individual sphere center coordinates, how can I implemente it in a way that it can select both group object and individual sphere.


btw, I am writing it in C++.
graphics part done by openGL.
haptic part by openHaptics.

jing_ntu
09-04-2007, 10:20 PM
Originally posted by Jedimaster:
PS:
In my programming, I pass the WorldTransMatrix into Texture Matrix 1, so, in my VS, I can simply get its world position:

vec4 WorldPos = gl_Vertex*gl_TexureMatrix[1];

use shader smart,you can get everying. cool.
this may solve my coordinate problem.

Zengar
09-04-2007, 10:26 PM
Just render them one after another... This way, it will be the same modelview matrix applied to both...