Delphi GetSceneNodefromRay

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
tobmaster
Posts: 9
Joined: Fri Feb 27, 2015 6:48 am

Delphi GetSceneNodefromRay

Post by tobmaster »

Hello everybody,

I have already searched different forums and spent a lot of hours on this topic.

I am working with irrDelphi. I haven't got any big problems so far, except this one:

I want to use a ray, which is sent from the ScreenCenter, for detecting the nearest SceneNode.

Code: Select all

function irrEvent(const event: PSEvent; const userdata: PSAppContext): Boolean; register;
begin
 RESULT := False;
//Code zum Verwenden der Mausklicks:
 with event^ do
  if (EventType = EET_MOUSE_INPUT_EVENT) then begin
 case event.MouseInput.Event of
      EMIE_LMOUSE_PRESSED_DOWN:
        begin
        MouseState.LeftButtonDown := true;
        smgr.getSceneCollisionManager.getRayFromScreenCoordinates(Ray,dev.getCursorControl.getPosition,Camera);
        OutNode := smgr.getSceneCollisionManager.getSceneNodeAndCollisionPointFromRay(Ray,OutVector,OutTriangle);
        showmessage('Ray Start: ' + floattostr(trunc(ray.start.x)) + '/' + floattostr(trunc(ray.start.y)) + '/' + floattostr(trunc(ray.start.z))); //Ray works fine
        showmessage('Ray Ende: ' + floattostr(trunc(ray.end_.x)) + '/' + floattostr(trunc(ray.end_.y)) + '/' + floattostr(trunc(ray.end_.z)));
                end;
      EMIE_LMOUSE_LEFT_UP:
        MouseState.LeftButtonDown := false;
      EMIE_MOUSE_MOVED:
      begin
         MouseState.Position.X := event.MouseInput.X;
        MouseState.Position.Y := event.MouseInput.Y;
      end;
    end;
  end;
end;
When I send the ray on a SceneNode in my 3D-Application, the form closes as if there would be a mistake:
Image
When I send a ray into the air, everything works fine. Only if a SceneNode is hitten by the ray, the error occurs.

OutNode, Outvector and OutTriangle are emply variables.
Do I first have to create them and add a dummy value?
The error seems that something is used, that doesn't exist yet (maybe OutNode?).

My other idea is:
The function returns an ISceneNode, but the objects which are hit, are IMeshSceneNodes.
If that is the problem, how could I get the result of an IMeshSceneNode then?

Or am I just using the function wrong?


I got really stuck on this mistake and can't find any solution.

Or does somebody have a working example of this in Delphi?

I would be very grateful if someone could help in this topic.
Please reply if I should add some more code or screenshots.

Thanks a lot in advance!
tobmaster
Posts: 9
Joined: Fri Feb 27, 2015 6:48 am

Re: Delphi GetSceneNodefromRay

Post by tobmaster »

Does really nobody have a working example of this?
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Delphi GetSceneNodefromRay

Post by CuteAlien »

Delphi programmers are a little bit rare these days.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: Delphi GetSceneNodefromRay

Post by thanhle »

Let me guess, I think getPosition is a function? getPosition()

Regards
thanh
tobmaster
Posts: 9
Joined: Fri Feb 27, 2015 6:48 am

Re: Delphi GetSceneNodefromRay

Post by tobmaster »

Yes, I think getPosition is needed to find the ScreenCenter in this case.

I receive the same outcome as if I use @MouseState.getposition.
But the Ray seems to work fine:
Image

The error occurs in this line:

Code: Select all

OutNode := smgr.getSceneCollisionManager.getSceneNodeAndCollisionPointFromRay(Ray,OutVector,OutTriangle);
Each time this function is called, the window closes.
So I think something is wrong with this line and I need to have an example how this function is used (Parameters, ...).

Best regards
tobmaster
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Delphi GetSceneNodefromRay

Post by mongoose7 »

The poster was actually saying that this line

Code: Select all

smgr.getSceneCollisionManager.getRayFromScreenCoordinates(Ray,dev.getCursorControl.getPosition,Camera);
is wrong because getPosition is a function and not an actual position. I think your debugger is pointing to the wrong line. Also, Ray is a return variable (I think) so you wouldn't examine it before the call.

Do you get any compiler warnings?
tobmaster
Posts: 9
Joined: Fri Feb 27, 2015 6:48 am

Re: Delphi GetSceneNodefromRay

Post by tobmaster »

Thanks for the answers so far.
No I don't get any warnings in my compiler.

Now I tried it like this:

Code: Select all

smgr.getSceneCollisionManager.getRayFromScreenCoordinates(Ray,getvector2dip(800,400),Camera);
And I get exact the same result, so I am pretty sure that this line is correct.

I can also use some values of the ray, for example:

Code: Select all

showmessage(floattostr(ray.start.x));
showmessage(floattostr(ray.end_.x));
So I think the ray has been created succesfully.

It would be great if someone could try this little example in Delphi.
tobmaster
Posts: 9
Joined: Fri Feb 27, 2015 6:48 am

Re: Delphi GetSceneNodefromRay

Post by tobmaster »

This topic can be closed.

I switched to C++ and now I managed to do this.

Greetings, tobmaster
Post Reply