Another 3d Math Question
by James Laker (BurNinG) · in Torque Game Engine · 05/05/2008 (4:37 am) · 5 replies
How would I calculate if a target is onscreen (inscript)?
I'm busy refining my weapon systems and dont want to allow my ship to fire a homing missile if the target is not onscreen. Can someone help me out here please.
I'm busy refining my weapon systems and dont want to allow my ship to fire a homing missile if the target is not onscreen. Can someone help me out here please.
#2
Where and how you get those in torque, from script, I don't know.
But once you have them project P onto the screen:
V = S * C * P
If the x and y components of V are between -1 and 1, the target is on the screen.
05/13/2008 (2:45 am)
The maths side of it isn't hard... your target must have a world-space position P, you should have a "world to camera" transform C (sometimes called view matrix), and you must have a "camera to screen" transform S too (sometimes called projection matrix).Where and how you get those in torque, from script, I don't know.
But once you have them project P onto the screen:
V = S * C * P
If the x and y components of V are between -1 and 1, the target is on the screen.
#3
I don't know if it will be useful to you, but it seems, from the name, that's what you are looking for.
Nicolas Buquet
www.buquet-net.com/cv/
05/13/2008 (5:15 am)
Did you have a look at hte Line-Of_sight (LOS) ?I don't know if it will be useful to you, but it seems, from the name, that's what you are looking for.
Nicolas Buquet
www.buquet-net.com/cv/
#4
05/13/2008 (6:39 am)
Sensors for fighter aircraft have a maximum off-boresight angle (away from straight ahead) that they can traverse or otherwise point to follow a target. You could match this model with a simple dot product to calculate the angle from your model +Y axis (getForwardVector()) to the (target - shooter) position vector.
#5
So I would guess the best way would be to use the dot product Matthew mentions. That sounds pretty simple (always does), since I used something similar with my target locking code (Lock target closest too my crosshair). I guess I should probably use the FOV too or just keep it at 45 degrees.
05/14/2008 (12:21 am)
Thanks guys... I'm not sure if the things Hadoken mentions are accessible in script though. So I would guess the best way would be to use the dot product Matthew mentions. That sounds pretty simple (always does), since I used something similar with my target locking code (Lock target closest too my crosshair). I guess I should probably use the FOV too or just keep it at 45 degrees.
Torque Owner James Laker (BurNinG)