my team and I did this, I posted on the board a ways back. Never had any interest so i didn't package it up.. If interested let me know..
sample object h
#ifndef _OBJECT_H_
#define _OBJECT_H_
#include "vector3.h"
class u_Object {
public:
u_Object( void );
u_Object( const char *szPath );
virtual ~u_Object( void );
//temp vars..
int iTemp;
char cLable[128];
int u_Object::totalObjects();
void load( const char *szPath );
// Colors an object using the specified color
void color( int iRGB );
void enableGhosting( void );
void disableGhosting( void );
void show( void );
void hide( void );
void rotateX( float fDegrees );
void rotateY( float fDegrees );
void rotateZ( float fDegrees );
void rotate( float fX, float fY, float fZ );
void turnLeft( float fAmount );
void turnRight( float fAmount );
void loopAnimation( void );
void playAnimation( int iStartFrame = 0, int iEndFrame = 0 );;
void stopAnimation();
// Scales the object using percentage values from 0 - 100
void scale( float fXScale, float fYScale, float fZScale );
void showBounds( bool bBoxOnly = false );
void hideBounds( void );
void moveUp( float fSpeed );
void moveDown( float fSpeed );
void moveLeft( float fSpeed );
void moveRight( float fSpeed );
void move( float fSpeed );
void setLight(bool flag);
void setTexture( int iMode, int iMipMaps );
void scaleTexture( float fU, float fV );
void shadow(bool iSwitch);
float getCurrentFrame( void );
bool inScreen( void );
bool isLoopingAnimation( void );
bool isPlayingAnimation( void );
float getRadius( void );
bool isVisible( void );
float getX( void );
float getY( void );
float getZ( void );
float getSizeX( bool bActualSize = true );
float getSizeY( bool bActualSize = true );
float getSizeZ( bool bActualSize = true );
bool collidesWith( u_Object &collider );
float getAngleX( void );
float getAngleY( void );
float getAngleZ( void );
void setFrame( float fFrame, bool bRecalculateBounds );
void setSpeed( int iSpeed );
void setLightMappingOn( int iImage );
void setSpecular( int iSpecular );
void setPosition( Vector3 &iVector ) ;
void setPosition( float xPos, float yPos, float zPos ) ;
void setTransparency( bool iFlag );
int getLimbTexture( int iID );
void textureObject(int iImage);
void textureObject(int iStage, int iImage);
void scrollTexture( float iU, float iV);
//void textureObject(int iImage, int iState = ???);
void makeLimbs();
void glueLimb(int iSecondObject, int iLimb);
void addLimb(int iLimb, int iMesh);
int getLimbs();
int findEntityByName( const char *szName );
char* limbGetName ( int iLimb );
void makeFromLimb(int iNewObject, int iLimb);
//I think all offsets or xyz of scall pos rot are off, y is z for example.
//
//
float limbGetPositionX(int iLimb);
float limbGetPositionY(int iLimb);
float limbGetPositionZ(int iLimb);
float limbGetScaleX(int iLimb);
float limbGetScaleY(int iLimb);
float limbGetScaleZ(int iLimb);
float limbGetRotationX(int iLimb);
float limbGetRotationY(int iLimb);
float limbGetRotationZ(int iLimb);
Vector3 limbGetWorldPosition(int iLimb);
Vector3 limbGetPosition(int iLimb);
Vector3 limbGetScale(int iLimb);
Vector3 limbGetRotation(int iLimb);
void limbSetPositionX(int iLimb, float fX);
void limbSetPositionY(int iLimb, float fY);
void limbSetPositionZ(int iLimb, float fZ);
void limbSetScaleX(int iLimb, float fX);
void limbSetScaleY(int iLimb, float fY);
void limbSetScaleZ(int iLimb, float fZ);
void limbSetRotationX(int iLimb, float fX);
void limbSetRotationY(int iLimb, float fY);
void limbSetRotationZ(int iLimb, float fZ );
void limbSetPosition(int iLimb, Vector3 &iVector);
void limbSetPosition(int iLimb, float fX, float fY, float fZ);
void limbSetScale(int iLimb, Vector3 &iVector);
void limbSetScale(int iLimb, float fX, float fY, float fZ);
void limbSetScale(int iLimb, Vector3 &iVector, int iBoundFlag);
void limbSetScale(int iLimb, float fX, float fY, float fZ, int iBoundFlag);
void limbSetRotation(int iLimb, Vector3 &iVector);
void limbSetRotation(int iLimb, float fX, float fY, float fZ);
void limbHide(int iLimb);
int getID( void );
void destroy( void );
int getNextID( void );
Vector3 getPosition( );
private:
int m_iID;
char **m_limbs;
int m_numLimbs;
float frameCount;
};
#endif
sample object CPP
#include "Object.h"
#include "ObjectFactory.h"
#include "DarkGDK.h"
u_Object::u_Object( void ) {
m_iID = ObjectFactory::getInstance( )->getNextID( );
}
u_Object::u_Object( const char *szPath ) {
m_iID = ObjectFactory::getInstance( )->getNextID( );
load( szPath );
}
u_Object::~u_Object( void ) {
}
int u_Object::totalObjects(){
return ObjectFactory::getInstance( )->getCurrentID();
}
void u_Object::load( const char *szPath ) {
dbLoadObject( (char *)szPath, m_iID );
}
int u_Object::getID( void ) {
return m_iID;
}
void u_Object::color( int iRGB ) {
dbColorObject( m_iID, iRGB );
}
void u_Object::enableGhosting( void ) {
dbGhostObjectOn( m_iID );
}
void u_Object::disableGhosting( void ) {
dbGhostObjectOff( m_iID );
}
void u_Object::show( void ) {
dbShowObject( m_iID );
}
void u_Object::hide( void ) {
dbHideObject( m_iID );
}
void u_Object::rotateX( float fDegrees ) {
dbXRotateObject( m_iID, fDegrees );
}
void u_Object::rotateY( float fDegrees ) {
dbYRotateObject( m_iID, fDegrees );
}
void u_Object::rotateZ( float fDegrees ) {
dbZRotateObject( m_iID, fDegrees );
}
void u_Object::rotate( float fX, float fY, float fZ ) {
dbRotateObject( m_iID, fX, fY, fZ );
}
void u_Object::turnLeft( float fAmount ) {
dbTurnObjectLeft( m_iID, fAmount );
}
void u_Object::turnRight( float fAmount ) {
dbTurnObjectRight( m_iID, fAmount );
}
void u_Object::loopAnimation( void ) {
dbLoopObject( m_iID );
}
void u_Object::playAnimation( int iStartFrame, int iEndFrame ) {
dbPlayObject( m_iID, iStartFrame,iEndFrame);
}
void u_Object::stopAnimation( void ) {
dbStopObject( m_iID );
}
void u_Object::scale( float fXScale, float fYScale, float fZScale ) {
dbScaleObject( m_iID, fXScale, fYScale, fZScale );
}
void u_Object::showBounds( bool bBoxOnly ) {
dbShowObjectBounds( m_iID, ( bBoxOnly ) ? 1 : 0 );
}
void u_Object::hideBounds( void ) {
dbHideObjectBounds( m_iID );
}
void u_Object::moveUp( float fSpeed ) {
dbMoveObjectUp( m_iID, fSpeed );
}
void u_Object::moveDown( float fSpeed ) {
dbMoveObjectDown( m_iID, fSpeed );
}
void u_Object::moveLeft( float fSpeed ) {
dbMoveObjectLeft( m_iID, fSpeed );
}
void u_Object::moveRight( float fSpeed ) {
dbMoveObjectRight( m_iID, fSpeed );
}
void u_Object::move( float fSpeed ) {
dbMoveObject( m_iID, fSpeed );
}
void u_Object::setLight(bool flag){
dbSetObjectLight( m_iID, flag );
}
void u_Object::setTexture( int iMode, int iMipMaps ){
dbSetObjectTexture ( m_iID, iMode, iMipMaps );
}
void u_Object::scaleTexture( float fU, float fV ){
dbScaleObjectTexture ( m_iID, fU, fV );
}
void u_Object::shadow(bool iSwitch){
if(iSwitch) dbSetShadowShadingOn(m_iID);
else dbSetShadowShadingOff(m_iID);
}
bool u_Object::collidesWith( u_Object &collider ) {
if( dbObjectCollision( m_iID, collider.getID( ) ) > 0 ) return true;
else return false;
}
float u_Object::getCurrentFrame( void ) {
return dbObjectFrame( m_iID );
}
bool u_Object::inScreen( void ) {
if( dbObjectInScreen( m_iID ) > 0 ) return true;
else return false;
}
bool u_Object::isLoopingAnimation( void ) {
if( dbObjectLooping( m_iID ) ) return true;
else return false;
}
bool u_Object::isPlayingAnimation( void ) {
if( dbObjectPlaying( m_iID ) ) return true;
else return false;
}
float u_Object::getRadius( void ) {
return dbObjectSize( m_iID );
}
bool u_Object::isVisible( void ) {
if( dbObjectVisible( m_iID ) ) return true;
else return false;
}
float u_Object::getX( void ) {
return dbObjectPositionX( m_iID );
}
float u_Object::getY( void ) {
return dbObjectPositionY( m_iID );
}
float u_Object::getZ( void ) {
return dbObjectPositionZ( m_iID );
}
float u_Object::getSizeX( bool bActualSize ) {
return dbObjectSizeX( m_iID, ( bActualSize ) ? 1 : 0 );
}
float u_Object::getSizeY( bool bActualSize ) {
return dbObjectSizeY( m_iID, ( bActualSize ) ? 1 : 0 );
}
float u_Object::getSizeZ( bool bActualSize ) {
return dbObjectSizeZ( m_iID, ( bActualSize ) ? 1 : 0 );
}
float u_Object::getAngleX( void ) {
return dbObjectAngleX( m_iID );
}
float u_Object::getAngleY( void ) {
return dbObjectAngleY( m_iID );
}
float u_Object::getAngleZ( void ) {
return dbObjectAngleZ( m_iID );
}
void u_Object::setFrame( float fFrame, bool bRecalculateBounds ) {
dbSetObjectFrame( m_iID, fFrame, ( bRecalculateBounds ) ? 1 : 0 );
}
void u_Object::setSpeed( int iSpeed ) {
dbSetObjectSpeed( m_iID, iSpeed );
}
void u_Object::setLightMappingOn( int iImage ) {
dbSetLightMappingOn ( m_iID, iImage );
}
void u_Object::setSpecular( int iSpecular ) {
dbSetObjectSpecular ( m_iID, iSpecular );
}
void u_Object::setPosition( Vector3 &iVector ) {
dbPositionObject ( m_iID, iVector.getX(), iVector.getY(), iVector.getZ() );
}
Vector3 u_Object::getPosition( ) {
Vector3 iVector3(dbObjectPositionX( m_iID ),dbObjectPositionY( m_iID ),dbObjectPositionZ( m_iID ));
return (iVector3);
}
void u_Object::setPosition( float xPos, float yPos, float zPos ) {
dbPositionObject ( m_iID, xPos, yPos, zPos );
}
void u_Object::setTransparency( bool iFlag ) {
dbSetObjectTransparency ( m_iID, iFlag );
}
int u_Object::getLimbTexture( int iID){
return dbLimbTexture(m_iID, iID);
}
void u_Object::scrollTexture( float iU, float iV){
dbScrollObjectTexture(m_iID, iU,iV);
}
//void u_Object::textureObject(int iImage,int iState){
void u_Object::textureObject(int iImage){
dbTextureObject (m_iID, iImage);
}
void u_Object::textureObject(int iStage, int iImage){
dbTextureObject (m_iID, iStage, iImage);
}
char* u_Object::limbGetName ( int iLimb ) {
return dbLimbName ( m_iID, iLimb-1 );////// -1 gets the righ lable for the actul data..
}
void u_Object::makeLimbs(){
dbPerformChecklistForObjectLimbs( m_iID);
int quantity=dbChecklistQuantity();
m_numLimbs = quantity;
m_limbs = new char *[ quantity ];
for (int x=0;x<quantity;x++)
{
//if(!strcmp(m_limbs[ x ], "$NoName$ "))
m_limbs[ x ] = new char[ 64 ];
sprintf( m_limbs[ x ], "%s", dbChecklistString( x ) );
char out[256];
sprintf (out,"<%d is %s n", x, m_limbs[ x ] );//offset to match id to name
//OutputDebugString (out);
}
}
int u_Object::getLimbs(){
dbPerformChecklistForObjectLimbs( m_iID);
return dbChecklistQuantity();
}
int u_Object::findEntityByName( const char *szName ) {
for( int x = 0; x < m_numLimbs; x++ ) {
if( !strcmp( szName, m_limbs[ x ] ) ) {
return x;
}
}
}
void u_Object::makeFromLimb(int iNewObject, int iLimb) {
dbMakeObjectFromLimb (iNewObject, m_iID, iLimb);
}
void u_Object::glueLimb(int iSecondObject, int iLimb) {
dbGlueObjectToLimb ( m_iID, iSecondObject, iLimb ) ;
}
void u_Object::addLimb(int iLimb, int iMesh) {
dbAddLimb ( m_iID, iLimb, iMesh );
}
void u_Object::limbHide(int iLimb){
dbHideLimb (m_iID, iLimb);
}
float u_Object::limbGetPositionX(int iLimb){
return (dbLimbOffsetX (m_iID,iLimb));
}
float u_Object::limbGetPositionY(int iLimb){
return (dbLimbOffsetY (m_iID,iLimb));
}
float u_Object::limbGetPositionZ(int iLimb){
return (dbLimbOffsetZ (m_iID,iLimb));
}
float u_Object::limbGetScaleX(int iLimb){
return (dbLimbScaleX (m_iID,iLimb));
}
float u_Object::limbGetScaleY(int iLimb){
return (dbLimbScaleY (m_iID,iLimb));
}
float u_Object::limbGetScaleZ(int iLimb){
return (dbLimbScaleZ (m_iID,iLimb));
}
float u_Object::limbGetRotationX(int iLimb){
return (dbLimbDirectionX (m_iID,iLimb));
}
float u_Object::limbGetRotationY(int iLimb){
return (dbLimbDirectionY (m_iID,iLimb));
}
float u_Object::limbGetRotationZ(int iLimb){
return (dbLimbDirectionZ (m_iID,iLimb));
}
Vector3 u_Object::limbGetPosition(int iLimb) {
Vector3 iVector3(dbLimbOffsetX(m_iID,iLimb),dbLimbOffsetY(m_iID,iLimb),dbLimbOffsetZ(m_iID,iLimb));
return (iVector3);
}
Vector3 u_Object::limbGetWorldPosition(int iLimb) {
Vector3 iVector3(dbLimbPositionX(m_iID,iLimb),dbLimbPositionY(m_iID,iLimb),dbLimbPositionZ(m_iID,iLimb));
return (iVector3);
}
Vector3 u_Object::limbGetScale(int iLimb) {
Vector3 iVector3(dbLimbScaleX(m_iID,iLimb),dbLimbScaleY(m_iID,iLimb),dbLimbScaleZ(m_iID,iLimb));
return (iVector3);
}
Vector3 u_Object::limbGetRotation(int iLimb) {
Vector3 iVector3(dbLimbDirectionX(m_iID,iLimb),dbLimbDirectionY(m_iID,iLimb),dbLimbDirectionZ(m_iID,iLimb));
return (iVector3);
}
void u_Object::limbSetPositionX(int iLimb,float fX ){
dbOffsetLimb (m_iID, iLimb, fX, limbGetPositionY(iLimb) ,limbGetPositionZ(iLimb));
}
void u_Object::limbSetPositionY(int iLimb,float fY ){
dbOffsetLimb (m_iID, iLimb, limbGetPositionX(iLimb), fY ,limbGetPositionZ(iLimb));
}
void u_Object::limbSetPositionZ(int iLimb,float fZ ){
dbOffsetLimb (m_iID, iLimb, limbGetPositionX(iLimb), limbGetPositionY(iLimb) ,fZ);
}
void u_Object::limbSetScaleX(int iLimb,float fX ){
dbScaleLimb (m_iID, iLimb, fX, limbGetScaleY(iLimb) ,limbGetScaleZ(iLimb));
}
void u_Object::limbSetScaleY(int iLimb,float fY ){
dbScaleLimb (m_iID, iLimb, limbGetScaleX(iLimb), fY ,limbGetScaleZ(iLimb));
}
void u_Object::limbSetScaleZ(int iLimb,float fZ ){
dbScaleLimb (m_iID, iLimb, limbGetScaleX(iLimb), limbGetScaleY(iLimb) ,fZ);
}
void u_Object::limbSetRotationX(int iLimb,float fX ){
dbRotateLimb (m_iID, iLimb, fX, limbGetRotationY(iLimb) ,limbGetRotationZ(iLimb));
}
void u_Object::limbSetRotationY(int iLimb,float fY ){
dbRotateLimb (m_iID, iLimb, limbGetScaleX(iLimb), fY ,limbGetRotationZ(iLimb));
}
void u_Object::limbSetRotationZ(int iLimb,float fZ ){
dbRotateLimb (m_iID, iLimb, limbGetRotationX(iLimb), limbGetRotationY(iLimb) ,fZ);
}
void u_Object::limbSetPosition(int iLimb,float fX, float fY, float fZ ){
dbOffsetLimb (m_iID, iLimb, fX, fY, fZ );
}
void u_Object::limbSetPosition(int iLimb,Vector3 &iVector ){
dbOffsetLimb (m_iID, iLimb, iVector.getX(), iVector.getX(), iVector.getX() );
}
void u_Object::limbSetScale(int iLimb,float fX, float fY, float fZ ){
dbScaleLimb (m_iID, iLimb, fX, fY, fZ );
}
void u_Object::limbSetScale (int iLimb, float fX, float fY, float fZ ,int iBoundFlag)
{
dbScaleLimb ( m_iID, iLimb, fX, fY, fZ , iBoundFlag);
}
void u_Object::limbSetScale(int iLimb,Vector3 &iVector ){
dbScaleLimb (m_iID, iLimb, iVector.getX(), iVector.getX(), iVector.getX() );
}
void u_Object::limbSetScale (int iLimb, Vector3 &iVector ,int iBoundFlag)
{
dbScaleLimb (m_iID, iVector.getX(), iVector.getX(), iVector.getX(), iBoundFlag);
}
void u_Object::limbSetRotation(int iLimb,float fX, float fY, float fZ ){
dbRotateLimb (m_iID, iLimb, fX, fY, fZ );
}
void u_Object::limbSetRotation(int iLimb,Vector3 &iVector ){
dbRotateLimb (m_iID, iLimb, iVector.getX(), iVector.getX(), iVector.getX() );
}
int u_Object::getNextID( void )
{
return ObjectFactory::getInstance( )->getNextIDOnly( );
}
/*
void dbOffsetLimb ( int iObject, int iLimb, float fX, float fY, float fZ )
dbScaleLimb : void dbScaleLimb ( int iObject, int iLimb, float fX, float fY, float fZ )
dbRotateLimb : void dbRotateLimb ( int iObject, int iLimb, float fX, float fY, float fZ )
dbShowLimb : void dbShowLimb ( int iObject, int iLimb )
dbHideLimb : void dbHideLimb ( int iObject, int iLimb )
dbTextureLimb : void dbTextureLimb ( int iObject, int iLimb, int iImage )
dbColorLimb : void dbColorLimb ( int iObject, int iLimb, int iColor )
dbScaleLimbTexture : void dbScaleLimbTexture ( int iObjct, int iLimb, float fU, float fV )
dbScrollLimbTexture : void dbScrollLimbTexture ( int iObject, int iLmb, float fX, float fY )
dbRemoveLimb : void dbRemoveLimb ( int iObject, int iLimb )
dbSetLimbSmoothing : void dbSetLimbSmoothing ( int iObject, int iLimb, int iPercentage )
*/
void u_Object::destroy( void ) {
dbDeleteObject( m_iID );
for( int x = 0; x < m_numLimbs; x++ )
{
delete [] m_limbs[ x ];
}
delete [] m_limbs;
}
the factory
#include "ObjectFactory.h"
ObjectFactory *ObjectFactory::m_pInstance = 0;
ObjectFactory::ObjectFactory( void ) {
m_iNextID = 0;
}
ObjectFactory::~ObjectFactory( void ) {
}
int ObjectFactory::getNextID( void ) {
return ++m_iNextID;
}
int ObjectFactory::getNextIDOnly ( void ) {
return m_iNextID;
}
int ObjectFactory::getCurrentID( void ) {
return m_iNextID;
}
ObjectFactory *ObjectFactory::getInstance( void ) {
if( !m_pInstance ) {
m_pInstance = new ObjectFactory( );
}
return m_pInstance;
}
void ObjectFactory::deleteInstance( void ) {
if( !m_pInstance ) {
return;
}
delete m_pInstance;
m_pInstance = 0;
}
the factory can be used for all classes. Otherwise you can create a new one for each. Basically it creates an ID for each instance of a class construction. So if you use one object factory you get..
bipmap1 ID 1
bitmap2 ID 2
object1 ID 3
object2 ID 4
sprite1 ID 5
sprite2 ID 6
other wise with multiple factories you could get.
bipmap1 ID 1
bitmap2 ID 2
object1 ID 1
object2 ID 2
sprite1 ID 1
sprite2 ID 2
really makes no difference since ID's be come transparent at that point.
There is a getID function to get the ID. Also its not hard to make a find by id function if needed..
we did the following..
Vector class
Terrain class
Sprite class
Object class
Light class
Input class
Image class
D3DText class
Camera class
Bitmap Class
kBessa, like I mentioned before if you wish to package this together with yours let me know. Would be nice to source control it if there is enough interest. So far we just use it in house.