Jump to content
  • Advertisement
Sign in to follow this  
DigiMan Shart

CAL3D Create Function

This topic is 3469 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was looking through the CAL3D documentation and saw that they say to call the "create: function of the CalCoreModel to create a core model, but when I tried doing that within my code the compiler says "create is not a member of CalCoreModel" and when I check the CAL3D headers, the only file that has create within it is in skeleton.h. I was wondering if anyone could suggest what I should do or any mistakes I may be making. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
I'm going to sleep, but I leave you a class I managed to write based on the Cal3d examples source code.


/*===============================================================================

model.h

Damian Gabriel Paz


================================================================================*/


#ifndef INCLUDE_SKELETAL_CSKMODEL_H
#define INCLUDE_SKELETAL_CSKMODEL_H

#include <cal3d/cal3d.h>
#include <vector>
using namespace std;

/*================================================================================*/

namespace engine
{
/*-= cmodel3d =- ===============================================================

Main application object
================================================================================*/

class cmodel3d
{
// member variables
protected:
CalCoreModel* m_CalCoreModel;
CalModel* m_CalModel;
vector<int> m_Animations;
float m_fRenderScale;
float m_fLodLevel;
float m_fFpsDuration;
int m_iFpsFrames;
int m_iFps;
unsigned int m_iLastTick;

public:
// Construction
cmodel3d();
virtual ~cmodel3d();

public:
// Get
float lod_level ( void );
float render_scale ( void );

// Set
void lod_level ( float lodLevel );

// Initialization
void setup ();
bool load_skeleton (string filepath);
bool load_mesh (string filepath);
bool load_animation (string filepath);
bool load_material (string filepath);

// Actions
void render ( void );
void update ( const uint32_t& ticks );

void render_mesh ( void );
void render_skeleton ( void );
void render_bounding_box ( void );

void run_animation (int id);

};
}

/*================================================================================*/

#endif

/*=================================================================================
-= End of file =-
==================================================================================*/








/*===============================================================================

cskmodel.cpp

Damian Gabriel Paz


================================================================================*/


#include "model3d.h"
// Windows libraries
#include "../platform/os.h"
// Opengl libraries
#include "../platform/opengl.h"

using namespace engine;

/*-= cmodel3d =-*\==================================================================

Constructor ( )

=================================================================================*/

cmodel3d::cmodel3d()
{
// Create a new instance of CalCoreModel
m_CalCoreModel = new CalCoreModel("dummy");
m_CalModel = 0;
m_fRenderScale = 1.0f;
m_fLodLevel = 1.0f;

m_fFpsDuration = 0.0f;
m_iFpsFrames = 0;
m_iFps = 0;
// m_iLastTick = CSystem::Clock.Ticks();;
}

/*-= cmodel3d =-*\==================================================================

Destructor ( )

=================================================================================*/

cmodel3d::~cmodel3d()
{
delete m_CalModel;
delete m_CalCoreModel;
}

/*-= cmodel3d =-*\==================================================================

Setup ( )

=================================================================================*/

void cmodel3d::setup()
{
// Calculate Bounding boxes
CalCoreSkeleton* pSkeleton = m_CalCoreModel->getCoreSkeleton();
if (NULL != pSkeleton)
pSkeleton->calculateBoundingBoxes(m_CalCoreModel);

// Create a new instance of CalModel
delete m_CalModel;
m_CalModel = new CalModel(m_CalCoreModel);

// attach all meshes to the model
int meshId;
for(meshId = 0; meshId < m_CalCoreModel->getCoreMeshCount(); meshId++)
m_CalModel->attachMesh(meshId);

}

/*-= cmodel3d =-*\==================================================================

LoadSkeleton ( )

=================================================================================*/

bool cmodel3d::load_skeleton(string filepath)
{
return m_CalCoreModel->loadCoreSkeleton(filepath);
}

/*-= cmodel3d =-*\==================================================================

LoadMesh ( )

=================================================================================*/

bool cmodel3d::load_mesh(string filepath)
{
return m_CalCoreModel->loadCoreMesh(filepath);
}

/*-= cmodel3d =-*\==================================================================

LoadAnimation ( )

=================================================================================*/

bool cmodel3d::load_animation(string filepath)
{
int val = m_CalCoreModel->loadCoreAnimation(filepath);

if (-1 == val) return false;

m_Animations.push_back(val);

return true;
}

/*-= cmodel3d =-*\==================================================================

LoadMaterial ( )

=================================================================================*/

bool cmodel3d::load_material(string filepath)
{
return m_CalCoreModel->loadCoreMaterial(filepath);
}

/*-= cmodel3d =-*\==================================================================

RenderSkeleton ( )

=================================================================================*/

void cmodel3d::render_skeleton( void)
{
// TODO (xaxa#1#): Find out how to get SKELETON information from Cal3D and how to use it.
}

/*-= cmodel3d =-*\==================================================================

RenderBoundingBox ( )

=================================================================================*/

void cmodel3d::render_bounding_box()
{

// TODO (xaxa#1#): Find out how to get the BOUNDING BOX information from Cal3D.

}

/*-= cmodel3d =-*\==================================================================

RenderMesh ( )

=================================================================================*/

