Results 1 to 4 of 4

Thread: Moving an object with respect to the camera

  1. #1
    Member Contributor
    Join Date
    Feb 2000
    Location
    Stafford, UK
    Posts
    60

    Moving an object with respect to the camera

    I have an object in 3d space using perspective projection. What i want to do is select the object (which i can already do) then move it using the mouse. This works fine if the screen is parallel to the x axis, but if I rotate around the y axis I want to move the object with respect to the cameras (screens) x axis, not the world x axis.

    for example if I rotate 180 degrees, moving the mouse to the left would make the object move to the right.

    If anyone can offer any suggetsions i would be grateful

    Thanks

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: Moving an object with respect to the camera

    Can only give you a hint on how to do.

    Let's say a=angle around the y-axis and v=distance you want to move the object.

    new_x = x + v*cos(a)
    new_z = z + v*sin(a)

    This pseudocode should do the work. Translation along the y-axis is unaffected by rotations about the y-axis.

    So if you move your mouse to the right (for example), v will get a positive value, and if you move your mouse left, it will get a negative value.

    It's a litle bit more tricky if you camera can look downwards/upwards too...

    Bob

    btw, this is just theory...

  3. #3
    Member Contributor
    Join Date
    Feb 2000
    Location
    Stafford, UK
    Posts
    60

    Re: Moving an object with respect to the camera

    Yup that works!

    Thanks

  4. #4
    Member Contributor
    Join Date
    Feb 2000
    Location
    Stafford, UK
    Posts
    60

    Re: Moving an object with respect to the camera

    Yup that works!

    Thanks

Similar Threads

  1. Align object in 3D space with respect to (View port) Window Coordinates
    By saransiva_ps in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-28-2014, 02:34 AM
  2. Object orientation with respect to camera
    By ProofKhan in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 07-15-2013, 02:42 AM
  3. Rotate the camear with respect to object
    By Srija in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 10-19-2011, 01:44 AM
  4. Put Camera at Moving's Object's Position
    By dellatorre in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 01-17-2010, 08:57 PM
  5. moving object with mouse after rotate camera
    By mjftx in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 10-17-2009, 08:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean