Managing my objects
Hello,
I'm working on creating my first game with Delphi+OpenGL. Right now I've gone through some tutorials about translations,rotations, and of course, creating primitives with OpenGL. I want to start working on a pong game, but carry things a little further. I'd like to be able to define my objects, in a similar way as done in BlitzBasic.
For Example:
If I wanted to make a cube, I'd do something like this.
MyCube = MakeCubeFunctionHere()
Then, whenever I want to rotate my object, I just use MyCube to identify which vertices I want to move.
Maybe something like this?
RotateObject MyCube,x,x,z
I'm just having trouble figuring out a way to package everything together. So when I'm creating my vertices for the cube in my function, how do I ensure that those verts are unique to the name "MyCube"?
I've read about SceneGraph's, and other things like that, but I'm still a little confused.
Thanks for any help you may provide.
Mike
I code using straight C++, and I could offer you some ideas and not code. You could have a class like this:
class MyObject
{
GLuint dlist; // make a display list and store a cube here
GLfloat theta_x, theta_y, theta_z; // the current angles by which it is rotated
GLfloat pos_x, pos_y, pos_z; // the current position coords (or use vectors)
// constructor / destructor - use to make display list
void draw(); // translate, rotate, and then glCallList
};
I hope this helps you - all the best porting to whatever works for you. And if you have questions just ask!
class MyObject
{
GLuint dlist; // make a display list and store a cube here
GLfloat theta_x, theta_y, theta_z; // the current angles by which it is rotated
GLfloat pos_x, pos_y, pos_z; // the current position coords (or use vectors)
// constructor / destructor - use to make display list
void draw(); // translate, rotate, and then glCallList
};
I hope this helps you - all the best porting to whatever works for you. And if you have questions just ask!
Hi thanks for the quick response deavik. Right now I'm working on writting a class to store the information for my objects based on what you've posted. If there are any other ways you can think of that'd be more efficient, please post.
Thanks for your help.
:)
Thanks for your help.
:)
Oh I forgot to add that you can write member functions to change the rotation angles and position easily. So you could have some simple code to do stuff in your program:
// If MyCube is your class,
MyCube cubo;
cubo.translate (1, 2, 3); // sort out vectors
cubo.rotate_x (60.0f);
// and so on
This is what you wanted right? I can't think of anything better, I admit. In the class you can add scale factors. Use glScalef to scale your object.
All the best on your project! Let me know how it comes along.
// If MyCube is your class,
MyCube cubo;
cubo.translate (1, 2, 3); // sort out vectors
cubo.rotate_x (60.0f);
// and so on
This is what you wanted right? I can't think of anything better, I admit. In the class you can add scale factors. Use glScalef to scale your object.
All the best on your project! Let me know how it comes along.
Thanks deavik, that will help me out a lot! I'm going to spend this afternoon implementing the member functions, and I'll be sure to post my progress.
:)
:)
Okay, I bundled up my class into its own object handling unit.
I've been looking at BlitzBasic3D(B3D), and I admire the entity system that's in place. The genius of it is how they control every type of entity(lights, camera, sprites,terrains,and objects) with the same commands.
I'm curious to know how something like this is done. For example, with what I have now, surely I couldn't use the same scale command on an object that I'd use on a light. You can't truly scale the size of a light right?
So what would be the best way to solve this problem. Perhaps if I added a variable where you defined what kind of object you're creating, and based on that, have a flag in each procedure that said whether or not that object can do this or that(For I don't think it's possible to scale a light).
Here's the B3D manual which I'm gathering my ideas from.
BlitzBasic 3D manual
Thanks for your help.
unit objecthandle;interface// External Dependenciesuses SysUtils, OpenGL, glfw;// [ ===== Entity =====]// The entity class which handles object translation,rotation, and scaling.type entity = class xpos,ypos,zpos:single; angle,xrot,yrot,zrot:single; xscale,yscale,zscale:single; procedure position(xpos,ypos,zpos:single); procedure rotation(angle,xrot,yrot,zrot:single); procedure scale(xscale,yscale,zscale:single);end;// [ ===== Entity =====]implementation// [ = Position the entity = ]procedure entity.position(xpos,ypos,zpos:single);begin gltranslatef( xpos,ypos,zpos);end;// [ = Rotate the entity = ]procedure entity.rotation(angle,xrot,yrot,zrot:single);begin glrotatef(angle, xrot,yrot,zrot);end;// [ = Scale the entity = ]procedure entity.scale(xscale,yscale,zscale:single);begin glscalef(xscale,yscale,zscale);end;end.
I've been looking at BlitzBasic3D(B3D), and I admire the entity system that's in place. The genius of it is how they control every type of entity(lights, camera, sprites,terrains,and objects) with the same commands.
I'm curious to know how something like this is done. For example, with what I have now, surely I couldn't use the same scale command on an object that I'd use on a light. You can't truly scale the size of a light right?
So what would be the best way to solve this problem. Perhaps if I added a variable where you defined what kind of object you're creating, and based on that, have a flag in each procedure that said whether or not that object can do this or that(For I don't think it's possible to scale a light).
Here's the B3D manual which I'm gathering my ideas from.
BlitzBasic 3D manual
Thanks for your help.
Sorry for being so very late, but unfortunately I have little to help you this time. What I suggested went with everything that has a display list. It could handle textures, but you may have to prebuild the textures (Get back to me on that if you're really interested and I'll try to help you out). But lights are a total no-go. Alright, you could may be change position, but that's about it. Why not have a different light class? You could have member fuctions to change position, control brightness, etc etc
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement