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>
|