Interacting with nodes from an .Irr file
Interacting with nodes from an .Irr file
I seriously can't find anything on this...
I've successfuly loaded an .irr file but how do I interact with the stuff in there? I have two meshes in it called Terrain and PlayerMdl and want my camera to look on PlayerMdl (for example). But I can't do it without redeclaring PlayerMdl somewhere in my code o.O So how do I do it?
I've successfuly loaded an .irr file but how do I interact with the stuff in there? I have two meshes in it called Terrain and PlayerMdl and want my camera to look on PlayerMdl (for example). But I can't do it without redeclaring PlayerMdl somewhere in my code o.O So how do I do it?
If it exists, it can be broken.
-
Lonesome Ducky
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
Code: Select all
smgr->getSceneNodeFromName("PlayerMdl");But the scene node is an IMeshSceneNode (or supposed to be) and it says it can't convert one to the other.
Edit:
I'm so tired with getting this to work... Right now when I try to run it I get an unhandled exception error. Here's all my code so far:
Can someone please, pretty please make it work again? 
Edit:
I'm so tired with getting this to work... Right now when I try to run it I get an unhandled exception error. Here's all my code so far:
Code: Select all
#include "stdafx.h" //Must be included to work
#include <irrlicht.h> //Include IrrLicht
using namespace irr; //Namespaces
using namespace core; //Namespaces
using namespace scene; //Namespaces
using namespace video; //Namespaces
using namespace io; //Namespaces
using namespace gui; //Namespaces
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
//^Setting up various stuff^
//Creating variables
float px; //player X position (default=0)
float py; //player Y position (default=140)
float pz; //player Z position (default=0)
float protx; //player X rotation (default=0)
float proty; //player Y rotation (default=0)
float protz; //player Z rotation (default=0)
double playerspeed; //player speed (default=0.035)
double playerrotspeed; //player rotation speed (default=0.15)
bool keys[KEY_KEY_CODES_COUNT]; //key codes (for movement and stuff)
//Keyboard input receiver ahead!
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];
};
//End of keyboard input receiver
int main(){
MyEventReceiver receiver; //Create the event receiver (for receiving keyboard input)
IrrlichtDevice *device = createDevice(EDT_DIRECT3D9, dimension2d<s32>(1024, 768), 32,
false, false, false, &receiver); //Create the window and device
if(!device) //Meh
return 1; //Return 1 on error
device->setWindowCaption(L"Waste Rage"); //Set the window caption
IVideoDriver* driver = device->getVideoDriver(); //Loading...
ISceneManager* smgr = device->getSceneManager(); //Loading...
IGUIEnvironment* guienv = device->getGUIEnvironment(); //Loading...
ITexture* logo_small = driver->getTexture("C:/Users/Dandi8/Documents/Visual Studio 2008/Projects/irrLicht_helloworld/Debug/Data/Gfx/logo_small.png");
smgr->loadScene("C:/Users/Dandi8/Documents/Visual Studio 2008/Projects/irrLicht_helloworld/Debug/Data/Maps/WRMap.irr");
IMesh* mesh = smgr->getMesh("C:/Users/Dandi8/Documents/Visual Studio 2008/Projects/irrLicht_helloworld/Debug/Data/Models/Terrain.obj"); //Load the terrain model
ISceneNode* Terrain = smgr->getSceneNodeFromName("Terrain");
ISceneNode* PlayerMdl = smgr->getSceneNodeFromName("PlayerMdl");
PlayerMdl->drop();
ICameraSceneNode* cam = smgr->addCameraSceneNode(); //Add camera
playerspeed=0.15; //Set player's speed
playerrotspeed=0.15; //Set player's rotation speed
PlayerMdl->setPosition(vector3df(px,py,pz)); //Set player's position
//Collision ahead!
scene::ITriangleSelector* level_selector = 0;
scene::ITriangleSelector* player_selector = 0;
level_selector = smgr->createOctTreeTriangleSelector(mesh, Terrain, 128);
Terrain->setTriangleSelector(level_selector);
if (level_selector)
{
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
level_selector, PlayerMdl, core::vector3df(10,10,10),
core::vector3df(0,0,0),
core::vector3df(0,0,0));
PlayerMdl->addAnimator(anim);
anim = smgr->createCollisionResponseAnimator(
level_selector, cam, core::vector3df(1,1,1),
core::vector3df(0,0,0),
core::vector3df(0,py,0), 1);
level_selector->drop();
cam->addAnimator(anim);
anim->drop();
}
guienv->addImage(logo_small, core::position2d<s32>(10,10));
while(device->run()){
driver->beginScene(true, true, SColor(255, 144, 255, 140)); //Begin the scene
//movement ahead!
if(receiver.IsKeyDown(irr::KEY_KEY_W) || receiver.IsKeyDown(irr::KEY_UP)){
px = sin(double (proty * irr::core::DEGTORAD)) * playerspeed;
pz = cos(double (proty * irr::core::DEGTORAD)) * playerspeed;
PlayerMdl->setPosition(PlayerMdl->getPosition() + vector3df(px,0,pz)); //Set player's position
}
if(receiver.IsKeyDown(irr::KEY_KEY_S) || receiver.IsKeyDown(irr::KEY_DOWN)){
px = sin(double (proty * irr::core::DEGTORAD)) * playerspeed;
pz = cos(double (proty * irr::core::DEGTORAD)) * playerspeed;
PlayerMdl->setPosition(PlayerMdl->getPosition() - vector3df(px,0,pz)); //Set player's position
}
if(receiver.IsKeyDown(irr::KEY_KEY_A) || receiver.IsKeyDown(irr::KEY_LEFT)){
proty-=playerrotspeed;
}
if(receiver.IsKeyDown(irr::KEY_KEY_D) || receiver.IsKeyDown(irr::KEY_RIGHT)){
proty+=playerrotspeed;
}
if(receiver.IsKeyDown(irr::KEY_KEY_E) || receiver.IsKeyDown(irr::KEY_KEY_X)){
px = sin(double ((proty+90) * irr::core::DEGTORAD)) * playerspeed;
pz = cos(double ((proty+90) * irr::core::DEGTORAD)) * playerspeed;
PlayerMdl->setPosition(PlayerMdl->getPosition() + vector3df(px,0,pz)); //Set player's position
}
if(receiver.IsKeyDown(irr::KEY_KEY_Q) || receiver.IsKeyDown(irr::KEY_KEY_Z)){
px = sin(double ((proty+90) * irr::core::DEGTORAD)) * playerspeed;
pz = cos(double ((proty+90) * irr::core::DEGTORAD)) * playerspeed;
PlayerMdl->setPosition(PlayerMdl->getPosition() - vector3df(px,0,pz)); //Set player's position
}
//end of movement!
PlayerMdl->setRotation(vector3df(protx,proty,protz)); //Set player's rotation
cam->setPosition(PlayerMdl->getPosition() - vector3df(sin(double (proty * irr::core::DEGTORAD)) * 35, -15, cos(double (proty * irr::core::DEGTORAD)) * 35)); //Alternate cam
cam->setTarget(PlayerMdl->getPosition()); //Make the camera look at the vehicle
smgr->drawAll(); //Draw the scene
guienv->drawAll(); //Draw the GUI
driver->endScene(); //End the scene
}
device->drop(); //Destroy the device
return 0; //Return the zero
}
If it exists, it can be broken.
-
Lonesome Ducky
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
Code: Select all
PlayerMdl->drop(); Stupid me! It was a leftover from previous experiments. Now it launches 
Question #2:
Why are there strange outlines in my terrain? How do I get rid of them? Notice they only appear far away.

