realbasic-nug
[Top] [All Lists]

Re: RB3D Camera.position based on Object3d.postion

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: RB3D Camera.position based on Object3d.postion
From: Bryan Lund <bryan at radicalbreeze dot com>
Date: Thu, 31 Jan 2008 12:26:23 -0800
Delivered-to: listarchive at realsoftware dot com
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <47A005E9 dot 1040701 at radicalbreeze dot com> <1D6A4AF1-AD19-475B-8078-EDE99C414F36 at inspiringapps dot com> <47A166F0 dot 5050707 at radicalbreeze dot com> <F14EB11A-1352-4C70-9AAF-DB522140B16D at inspiringapps dot com> <47A21347 dot 3060802 at radicalbreeze dot com>
Bryan Lund wrote:
> Joe Strout wrote:
>> In the Rb3D FAQ, I think there is some code to position something at  
>> any desired pixel position within an Rb3DSpace.  It's more complex  
>> than what we've discussed here, because it works for any camera  
>> position and orientation, but the basic idea is the same.  <http:// 
>> www.strout.net/info/coding/rb/>
> 
> Thanks Joe, the pointers are much appreciated.
> 
> Would you (or anyone else) mind putting up the rb3d faq archive in 
> something other than .sit? 

Ok, realized that the 3d faq is in the examples folder of RB.  :)  (Very 
helpful document, btw.)

I pulled the example code below from the faq (I assume that kDegrees =
0.0174532925).

But it seems to not return consistent results at different camera 
positions.  If I return the x/y of the returned vector of a known 
location of an existing 3d object, then modify the camera.position.x 
(say, to slide it to the right a bit while still keeping the object 
visible), the next time I return the x/y of the vector of that same 
known location... it's now a different value.

I've tried this in simple project (with a single object3d added from a 
picture and the values of the screenToWorld function displayed on 
mousemove of the rb3dspace).

Any ideas?

Function ScreenToWorld(view as Rb3DSpace, X as Integer, Y As Integer) As
Vector3D

    // Find the point in 3D space represented by the given
    // point in the 2D rendering.
    Dim dist As Double
    Dim screenPos As Vector3D

   dist = Min(view.width, view.height) * 0.5 / tan(view.FieldOfView *
kDegrees * 0.5)

    screenPos = New Vector3D
    screenPos.X = (view.width/2 - X)
    screenPos.Y = (view.height/2 - Y)
    screenPos.Z = dist
    screenPos = view.camera.orientation.Transform(screenPos)
    screenPos.Add view.camera.position

    return screenPos
End Function

-Bryan


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


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