need help, im new in irrlicht...
need help, im new in irrlicht...
Can someone please show me how i can use .3ds file as a map? I am trying to make collision detection whit node and map. But when i create collision response animator and put gravity (0,-5,0), my node just fall down through the map. I use Ubuntu 8.04. Sorry my bad English.
I don't speak very good English...
-
rogerborg
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Example 07.Collision should show you how to do that. We'll need to see what you're doing differently, so please show us your code.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
CODE:
header_main:
eventhandler.h:
And debugger says that the problem is at line "selector_arena->drop();".
Don't care about comments. I speak Finnish so i write comments in finnish.
I don't know why i got "Segmentation fault". If i comment the selector_arena->drop(); line i don't get "Segmentation fault" error, but the collision will not work.
And again, i don't speak very good English...
Code: Select all
//Include
#include <irrlicht.h>
#include <iostream>
#include "header_main.h"
#include "eventhandler.h"
//Namespaces(head)
using namespace irr;
using namespace std;
//Namespaces(second)
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
int main()
{
// Event receiver
MyEventReceiver receiver;
/*
-Video moodit:EDT_BURNINGSVIDEO, EDT_NULL, EDT_DIRECT3D8, EDT_DIRECT3D9, tai EDT_OPENGL.
- windowSize: Ikkunan koko nyt 1280 x 1024, Eli X x Y.
- bits: Pixelin värimäärä, voi olla 16 tai 32. Ei toimi hyvin ikkunoidussa modissa
- fullscreen: Esitellään halutaanko ikkunoitu- vai kokoruutumodi.
- stencilbuffer: Esitellään käytetäänkö stencil bufferia (varjojen piirtämiseen).
- vsync: Esitellään halutaanko käyttää vsyciä, hyödyllinen vain kokoruutu modissa.
- eventReceiver: Objekti jolla saadaan tietoon eventit. eli näppäimistö ja hiiri tapahtumat. Koska emme halua käyttää tätä laitamme tähän parametriksi 0. Muista aina katsoa paluu arvo tunnistaaksesi epäsopivat ajurit, paikka, jne.
*/
IrrlichtDevice *device = createDevice( video::EDT_OPENGL, dimension2d<s32>(window_x, window_y), 32, false, true, false, &receiver);
if (!device) return 1;
/*
Ohjelman ja ikkunan nimike.
*/
device->setWindowCaption(window_header.c_str());
/*
Osoittimet video-,scene-,tekstiajureille.
*/
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
/*
Tekstiä yläkulmaan. Muodossa (x,y,w,h)
*/
guienv->addStaticText(L"Battle Baseball Render", rect<s32>(10,10,260,22), true);
//Ukkeli ja areena
IAnimatedMesh* mesh = smgr->getMesh("media/player/obj/test_main.3ds");
if (!mesh) return 1;
IAnimatedMesh* arena_mesh = smgr->getMesh("media/map/map_2/obj/arena.obj");
if (!arena_mesh) return 1;
IAnimatedMeshSceneNode* arena = smgr->addAnimatedMeshSceneNode(arena_mesh);
//Areena
if (arena)
{
arena->setMaterialFlag(EMF_LIGHTING, false);
arena->setMaterialTexture( 0, driver->getTexture("media/map/map_2/tex/arena_tex.png") );
arena->setScale(core::vector3df(130,130,130));
arena->setPosition(core::vector3df(1600,520,2450));
}
//Node, eli player objekti:
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
//Node
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMaterialTexture( 0, driver->getTexture("media/player/tex/test_main_tex.bmp") );
node->setScale(core::vector3df(20,20,20));
node->setPosition(core::vector3df(0,220,0));
}
/*
Kamera
*/
ICameraSceneNode* camera = smgr->addCameraSceneNode();
scene::ITriangleSelector* selector_arena = smgr->createOctTreeTriangleSelector(arena_mesh->getMesh(0), 0);
arena->setTriangleSelector(selector_arena);
scene::ISceneNodeAnimator* arena_anim = smgr->createCollisionResponseAnimator(selector_arena, node, core::vector3df(60,100,60),core::vector3df(0,-3,0), core::vector3df(0,50,0));
selector_arena->drop();
node->addAnimator(arena_anim);
arena_anim->drop();
while(device->run())
{
core::vector3df nodePosition = node->getPosition();
core::vector3df nodeRotation = node->getRotation();
float diry = ((nodeRotation.Y+90)*3.14)/180;
if(receiver.IsKeyDown(irr::KEY_KEY_W))
{
nodePosition.X += LIIKE_NOPEUS * cos((nodeRotation.Y) * 3.14 / 180);
nodePosition.Z -= LIIKE_NOPEUS * sin((nodeRotation.Y) * 3.14 / 180);
}
if(receiver.IsKeyDown(irr::KEY_KEY_S))
{
nodePosition.X -= LIIKE_NOPEUS * cos((nodeRotation.Y) * 3.14 / 180);
nodePosition.Z += LIIKE_NOPEUS * sin((nodeRotation.Y) * 3.14 / 180);
}
if(receiver.IsKeyDown(irr::KEY_KEY_A))
{
nodeRotation.Y -= LIIKE_NOPEUS * KERROIN / 2;
}
if(receiver.IsKeyDown(irr::KEY_KEY_D))
{
nodeRotation.Y += LIIKE_NOPEUS * KERROIN / 2;
}
if(receiver.IsKeyDown(irr::KEY_SPACE))
{
nodePosition.Y += LIIKE_NOPEUS * HYPPY_KERROIN / 2;
}
node->setPosition(nodePosition);
node->setRotation(nodeRotation);
int xf = (nodePosition.X-sin(diry)*250);
int yf = (nodePosition.Z-cos(diry)*250);
int zf = (nodePosition.Y + 120);
node->setPosition(nodePosition);
camera->setTarget(nodePosition);
nodePosition.Y +=200.f;
nodePosition.Z -= 150.f;
camera->setPosition(vector3df(xf,zf,yf));
cout << "Node position Y: " << nodePosition.Y << endl;
cout << "Node position X: " << nodePosition.X << endl;
/*
Piirto
*/
driver->beginScene(true, true, SColor(255,255,255,255));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
device->drop();
//END
return 0;
}
Code: Select all
//Namespaces
using namespace irr;
//WINDOW SIZE:
int window_x = 1280;
int window_y = 1024;
//WINDOW NAME
core::stringw window_header(L"Irrlicht");
Code: Select all
using namespace irr;
//My eventreceiver luokka, käytetään eventtien käsittelyyn.
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(const SEvent& event)
{
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
}
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:
bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
//How fast node moves
const f32 LIIKE_NOPEUS = 5.f;
//Multiplier
const float KERROIN = 0.67;
//Jump multiplier
const float HYPPY_KERROIN = 2.5;
Don't care about comments. I speak Finnish so i write comments in finnish.
I don't know why i got "Segmentation fault". If i comment the selector_arena->drop(); line i don't get "Segmentation fault" error, but the collision will not work.
And again, i don't speak very good English...
Last edited by wif on Sun Feb 08, 2009 9:03 am, edited 3 times in total.
I don't speak very good English...
-
hybrid
- Admin
- Posts: 14144
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
Yes, debugger should get the faulty pointer here. I don't see why the tri selector would be invalid, but maybe just check for 0 before using it, maybe something in the selector creation fails and you get a 0 pointer...
However, the drop is correct at that place, so it should be something before that fails.
However, the drop is correct at that place, so it should be something before that fails.