ok well im very exhausted atm. been a long day at work
![Smile :)](./images/smilies/icon_smile.gif)
. been helping out someone with landscaping so by the end of the day its hard to think of complex things XD.
um i managed to get the camera i wanted. i came up with the idea that since i am moving the model on a 2d plane. i can move the camera aswell. this way i can set the camera where i want it to be and then it only flows it if it moves and doesnt rotat with the model.
but the things i dont know how to do. i work out how to move the model forward once it has turned off of the z axis. do i have to do some calculation that checks how far the model has moved from the z axis and move it forward from how far its from the z axis?
then next thing i cant work out aswell. is i want the model to tilt. and i want it to tilt about 150 degrees. basicly think of it as a RL plane. how it banks and then turns. i want the model to bank and turn on the spot. i got the turning on the spot but if i add tilting into the eqation it thoughs of all the axis. so again i need to do somthing to keep it working with the axises.
i've tried to think of ways that can do this but im not sure how becuase i just dont have enough knowledge of the irrlicht syntax.
anyway i cant seem to attach files on this forum so i have to copy and past all the code in this post. so sorry for the spam
![Sad :(](./images/smilies/icon_sad.gif)
. you will notice that the tilt code has been commented out for the moment.
Code: Select all
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(lib, "Irrlicht.lib")
#endif
#include <irrlicht.h>
#include "driverChoice.h"
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
vector3df GetIrrIn(ISceneNode* node)
{
matrix4 mat = node->getRelativeTransformation();
vector3df in(mat[8],mat[9],mat[10]);
in.normalize();
return in;
}
vector3df GetIrrUp(ISceneNode* node)
{
matrix4 mat = node->getRelativeTransformation();
vector3df up(mat[4],mat[5],mat[6]);
up.normalize();
return up;
}
vector3df GetIrrLeft(ISceneNode* node)
{
matrix4 mat = node->getRelativeTransformation();
vector3df left(mat[0],mat[1],mat[2]);
left.normalize();
return left;
}
vector3df GetPointInFront(ISceneNode* node, float distance)
{
vector3df p = node->getPosition();
p += distance * GetIrrIn(node);
return p;
};
vector3df GetPointInBack(ISceneNode* node,float distance)
{
vector3df p = node->getPosition();
p -= distance * GetIrrIn(node);
return p;
};
vector3df GetPointAbove(ISceneNode* node,float distance)
{
vector3df p = node->getPosition();
p += distance * GetIrrUp(node);
return p;
};
vector3df GetPointBelow(ISceneNode* node, float distance)
{
vector3df p = node->getPosition();
p -= distance * GetIrrUp(node);
return p;
};
vector3df GetPointInFrontAndAbove(ISceneNode* node,float d, float u)
{
vector3df p = GetPointInFront(node,d);
p.Y = GetPointAbove(node,u).Y;
return p;
};
vector3df GetPointInBackAndAbove(ISceneNode* node,float d, float u)
{
vector3df p = GetPointInBack(node,d);
p.Y = GetPointAbove(node,u).Y;
return p;
};
class MyEventReceiver : public IEventReceiver
{
public:
// This is the one method that we have to implement
virtual bool OnEvent(const SEvent& event)
{
// Remember whether each key is down or up
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
}
// This is used to check whether a key is being held down
virtual bool IsKeyDown(EKEY_CODE keyCode) const
{
return KeyIsDown[keyCode];
}
MyEventReceiver()
{
for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
KeyIsDown[i] = false;
}
private:
// We use this array to store the current state of each key
bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
int main()
{
// ask user for driver
video::E_DRIVER_TYPE driverType=driverChoiceConsole();
if (driverType==video::EDT_COUNT)
return 1;
// create device
MyEventReceiver receiver;
IrrlichtDevice* device = createDevice(driverType,
core::dimension2d<u32>(640, 480), 16, false, false, false, &receiver);
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
IAnimatedMesh* usership = smgr->getMesh("C:/Users/Jordan/Documents/My Received Files/Space_Ship_35.3DS");
if (!usership)
{
device->drop();
return 1;
}
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(usership);
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMaterialTexture( 0, driver->getTexture("C:/Users/Jordan/Documents/My Received Files/Space_Ship_35_Texmap.png") );
}
//load camera at the right distance from the model and remove cursor
ICameraSceneNode* camera = smgr->addCameraSceneNode(0, vector3df(-500,600,500));
device->getCursorControl()->setVisible(false);
int lastFPS = -1;
u32 then = device->getTimer()->getTime();
// This is the movemen speed in units per second.
const f32 MOVEMENT_SPEED = 2000.f;
const f32 ROTATION_SPEED = 100.f;
while(device->run())
{
// Work out a frame delta time.
const u32 now = device->getTimer()->getTime();
const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
then = now;
vector3df nodePosition = node->getPosition();
vector3df cameraPosition = camera->getPosition();
vector3df rotation = node->getRotation();
if(receiver.IsKeyDown(irr::KEY_KEY_W))
{
nodePosition.Z -= MOVEMENT_SPEED * frameDeltaTime;
cameraPosition.Z -= MOVEMENT_SPEED * frameDeltaTime;
}
else if(receiver.IsKeyDown(irr::KEY_KEY_S))
{
nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime;
cameraPosition.Z += MOVEMENT_SPEED * frameDeltaTime;
}
if(receiver.IsKeyDown(irr::KEY_KEY_A))
{
rotation.Y += ROTATION_SPEED * frameDeltaTime;
/*rotation.Z += ROTATION_SPEED * frameDeltaTime;*/
node->setRotation(rotation);
}
else if(receiver.IsKeyDown(irr::KEY_KEY_D))
{
rotation.Y -= ROTATION_SPEED * frameDeltaTime;
node->setRotation(rotation);
/*rotation.Z -= ROTATION_SPEED * frameDeltaTime;
node->setRotation(rotation);*/
}
//set postions of camera and node
node->setPosition(nodePosition);
camera->setPosition(cameraPosition);
/*Set camera to look at node*/
camera->setTarget(node->getPosition());
driver->beginScene(true, true, video::SColor(255,113,113,133));
smgr->drawAll(); // draw the 3d scene
device->getGUIEnvironment()->drawAll(); // draw the gui environment (the l
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw tmp(L"Movement Example - Irrlicht Engine [");
tmp += driver->getName();
tmp += L"] fps: ";
tmp += fps;
device->setWindowCaption(tmp.c_str());
lastFPS = fps;
}
}
/*
In the end, delete the Irrlicht device.
*/
device->drop();
return 0;
}
/*
That's it. Compile and play around with the program.
**/
thanks againg for all the help you been giving me. I am very greatful i dont know how i would of got as far as i have wihtout this help hehe
![Smile :)](./images/smilies/icon_smile.gif)
.
cgcgames