getting my X Y Z to display Event receiver Problem

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.
Post Reply
Cear
Posts: 45
Joined: Wed Jul 18, 2007 9:31 pm

getting my X Y Z to display Event receiver Problem

Post by Cear »

is there a camera command for getPosition? im haing a heck of a time getting partticle effects to the right X Y Z spot. so if i could just fly the camera to where i want them to be and get the XYZ coordinates it would save me AGES of time.

any ideas how to get it to display in the top of the window like FPS?
code snips encouraged as i learn from them very well.
thanks humes. bump
Last edited by Cear on Sat Aug 25, 2007 2:58 am, edited 2 times in total.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Try changing the topic and maybe it would be more clear so someone who knows how to do it could help you..
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Code snips don't help you learn ;)

You can check the API on the main irrlicht website so you can find out for yourself which functions exist in the camera class. Just for a freebie i will tell you that yes getPosition() does exist.

Whenever you're using a library the API is invaluable as you obviously can't come onto the forum asking for every single function that does what you require, much quicker to look in the API than wait for replies :)
Image Image Image
Cear
Posts: 45
Joined: Wed Jul 18, 2007 9:31 pm

Post by Cear »

so this is all i can figure.

ive got a sword attached to my camera as a child so im using
scene::ISceneNode* getPosition(avatar_node);
but theres no command to for the driver to get the position. and if i tell the string at the top of the window to include
scene::ISceneNode* getPosition(avatar_node); like it does with FPS
it doesnt complie.

so if i have the position of the camera (cause get position returns position of parent only) how do i get it to display? ive got a GUI box with some text and the main core string at the top of the window to display it.

any help?
Cear
Posts: 45
Joined: Wed Jul 18, 2007 9:31 pm

Post by Cear »

ok if no ones got any help for me i gotta knw this.


how do you guys position things on your maps??? do you jsut guess the position you want the first time then repeat trial and error over and over til its where you want it to be?

thats all im trying to do. i want 4 partice systems at teh top of 4 pillars that are a part of a giant town hall mesh. i need soemthing less tiem consuming
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

Code: Select all

core::vector3df pos = smgr->getActiveCamera()->getAbsolutePosition();
printf("Position: %f,%f,%f\n", pos.X,pos.Y,pos.Z);
That will display in the console window... You may need to compile as "Win32 console" or something in your compiler options. Or at the start of your program you can put

Code: Select all

freopen("log.txt", "wt", stdout);
which will change printf's output to a text file.

But yes, IrrEdit or making your own editor is the best thing to do.
Cear
Posts: 45
Joined: Wed Jul 18, 2007 9:31 pm

Post by Cear »

fantastic dan. but is there a way for me to get to tp update as the camera moves around? or will i have to make an event reciever to push a button when i get to where i want a particle system to be and then have it display. ill do that if its possible. as for irredit im working on one scene with it. i hear there are collition issues with irr scenes but i'll get around to it. thanks alot tho.
Cear
Posts: 45
Joined: Wed Jul 18, 2007 9:31 pm

Post by Cear »

Code: Select all

class MyEventReceiver : public IEventReceiver{public: virtual bool OnEvent(SEvent event) 
  { 
  //ESC to exit program    
  if(event.EventType == EET_KEY_INPUT_EVENT && 
    event.KeyInput.Key == KEY_ESCAPE && 
   event.KeyInput.PressedDown == false) 
   device->closeDevice(); 
  if(event.KeyInput.Key == KEY_KEY_3) 
    { 
    core::vector3df pos = smgr->getActiveCamera()->getAbsolutePosition(); 
printf("Position: %f,%f,%f\n", pos.X,pos.Y,pos.Z); 
    } 
  else 
    { 
    return false; 
    }} 
  };
it doesnt compile but for reasons i dont really think make perfect sence
its unhappy that i have already declared the device and the smgr
strange to me it points to this code at the top of my .cpp

Code: Select all

	
IrrlichtDevice *device =
    createDevice(driverType, core::dimension2d<s32>(640,480),32,false,true,true);

if (device == 0)
   return 1;

video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

It usually makes it easier to tell you what is wrong with your code if you post the error message. That said, it is most likely that it is complaining because device hasn't been declared at the proper scope so it is available to the MyEventReceiver::OnEvent() method. Try this...

