realbasic-games
[Top] [All Lists]

Re: Determining an Object's bearing from the direction the Camera is fac

To: REALbasic Games <realbasic-games at lists dot realsoftware dot com>
Subject: Re: Determining an Object's bearing from the direction the Camera is facing.
From: "Joseph J. Strout" <joe at realsoftware dot com>
Date: Tue, 17 Aug 2004 14:43:38 -0500
Delivered-to: realbasic-games at lists dot realsoftware dot com
References: <BD47CBB6 dot 363F%wukystan at hotmail dot com>
At 2:50 PM -0400 8/17/04, Stan Rosenbaum wrote:

    There are a couple problems I get when I use this...

    1.  Let say the Camera is at the origin [0,0,0] pointing "North"/down
the -Z Axis/[0,0,-1].  [Therefore, from what I understand [0,0,-1] is what
we are using to orient stuff to "North".]   And then we have an Object at
[0,0,-5].

    The result I get from the functions says that the "object" is at 180
degrees.  ???.

The function doesn't tell you where the object is; it tells you whether the object and the camera are pointing in the same direction (or how different their forward-vectors are). I thought that was what you wanted?

   I mean if the camera was pointing the same direction as
North [0, 0, -1],  and the object is "North"  [0,0,-5]  should it return 0
degrees, if I am at the origin?

Not this function, no. If you want to know the angle between the camera's forward vector and a vector from the camera to the object, then change your function to calculate ObjVector this way:

 ObjVector = theObject.position.Minus( theCamera.position )
 ObjVector.Normalize

(and note, do NOT rotate this vector by the object's orientation; in my new understanding of what you want to do, the object rotation is not involved).

    It is also strange because when I set the orientation vector in these
lines to ObjVector = New Vector3D( 0, 0, 1 )
CamVector = New Vector3D( 0, 0, 1 )

    I get the same answer [just the positive and negative number of rotating
the camera get reversed].

Nothing strange about that. However I consider the above (0,0,1) definition of the forward-vector to be more correct.

    Finally,  the function only seem to return a result as if I was at the
Origin.   If I move the camera around, lets say to [0,0,5] with the camera
still facing due North [0,0,-1], I get a result saying the object is still
at 180 from the camera, and not -+45 [whatever the previous angle should be,
0 I think] to the left of me.

No, you're getting a result saying that the camera and the object are still pointing in the same direction (or rather, in exactly opposite directions) -- just what the code was designed to do. No reason that moving the camera should affect that result.

    I mean... This is a fairly easy problem to solve for in 2D geometry/trig
which is what I am basically trying to do.  But I need to figure out which
direction the camera is pointing, and that is what I am having a hard time
with.

No, the code you have tells you which direction the camera is pointing, relative to what direction some other object is pointing. Apparently that's not what you want? Now you seem to be saying you want to know how close the camera is to pointing at a particular object. So, the modification above will do that.

Best,
- Joe

P.S. Sorry I misunderstood your intent the first time, hopefully we've got it now!

--
,------------------------------------------------------------------.
|    Joseph J. Strout           REAL Software, Inc.                |
|    joe at realsoftware dot com       http://www.realsoftware.com        |
`------------------------------------------------------------------'
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>