Need Help With Vertex Buffer

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
IrrNoob
Posts: 110
Joined: Sun Nov 16, 2008 8:01 pm
Location: Fort Collins, Us

Post by IrrNoob »

I see your point. I changed it to that.

Oh, the documents for SPE are helpful, but all of the examples are done in Directx, and I do not understand directx library. The information I got about Initialize() was taken from that documents page.

But I'm getting an error here:

Code: Select all

vb [used_vertices].x = pv->Pos.x; 
and on .y and .z, because they are not members of core::vector3d<T>

The code is large, so it will take me some time to understand SPE_Initialize().
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

This is the code for adding initializing a ISPEShape from an IMeshBuffer.

Code: Select all

void InitShape(ISPEShape* pShape, const scene::IMeshBuffer* pMeshBuffer)
{
    u32 stride = 0;

    switch (pMeshBuffer->getVertexType())
    {
      case video::EVT_STANDARD:
        stride = sizeof (video::S3DVertex);
        break;
      case video::EVT_2TCOORDS:
        stride = sizeof (video::S3DVertex2TCoords);
        break;
      case video::EVT_TANGENTS:
        stride = sizeof (video::S3DVertexTangents);
        break;
    }


    if(pMeshBuffer->getIndexType() == EIT_32BIT)  // 32BIT index
    {
        pShape->Initialize ((BYTE*)pMeshBuffer->getVertices(),
                            stride,
                            (int*)pMeshBuffer->getIndices(),
                            pMeshBuffer->getIndexCount() / 3);
    }
    else  // 16BIT index
    {
        pShape->Initialize ((BYTE*)pMeshBuffer->getVertices(),
                            stride,
                            (WORD*)pMeshBuffer->getIndices(),
                            pMeshBuffer->getIndexCount() / 3);
    }
}
It looks like you would create a ISPEShape for each mesh buffer, associate those shapes with their own ISPERigidBody, and join them using ISPEJoints. So all of that code I posted above is only useful for static meshes.

Travis
Last edited by vitek on Mon Jan 12, 2009 5:20 am, edited 1 time in total.
IrrNoob
Posts: 110
Joined: Sun Nov 16, 2008 8:01 pm
Location: Fort Collins, Us

Post by IrrNoob »

I'm sorry if this is a dumb question, but what is pMesh in InitShape()?
because in the first samples of SPE, pMesh is a LPSPERIGIDBODY.
At the moment I get a error about that. The call to

Code: Select all

pmesh->getIndexType() == EIT_32BIT
means that its pmesh is a member of IMeshBuffer, right?

oh, and I see were I was mistaken, ISPEShape is the struct of Initialize().
vitek wrote: It looks like you would create a ISPEShape for each mesh buffer, associate those shapes with their own ISPERigidBody, and join them using ISPEJoints. So all of that code I posted above is only useful for static meshes.
So this means I need to find out how this is done, in order to get animated meshs, correct? And you mean meshes that don't move when you say "static". I'll search the SPE document.

I see ISPEJoint Reference in there...
looks like I can do this with

Code: Select all

 virtual ISPERigidBody* GetBody(int index) = 0;
     Get one of rigid body linked by this joint. 
 
Parameters
    index
        [in] Rigid body index, 0 or 1.
    
Return
        Interface of the rigid body.
But this is for animated meshs that have joints?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

IrrNoob wrote:I'm sorry if this is a dumb question, but what is pMesh in InitShape()?
Code fixed...

IrrNoob wrote:So this means I need to find out how this is done, in order to get animated meshs, correct? And you mean meshes that don't move when you say "static". I'll search the SPE document.
Yes, and yes.
IrrNoob
Posts: 110
Joined: Sun Nov 16, 2008 8:01 pm
Location: Fort Collins, Us

Post by IrrNoob »

Ok, heres what I have so far:

Code: Select all


#include <irrlicht.h>
#include <SPE.h>
#include <iostream>


#pragma comment(lib, "Irrlicht.lib")
#pragma comment(lib, "SPE.lib")

using namespace irr;
using namespace core; 
using namespace scene; 
using namespace video; 
using namespace io; 
using namespace gui;



void InitShape(ISPEShape* pShape, const scene::IMeshBuffer* pMeshBuffer) 
{ 
    u32 stride = 0; 

    switch (pMeshBuffer->getVertexType()) 
    { 
      case video::EVT_STANDARD: 
        stride = sizeof (video::S3DVertex); 
        break; 
      case video::EVT_2TCOORDS: 
        stride = sizeof (video::S3DVertex2TCoords); 
        break; 
      case video::EVT_TANGENTS: 
        stride = sizeof (video::S3DVertexTangents); 
        break; 
    } 


    if(pMeshBuffer->getIndexType() == EIT_32BIT)  // 32BIT index 
    { 
        pShape->Initialize ((BYTE*)pMeshBuffer->getVertices(), 
                            stride, 
                            (int*)pMeshBuffer->getIndices(), 
                            pMeshBuffer->getIndexCount() / 3); 
    } 
    else  // 16BIT index 
    { 
        pShape->Initialize ((BYTE*)pMeshBuffer->getVertices(), 
                            stride, 
                            (WORD*)pMeshBuffer->getIndices(), 
                            pMeshBuffer->getIndexCount() / 3); 
    } 
} 


