Orthogonal Camera causing racasting 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
Slaine
Posts: 120
Joined: Fri May 04, 2007 12:28 pm

Orthogonal Camera causing racasting problem

Post by Slaine »

I'm not sure if it's the raycast or a math problem, but with orthogonal projection off the sphere stays attached to the cursor on a plane when you move the cursor around the spheres stays with it, but as soon as I set the cam to ortho the sphere doesn't follow, it moves in the same direction as the cursor but it doesn't move as far? Here is the code I'm using:

Code: Select all

scene::ICameraSceneNode * camera = ezgame.scene()->addCameraSceneNode();
camera->setPosition(vector3df(camX,camY,camZ));

core::matrix4 projMat;
projMat.buildProjectionMatrixOrthoLH(800,600,0,1000); //
camera->setProjectionMatrix(projMat);

camera->isOrthogonal();
and now the code in the main loop

Code: Select all

// Create a ray through the mouse cursor. 
line3df ray = ezgame.scene()->getSceneCollisionManager()->getRayFromScreenCoordinates(position2d<s32>(ezgame.getCursorPosition()), camera);

plane3df plane(ball->getPosition(), vector3df(0, -1, 0));
vector3df mousePosition;

if(plane.getIntersectionWithLine(ray.start, ray.getVector(), mousePosition))
{ 
	float rect_x = (ball->getPosition().X - mousePosition.X);
	float rect_z = (ball->getPosition().Z - mousePosition.Z);
	
   ball->setPosition(core::vector3df(mousePosition.X ,0, mousePosition.Z));
}
I'm just not entirely sure why changing the cam to ortho looses the ray cast? I thought using getRayFromScreenCoordinates was the currect function for ortho cams?

Thanks for any help :)
Epi
Posts: 9
Joined: Wed Mar 04, 2009 4:27 am

Post by Epi »

i have a similiar problem with

Code: Select all

getSceneCollisionManager()->getSceneNodeFromScreenCoordinatesBB(mousePosition)
if i switch to a orthogonal camera, it doesn't find any objects, but works with a normal camera
zillion42
Posts: 324
Joined: Wed Aug 29, 2007 12:32 am
Location: Hamburg, Germany

Post by zillion42 »

I'm not sure if it's the raycast or a math problem, but with orthogonal projection off the sphere stays attached to the cursor on a plane when you move the cursor around the spheres stays with it, but as soon as I set the cam to ortho the sphere doesn't follow, it moves in the same direction as the cursor but it doesn't move as far? Here is the code I'm using:
aha ! :lol:

sorry but could you try to pharase that question again into 3 or four coherent sentences please... I got a little confused with all the commas.
edit:
after reading the code I could understand what you are trying to say, but the question is somehow phrased odd, to say the least. And sorry, I can't help you, I never tried that so far...
Slaine
Posts: 120
Joined: Fri May 04, 2007 12:28 pm

Post by Slaine »

What?! I admit I don't get a lot of time to write forum questions but I'm sure you can get the general idea of what I'm talking about?

So, you don't know how to fix other people's problems, just pick holes in grammer? Why do I bother trying to learn 3rd party engines :?:
Slaine
Posts: 120
Joined: Fri May 04, 2007 12:28 pm

Post by Slaine »

Epi wrote:i have a similiar problem with

Code: Select all

getSceneCollisionManager()->getSceneNodeFromScreenCoordinatesBB(mousePosition)
if i switch to a orthogonal camera, it doesn't find any objects, but works with a normal camera
I think this is a similar problem, I basically don't know how to pass the raycast cursor position to the node when the camera matrix is set to Orthogonal? The screen debug I'm printing says that the cursor x and z is the same as the node's x and z, yet the node only moves a fraction of the distance compared to the cursor? :?
vins
Posts: 51
Joined: Mon Aug 16, 2004 6:14 pm
Location: Sofia, Bulgaria
Contact:

Post by vins »

I have similar problems.
Slaine
Posts: 120
Joined: Fri May 04, 2007 12:28 pm

Post by Slaine »

Okay it's to do with the fact that the coordinates are correct It's just that the camera is drawing everything without perspective, which is a bit of a worry because does that mean we have to fudge the code to get the node into the same screen position as the cursor? Like this:

Code: Select all

if(plane.getIntersectionWithLine(ray.start, ray.getVector(), mousePosition)) 
{ 
   float x = (ball->getPosition().X - mousePosition.X)*4; 
   float z = (ball->getPosition().Z - mousePosition.Z)*4; 
    
   ball->setPosition(core::vector3df(x ,0, z)); 
}
I've also corrected my code, I made a stupid mistake and didn't use the variables I was creating in the if statement, I tend to make silly mistakes like this now and then :( I'm also quite new to screen to world coordinate conversions.
zillion42
Posts: 324
Joined: Wed Aug 29, 2007 12:32 am
Location: Hamburg, Germany

Post by zillion42 »

No.
And Yes I got a basic idea of your problem after reading the code, but the question itself was completely riddling for me, sorry.
Edit:
And sorry again, I really didn't try to mock you, I just had to laugh about that incomprehensible giant senctece of yours... Basically if the question is phrased like that, most people won't read the code in the first place.
Slaine
Posts: 120
Joined: Fri May 04, 2007 12:28 pm

Post by Slaine »

zillion42 wrote:No.
And Yes I got a basic idea of your problem after reading the code, but the question itself was completely riddling for me, sorry.
Edit:
And sorry again, I really didn't try to mock you, I just had to laugh about that incomprehensible giant senctece of yours... Basically if the question is phrased like that, most people won't read the code in the first place.
LOL!!! It is pretty bad isn't it :wink: I had to rush it though.
Slaine
Posts: 120
Joined: Fri May 04, 2007 12:28 pm

Post by Slaine »

zillion42 wrote:No.
And Yes I got a basic idea of your problem after reading the code, but the question itself was completely riddling for me, sorry.
Edit:
And sorry again, I really didn't try to mock you, I just had to laugh about that incomprehensible giant senctece of yours... Basically if the question is phrased like that, most people won't read the code in the first place.
LOL!!! It is pretty bad isn't it :wink: I had to rush it though.
zillion42
Posts: 324
Joined: Wed Aug 29, 2007 12:32 am
Location: Hamburg, Germany

Post by zillion42 »

and another OT post:
being able to laugh about oneself is a virtue !
I read the sentence to a friend yesterday and we were both laughing, he added:
Nerds, he probably wrote the first english sentence, after sinking into programing syntax alone at home for quite some time
good luck with the orthogonal camera raycast problem, maybe make a good example case illustrating your problem and post a link to that...
Slaine
Posts: 120
Joined: Fri May 04, 2007 12:28 pm

Post by Slaine »

zillion42 wrote:and another OT post:
being able to laugh about oneself is a virtue !
I read the sentence to a friend yesterday and we were both laughing, he added:
Nerds, he probably wrote the first english sentence, after sinking into programing syntax alone at home for quite some time
good luck with the orthogonal camera raycast problem, maybe make a good example case illustrating your problem and post a link to that...
Rofl! :lol: I've just re-read it again, I sound like I'm on drugs! Now, where did I put them?

Still haven't fixed it though? haha
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Have you tried passing true for the isOrthogonal (the second parameter) to camera->setProjectionMatrix()?

Travis
Post Reply