I'm a bit embarrased to ask this as it seems like it should be a blatently obvious sollution, but how could I detect if my camera is already pointed at an object?
PointEntity Done?
Blitz3D Forums/Blitz3D Programming/PointEntity Done? Create a pivot at the camera positions
Point the pivot at the object
check the variance in pitch yaw and roll values between the pivot and camera..
That should do it well enough anyhoo!!! :)
Point the pivot at the object
check the variance in pitch yaw and roll values between the pivot and camera..
That should do it well enough anyhoo!!! :)
You could also use the CameraPick command.
indeed, I never think of the Pick commands! such use! i do things the hard way
Oh, and dont forget to set EntityPickMode on all objects you will want to check :P
Oh, and dont forget to set EntityPickMode on all objects you will want to check :P
Or you could do it like this... (not tested)
Function CameraPointingAtEntity(CameraID,EntityID) oldpitch# = EntityPitch(CameraID) oldyaw# = EntityYaw(CameraID) oldroll# = EntityRoll(CameraID) PointEntity CameraID,EntityID newpitch# = EntityPitch(CameraID) newyaw# = EntityYaw(CameraID) newroll# = EntityRoll(CameraID) RotateEntity CameraID,oldpitch#,oldyaw#,oldroll# If oldpitch = newpitch If oldyaw = newyaw If oldroll = newroll then Return True EndIf EndIf Return False End Function
Papa, that was my first suggestion. :P
Cygnus its the same idea but without using any pivots ;)
BTW Using a camerapick doesn't tell you if the camera is pointing exactly at the entitys origin, it only tells you that any part of mesh is infront of the camera.
And what if another entity gets in the way? ;)
BTW Using a camerapick doesn't tell you if the camera is pointing exactly at the entitys origin, it only tells you that any part of mesh is infront of the camera.
And what if another entity gets in the way? ;)
You could also perhaps make use of the DeltaPitch and DeltaYaw functions.
You could use the CameraProject command, and then check if the projectedX() and projectedY() commands are in the center of the viewport.
Or if you can you could just put a global variable containing what entity the camera is pointed at, and change it as that changes.
Thanks for all that help everyone! My problem is that I'm ignorant in the use of alot of these commands like DeltaPitch, DeltaYaw, or TformVector. The help files arent all that helpful and doing a search in the forums leads you to reading post after post of stuff that usually doesnt pertain to what you're interested in.
It's very frustrating to see comments like "You could also perhaps make use of the DeltaPitch and DeltaYaw functions." (not to pick on DJWoodgate of course!) because I havent the faintest idea how I'd go about using them or what they are for. I *THINK* that the term 'delta' might mean a change in something so I'd hazzard to guess that "DeltaPitch" would mean a change in pitch ..??
I've done search after search to try and figure out how to use TformVector stuff but I havent found much in the way of explaining what its for, how its used, etc for someone who is totaly ignorant of it. I've seen a few "now that i understand it i can't believe i've gone this long without it" posts, but so far no bulbs have gone off for me. I even tried looking up "Vector Math" on google. The doctor said my eyes will stop bleeding soon and the brain swelling will go down ...
I truly thank Papa Lazarou for his code bit. That is what I was trying to do but I wasnt quite getting it right. His code plugged in nicely. It sounds like Cygnus is suggesting a pick Command sollution. While I've got a faint understanding of the pick commands, I'm no whiz at it and don't quite see what clever bit of coding would be required to use it.
I know just enough to get me into trouble is what I'm guess I'm saying ;) Thanks again for the help everyone and sorry to keep asking questions that have probably been asked a billion times already.
It's very frustrating to see comments like "You could also perhaps make use of the DeltaPitch and DeltaYaw functions." (not to pick on DJWoodgate of course!) because I havent the faintest idea how I'd go about using them or what they are for. I *THINK* that the term 'delta' might mean a change in something so I'd hazzard to guess that "DeltaPitch" would mean a change in pitch ..??
I've done search after search to try and figure out how to use TformVector stuff but I havent found much in the way of explaining what its for, how its used, etc for someone who is totaly ignorant of it. I've seen a few "now that i understand it i can't believe i've gone this long without it" posts, but so far no bulbs have gone off for me. I even tried looking up "Vector Math" on google. The doctor said my eyes will stop bleeding soon and the brain swelling will go down ...
I truly thank Papa Lazarou for his code bit. That is what I was trying to do but I wasnt quite getting it right. His code plugged in nicely. It sounds like Cygnus is suggesting a pick Command sollution. While I've got a faint understanding of the pick commands, I'm no whiz at it and don't quite see what clever bit of coding would be required to use it.
I know just enough to get me into trouble is what I'm guess I'm saying ;) Thanks again for the help everyone and sorry to keep asking questions that have probably been asked a billion times already.
Well, DeltaYaw/DeltaPitch tell you the angle an object should rotate to to point at another object.
If, for instance, you wanted to know if the object was somewhere in front of you,doesn't matter if its a bit off then:
Coded it in the message box so who knows if it works. The fuziness is just the number of degrees pitch or yaw the entity can be pointed away from the object.
If, for instance, you wanted to know if the object was somewhere in front of you,doesn't matter if its a bit off then:
Function InFront(Entity,Object,Fuzz=10) If Abs(DeltaYaw(Entity,Object)-EntityYaw(Entity))<Fuzz Then If Abs(DeltaPitch(Entity,Object)-EntityPitch(Entity))<Fuzz Then Return 1 EndIf EndIf End Function
Coded it in the message box so who knows if it works. The fuziness is just the number of degrees pitch or yaw the entity can be pointed away from the object.
It won't work - you spelt Fuzziness wrong twice! Also I don't think you need to subtract the current pitch/yaw from the delta pitch/yaw.
I think you can just call
EntityInView(Camera, Object) and the return value (True/False) will give you the answer!
Good luck!
EntityInView(Camera, Object) and the return value (True/False) will give you the answer!
Good luck!
You do have to subtract the deltas from the actual angles - check out the example in the documentation:
Note that it is returning an absolute angle not a change in angle (which delta would imply).
Changed fuzziness to fuzz btw.
Graphics3D 640,480 SetBuffer BackBuffer() camera=CreateCamera() ; Make camera orthagraphic for flat, 2D view CameraProjMode camera,2 ; Position and rotate camera so we have overhead (top-down) view PositionEntity camera,0,5,0 RotateEntity camera,90,0,0 ; Create red cone (the arrow) arrow=CreateCone() RotateMesh arrow,90,180,0 ScaleMesh arrow,.1,.1,.2 EntityColor arrow,255,0,0 ; Create blue sphere (the spot) spot=CreateSphere() ScaleMesh spot,.1,.1,.1 EntityColor spot,0,0,255 While Not KeyDown(1) ; If w,a,s,d pressed then move spot If KeyDown(17)=True Then MoveEntity spot,0,0,0.01 ; w - up If KeyDown(30)=True Then MoveEntity spot,-0.01,0,0 ; a - left If KeyDown(31)=True Then MoveEntity spot,0,0,-0.01 ; s - down If KeyDown(32)=True Then MoveEntity spot,0.01,0,0 ; d - right ; Rotate arrow using delta yaw value. Arrow will point at spot. RotateEntity arrow,0,DeltaYaw#(spot,arrow),0 RenderWorld Text 0,0,"Note: Camera view is overhead. The arrow will y-rotate using DeltaYaw value." Text 0,20,"Use w,a,s,d to move spot." Text 0,40,"Delta yaw: "+DeltaYaw#(spot,arrow) Flip Wend End
Note that it is returning an absolute angle not a change in angle (which delta would imply).
Changed fuzziness to fuzz btw.
Oops, yep your right bot builder :)