int main()
{


      IrrlichtDevice* device = 0;

	  // select opengl as driver type
	 video::E_DRIVER_TYPE driverType = video::EDT_OPENGL;

	  // create device
	  device = createDevice(driverType, core::dimension2d<s32>(1024, 768), 32,
		/*fullscreen*/true, /*stencilbuffer*/false, /*vsync*/true, 0);
	  if (device == 0)
		return 1; // could not create selected driver.

      ICameraSceneNode* camera = 0;
      video::IVideoDriver* driver = device->getVideoDriver();
      scene::ISceneManager* smgr = device->getSceneManager();

      scene::IAnimatedMesh* lilman = smgr->getMesh("media/LittleMan.md2");


	  smgr->addLightSceneNode(0, core::vector3df(3800,-1100,7400),
		video::SColorf(1.0f,1.0f,1.0f,1.0f),
		600.0f);

	// add camera
    // CREATE WASD KEYMAP ARRAY 
    SKeyMap keyMapWASD[5]; 
    keyMapWASD[0].Action = EKA_MOVE_FORWARD; 
    keyMapWASD[0].KeyCode = KEY_KEY_W; 
    keyMapWASD[1].Action = EKA_MOVE_BACKWARD; 
    keyMapWASD[1].KeyCode = KEY_KEY_S; 
    keyMapWASD[2].Action = EKA_STRAFE_LEFT; 
    keyMapWASD[2].KeyCode = KEY_KEY_A; 
    keyMapWASD[3].Action = EKA_STRAFE_RIGHT; 
    keyMapWASD[3].KeyCode = KEY_KEY_D; 
    keyMapWASD[4].Action = EKA_JUMP_UP; 
    keyMapWASD[4].KeyCode = KEY_SPACE; 
    camera = smgr->addCameraSceneNodeFPS(0,100.0f,1.f,0,keyMapWASD, 5, true, 3);

	camera->setPosition(core::vector3df(3800,-350,7400));
	camera->setTarget(core::vector3df(4794,-686,3400));
	camera->setFarValue(12000.0f);
	camera->setNearValue(1.0f);
   
    
	// disable mouse cursor
	device->getCursorControl()->setVisible(false);


    SPEVector Eye, At;
    LPSPEWORLD  pWorld;
    LPSPERIGIDBODY  pMesh; 

    Eye=SPEVector(10,20,10)*0.8;
	At=SPEVector(0,0,0);

	pWorld = CreateSPEWorld();
	//pWorld->SetGravity (SPEVector(0, -9.8f, 0));;  // this is the default value of gravity in SPE

    LPSPESHAPE pShape = pWorld->CreateShape();
    const scene::IMeshBuffer* pMeshBuffer = lilman->getMeshBuffer(0); 

    InitShape( pShape, pMeshBuffer);

	pMesh = pWorld->AddRigidBody (pShape);
	pMesh->SetBeStatic(true);
	pMesh->SetPosition (SPEVector(0,0,0));

    scene::IAnimatedMeshSceneNode* node = 0;
    node = smgr->addAnimatedMeshSceneNode(lilman);


	/*InitShape( pShape, pMeshBuffer2);
	pMesh2 = pWorld->AddRigidBody (pShape);
	pMesh2->SetPosition (SPEVector(2, 0, 2));
	pMesh2->SetOrientation (SPEMatrix::mAnglesZYX (0,90,0));
	pMesh2->SetVelocity (SPEVector(0,5,0));
	pMesh2->SetAngularVelocity (SPEVector(0,0,20));*/

	pWorld->ReleaseShape(pShape);	


    u32 previous = device->getTimer()->getTime();

	while(device->run()){
                         

//-----------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------                    
 
	  const u32 current = device->getTimer()->getTime(); 
      float fElapsedTime = (float*)current - (float*)previous;
	  pWorld->Update (fElapsedTime);
	  previous = current;

 //-----------------------------------------------------------------------------------------------------------------
 //-----------------------------------------------------------------------------------------------------------------              
     if (device->isWindowActive())
	 {
		driver->beginScene(true, true, 0 );

		smgr->drawAll();

		driver->endScene();


	 }}



 device->drop();
	
	return 0;
}
No errors compiling, but it crashes after a minute because theres a memory leak. I haven't setup proper rendering either nothing is being rendered. Debugging reveals nothing about the problem.
IrrNoob
Posts: 110
Joined: Sun Nov 16, 2008 8:01 pm
Location: Fort Collins, Us

Post by IrrNoob »

I'm still not sure how to fix the memory leaking, and I have no idea why the mesh is not rendering. I changed the mesh to an IMesh but that didn't work.
Post Reply