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 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!