Code: Select all

class MyEventReceiver : public IEventReceiver
{
public:
  // constructor takes pointer to device, so that we can access it in
  // the OnEvent() method below
  MyEventReceiver(IrrlichtDevice* device)
    : Device(device) // copy device pointer
  {
  }

  virtual bool OnEvent(SEvent event) 
  { 
    // always check that event type is key input event before you try
    // to see what key is pressed. you weren't doing this for the 3
    // key handler
    if (event.EventType == EET_KEY_INPUT_EVENT &&
        !event.KeyInput.PressedDown)
    {
      switch (event.KeyInput.Key) {
        case KEY_ESCAPE:
          // use the device pointer that the event receiver
          // is caching.
          Device->closeDevice();
          return true;
        case KEY_KEY_3: {
          const core::vector3df pos = smgr->getActiveCamera()->getAbsolutePosition(); 
          printf("Position: %f,%f,%f\n", pos.X,pos.Y,pos.Z); 
          return true;
        }
      }
    }

    // always ensure that all execution paths return a value from
    // a function that is declared to return something
    return false;
  }

private:
  IrrlichtDevice* Device;
};
You would use it like this...

Code: Select all

IrrlichtDevice *device = 
    createDevice(driverType, core::dimension2d<s32>(640,480),32,false,true,true); 
if (device == 0) 
   return 1; 

// now that you've got a device, create an event receiver. pass
// pointer to device to the event receiver so that it can cache a
// pointer to it.
MyEventReceiver receiver(device);

// now tell the device that your event receiver should handle all of the events
device->setEventReceiver(&receiver);

Also, a 'better' [i.e. simpler] way to display the camera position is to constantly display it in the main loop. This code will display the camera position in the title bar of the window. It won't really do anything useful if the program is running in full screen mode.

Code: Select all

while (device->run())
{
  if (driver->beginScene(true, true, video::SColor(255, 120, 120, 120))
  {
    smgr->drawAll();

    driver->endScene();
  }

  // even better way to do it will display the  position in the ti
  wchar_t caption[32];
  _snwprintf(caption, 32, L"%f, %f, %f", pos.X, pos.Y, pos.Z);
  //swprintf(caption, 32, L"%f, %f, %f", pos.X, pos.Y, pos.Z);

  device->setWindowCaption(caption);
}
Travis
Cear
Posts: 45
Joined: Wed Jul 18, 2007 9:31 pm

Post by Cear »

Thats all working out for me. ive studied if for about an hour now with teh event receiver and all but one things got me.
upon compiling i get this error

use of `auto' variable from containing function
and this again
irr::scene::ISceneManager*smgr' declared here

i was getting the same previously declared thing with the device before

but againt im still struck off by it even tho we fixed that one.

my smgr is a part of the device so what gives?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

It sounds like you have a function that uses a variable smgr that isn't declared. I've looked over my code and I don't see any reference to smgr except the main loop [which is supposed to go inside main]. The main loop code I provided requires that you declare smgr above, but that is pretty standard and in every one of the irrlicht examples.

As mentioned previously, it might be a good idea for you to go back and learn a little C/C++ before you try and dive into all of this. You will progress much faster once you understand the language you need to use. Learning both simultaneously is possible, but you will likely end up asking lots of questions that you should be able to answer yourself.

Travis
Cear
Posts: 45
Joined: Wed Jul 18, 2007 9:31 pm

Post by Cear »

switch (event.KeyInput.Key) {
case KEY_ESCAPE:
// use the device pointer that the event receiver
// is caching.
Device->closeDevice();
return true;
case KEY_KEY_3: {
const core::vector3df pos = smgr->getActiveCamera()->getAbsolutePosition();
printf("Position: %f,%f,%f\n", pos.X,pos.Y,pos.Z);
return true;

its right here. and the problem it says is that its already delcared. im not declaring here just commanding the smgr to get the camera.

as for learning c/c++ i started class monday for c# c++ and XNA for development of MMO games. looking forward to it mucho.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

are you sure smgr is global ???
maybe try something like this:

Code: Select all

const core::vector3df pos = Device->getSceneManager()->getActiveCamera()->getAbsolutePosition();
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

No, smgr isn't global. I just copied and pasted his code and didn't think anything of it. Acki has the right idea.
Post Reply