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

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
Nikko_Bertoa
Posts: 42
Joined: Wed Feb 18, 2009 5:26 am

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

Post 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.
Last edited by Nikko_Bertoa on Wed Feb 25, 2009 7:32 pm, edited 1 time in total.
Katsankat
Posts: 178
Joined: Sun Mar 12, 2006 4:15 am
Contact:

Post 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".
Nikko_Bertoa
Posts: 42
Joined: Wed Feb 18, 2009 5:26 am

Post 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
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post 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
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Nikko_Bertoa
Posts: 42
Joined: Wed Feb 18, 2009 5:26 am

Post by Nikko_Bertoa »

@bitplane:

I now understand all the purpose.

Thanks
Post Reply