realbasic-games
[Top] [All Lists]

Re: Looking at the origin in 3D

To: REALbasic Games <realbasic-games at lists dot realsoftware dot com>
Subject: Re: Looking at the origin in 3D
From: Craig M. <FishyRB at 98115 dot net>
Date: Thu, 4 Jan 2007 14:57:39 -0800
Delivered-to: listarchive at realsoftware dot com
Delivered-to: realbasic-games at lists dot realsoftware dot com
References: <61092 dot 216 dot 56 dot 22 dot 34 dot 1167931945 dot squirrel at mail dot athenet dot net>
The user can move the camera around my object in a circle but it always
views in the same direction. I want the camera to always be facing the
object which happens to be at the origin. The radius of the circle is 750.

After that I want the camera to point towards the origin.

I believe there is an example of this in the language reference somewhere. Look under rb3dspace, it might be there.


What would be even better is if the user could click and drag their mouse
on the RB3DSpace to move the camera.

This can be done in several ways. First you need to implement mouse down (and record the click location, X and Y) and in it return true. Then mouse drag will fire, where you capture the change in X and Y to apply some rotation. Something more advanced and scalable can be done by projecting the click onto the X,Y plain (Well, really the plain which is parallel to the screen and involves the origin) of the space and using that. I have some code for doing that, but everything is all rotated strange so Z is vertical and Y is horizontal.

This only works for one camera rotation about the origin because its intended for use with a rotating object.

Code:

Function ScreenXToSpaceX(X As integer) As Double
  Dim mX,XFOV,sXMax, sX As Double
  mX=X-(Space.Width/2)

  If Space.Width<Space.Height then
    XFOV=Space.FieldOfView
  else
    XFOV=Space.FieldOfView*(Space.Width/Space.Height)
  End If
  XFOV=XFOV/(180/Pi)

  sXMax=Tan(XFOV/2)*Space.Camera.Position.X

  sX=(mx/(Space.Width/2))*sXMax
  sX=sX+Space.Camera.Position.Y
  Return sX
End Function



Another option would be to add the camera to a group, centered at the origin and rotate the group.


I need to keep the object stationary to test for loctions.

I don't know the full context so this might not apply, but you could move the object and use worldToObjectTransform or ObjectToWorldTransform on the location vectors.


Any suggections would be great.

Good luck!

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

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


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