void cmodel3d::render_mesh()
{
// get the renderer of the model
CalRenderer *pCalRenderer;
pCalRenderer = m_CalModel->getRenderer();

// begin the rendering loop
if(!pCalRenderer->beginRendering()) return;

// we will use vertex arrays, so enable them
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);

// get the number of meshes
int meshCount;
meshCount = pCalRenderer->getMeshCount();

// render all meshes of the model
int meshId;
for(meshId = 0; meshId < meshCount; meshId++)
{
// get the number of submeshes
int submeshCount;
submeshCount = pCalRenderer->getSubmeshCount(meshId);

// render all submeshes of the mesh
int submeshId;
for(submeshId = 0; submeshId < submeshCount; submeshId++)
{
// select mesh and submesh for further data access
if(pCalRenderer->selectMeshSubmesh(meshId, submeshId))
{
// get the transformed vertices of the submesh
static float meshVertices[100000][3];
int vertexCount;
vertexCount = pCalRenderer->getVertices(&meshVertices[0][0]);

// get the transformed normals of the submesh
static float meshNormals[100000][3];
pCalRenderer->getNormals(&meshNormals[0][0]);

// get the texture coordinates of the submesh
/* static float meshTextureCoordinates[30000][2];
int textureCoordinateCount;
textureCoordinateCount = pCalRenderer->getTextureCoordinates(0, &meshTextureCoordinates[0][0]);
*/

// get the faces of the submesh
static CalIndex meshFaces[100000][3];
int faceCount;
faceCount = pCalRenderer->getFaces(&meshFaces[0][0]);

// set the vertex and normal buffers
glVertexPointer(3, GL_FLOAT, 0, &meshVertices[0][0]);
glNormalPointer(GL_FLOAT, 0, &meshNormals[0][0]);

/* // set the texture coordinate buffer and state if necessary
if((pCalRenderer->getMapCount() > 0) && (textureCoordinateCount > 0))
{
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_COLOR_MATERIAL);

// set the texture id we stored in the map user data
glBindTexture(GL_TEXTURE_2D, (GLuint)pCalRenderer->getMapUserData(0));

// set the texture coordinate buffer
glTexCoordPointer(2, GL_FLOAT, 0, &meshTextureCoordinates[0][0]);
glColor3f(1.0f, 1.0f, 1.0f);
}
*/

// draw the submesh
if(sizeof(CalIndex)==2)
glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_SHORT, &meshFaces[0][0]);
else
glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_INT, &meshFaces[0][0]);

// disable the texture coordinate state if necessary
/* if((pCalRenderer->getMapCount() > 0) && (textureCoordinateCount > 0))
{
glDisable(GL_COLOR_MATERIAL);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
}
*/

}
}
}

// clear vertex array state
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

// end the rendering
pCalRenderer->endRendering();

}

/*-= cmodel3d =-*\================================================================

Render ( )

=================================================================================*/

void cmodel3d::render()
{

}

/*-= cmodel3d =-*\================================================================

Update ( float )

=================================================================================*/

void cmodel3d::update(const uint32_t& ticks)
{
// get the current tick value

// tick = CSystem::Clock.Ticks();

// calculate the amount of elapsed seconds
float SecondsElapsed;
SecondsElapsed = (float)(ticks - m_iLastTick) / 1000.0f;

// adjust fps counter
m_fFpsDuration += SecondsElapsed;
if(m_fFpsDuration >= 1.0f)
{
m_iFps = (int)((float)m_iFpsFrames / m_fFpsDuration);
m_fFpsDuration = 0.0f;
m_iFpsFrames = 0;
}

// update the current model
m_CalModel->update(SecondsElapsed);

// current tick will be last tick next round
m_iLastTick = ticks;
}

void cmodel3d::run_animation (int id)
{
//m_CalModel->getMixer()->executeAction(m_Animations[id], 0.3f, 0.3f);

m_CalModel->getMixer()->blendCycle(m_Animations[0], 0.6f, 0.0f);
}

/*-= cmodel3d =-*\=================================================================

Get LodLevel ()

=================================================================================*/

float cmodel3d::lod_level()
{
return m_fLodLevel;
}

/*-= cmodel3d =-*\================================================================

Get RenderScale ( )

=================================================================================*/

float cmodel3d::render_scale()
{
return m_fRenderScale;
}

/*-= cmodel3d =-*\================================================================

Set LodLevel ( float )

=================================================================================*/

void cmodel3d::lod_level(float lodLevel)
{
m_fLodLevel = lodLevel;
m_CalModel->setLodLevel(m_fLodLevel);
}

/*=================================================================================
-= End of file =-
==================================================================================*/







[Edited by - owl on February 15, 2009 6:46:29 PM]

Share this post


Link to post
Share on other sites
I figured out my problem. The problem was the newest update to the CAL3D library removed the create functions in favor of having the constructors create the objects themselves.

Share this post


Link to post
Share on other sites
Now I'm running into another problem it seems. When I call new in my cModel Constructor my code breaks and it says the heap is corrupted.

Here's the code sample that it breaks on:

calModel = new CalCoreModel("default");

(calModel is CalCoreModel* calModel)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!