Hi all,
Recently I've got into the world of 3D, and I've been playing around a lot with it. Currently I'm trying to make an entity system(aka object factory or pluggable factory).
I'm trying to mimick BlitzBasic3D's system, as I really like the cleanliness of how it's done.
Blitz 3D Manual
Here's the class I wrote that can handle rotation,scaling,and position of objects. There's a few things I'd like to add, though I'm not sure how to properly implement them.
[pascal]unit objecthandle;
interface
// External Dependencies
uses
SysUtils,
OpenGL,
glfw;
procedure tri(size:single);
// [ ===== 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;
procedure tri(size:single);
begin
glBegin( GL_TRIANGLES );
glColor3f( 1.0, 0.0, 0.0 );
glVertex3f( -5.0-size, 0.0, -4.0-size );
glColor3f( 0.0, 1.0, 0.0 );
glVertex3f( 5.0+size, 0.0, -4.0-size );
glColor3f( 0.0, 0.0, 1.0 );
glVertex3f( 0.0, 0.0, 6.0+size);
glEnd;
end;
end.[/pascal]
Here's a little diagram I drew to hopefully make my intentions more clear.
[pascal][/pascal]
There are a few problems which I can't get my head around. The first being, how do I define what my entity is? I suppose I could put something in my procedures for when I create my objects that automatically assigns what entity they are, and there unique id(Hmm, might've actually solved my own problem while writting this post :shock: ).
The second problem though, is how can I prevent lights from being scaled. Since everything is manipulated from a common class, what stops a user from scaling a light? Would it just be easier to write a new class for the lighting functionality?
Well, I know I've kind of rambled a bit, but I'd like to know how you structure your games and manage all the different types of objects. Am I heading in the right or wrong direction?
Thanks for any help.
Bookmarks