Page 1 of 1

CDemo::shoot(): I don't understand something

Posted: Tue Feb 24, 2009 4:50 am
by Nikko_Bertoa
Hi Irrlicht's community.

File:
C:\irrlicht-1.5\examples\Demo\CDemo.cpp

This is the FPS Demo in Irrlicht's SDK


Problem Location:

Function CDemo::shoot()

Code: Select all

// get line of camera
core::vector3df start = camera->getPosition();
core::vector3df end = (camera->getTarget() - start);
end.normalize();
start += end*8.0f;
end = start + (end * camera->getFarValue());

Problem Explanation:

I don't understand this code's purpose.

Posted: Tue Feb 24, 2009 4:02 pm
by Katsankat
Determine the 3D coordinates of a point somewhat far away in front of the cam, in the direction the cam is looking at.

Why? To trace a line just to see if something intersects with this line and thus will be "hit".

Posted: Wed Feb 25, 2009 7:32 pm
by Nikko_Bertoa
@Katsankat:

Thanks I understand more now but not all.

I will explain step by step what I think about the code:


First part:

Code: Select all

core::vector3df start = camera->getPosition(); 
core::vector3df end = (camera->getTarget() - start); 
end.normalize();
end is a normalized vector. It represents the camera look-at vector.

o---->

o = camera position ----> = end vector


Second part:

Code: Select all

start += end*8.0f; 
end = start + (end * camera->getFarValue());
Why 8.0f and not 10.0f or 1111.0f or -145.0f?


Thanks

Posted: Wed Feb 25, 2009 7:39 pm
by bitplane
It moves the start vector to a reasonable distance from the camera, I don't know why but I guess start += end*camera->getNearValue() might work better

Posted: Wed Feb 25, 2009 8:07 pm
by Nikko_Bertoa
@bitplane:

I now understand all the purpose.

Thanks