And question #3:
Is there a way to isolate X, Y and Z (extract them to 3 different variables) from the getPosition function? I basicaly want to get X and Z of a model in space.
Question #2:
Why are there strange outlines in my terrain? How do I get rid of them? Notice they only appear far away.

And question #3:
Is there a way to isolate X, Y and Z (extract them to 3 different variables) from the getPosition function? I basicaly want to get X and Z of a model in space.
If it exists, it can be broken.
-
Lonesome Ducky
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
For the position:
Same with y and z.
As for the terrain, it looks like a mip mapping problem. Try disabling mipmaps and see if it gets rid of the problem.
Code: Select all
float x = node->getPosition().X;As for the terrain, it looks like a mip mapping problem. Try disabling mipmaps and see if it gets rid of the problem.
-
Lonesome Ducky
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
Before you load the model:
and after:
Code: Select all
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS,false);Code: Select all
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS,true);-
Lonesome Ducky
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
Just tried it, it werkz! Another question though - this time concerning something different entirely. Dynamic shadows - how to enable them? Scrolling through the driver's functions I've found drawStencilShadowVolume and drawStencilShadow, which I believe should be executed in that order. But I don't really know what to write in the parameters nor if I need anything else for that to work?
If it exists, it can be broken.
-
Lonesome Ducky
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm