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.