Page 1 of 1

Delphi GetSceneNodefromRay

Posted: Fri Feb 27, 2015 7:28 am
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!

Re: Delphi GetSceneNodefromRay

Posted: Tue Mar 03, 2015 5:37 pm
by tobmaster
Does really nobody have a working example of this?

Re: Delphi GetSceneNodefromRay

Posted: Tue Mar 03, 2015 5:39 pm
by CuteAlien
Delphi programmers are a little bit rare these days.

Re: Delphi GetSceneNodefromRay

Posted: Tue Mar 03, 2015 6:13 pm
by thanhle
Let me guess, I think getPosition is a function? getPosition()

Regards
thanh

Re: Delphi GetSceneNodefromRay

Posted: Wed Mar 04, 2015 6:58 pm
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

Re: Delphi GetSceneNodefromRay

Posted: Thu Mar 05, 2015 1:05 am
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?

Re: Delphi GetSceneNodefromRay

Posted: Thu Mar 05, 2015 6:19 pm
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.

Re: Delphi GetSceneNodefromRay

Posted: Sat Mar 07, 2015 10:48 pm
by tobmaster
This topic can be closed.

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

Greetings, tobmaster