Thread: How to make a cube move from a circle a certan amount in a direction based on an angl

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    76

    How to make a cube move from a circle a certan amount in a direction based on an angl

    How to make a cube move from a circle a certan amount in a direction based on an angle between 0 and 360?


    You use left and right keys to increase/decrease the angle from 0 to 360. (at 361 it goes to 0 and vise versa) and You have a cube that's a little infront of your view. How do I make it move so it's always infront of your view?

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Are you writing a software renderer? If so you should be able to answer your own question, otherwise you're going down the wrong track.

    Or, you need to explain what coordinate system/API whatever you're using uses.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    How do I make it move so it's always infront of your view?
    You don't. You move the cube and then translate the camera a set distance along the negative look vector of the cube and then create a look at matrix to look at the cube. The look-at matrix becomes the final view matrix for the scene. If you want to swing the camera back and forth gradually for smooth transition effects (think Tombraider style) you will need to use quaternions to spherically interpolate (SLERP) between two different 3D orientations.

    How to make a cube move from a circle a certan amount in a direction based on an angle between 0 and 360?
    Generally the use of Euler angles is a bad idea in a 3D environment. Normally your objects have an up, right, and look vector. Based on those three vectors you can yaw (rotate around the up), pitch (rotate around the right), and roll (rotate around the look). While you can orient items using Euler angles they don't fit easily into yaw, pitch, roll. A better representation is to say you have a set amount of yaw, a set amount of pitch, and a set amount of roll. To say you want to fly off at 135 degrees means nothing. 135 degrees with respect to what orientation and what axes? You could have 135 degrees of roll, pitch, and yaw but that does not mean the end result is the object is moving at 135 degrees with respect to x, y and z axes. Again there is no frame of reference.
    Last edited by VirtualAce; 08-09-2009 at 01:59 AM.

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    76
    I have a most of the program done, you can move around with the forward and back arrow keys and look to the left and right with the left and right arrow keys. But so far the cube just stays at the position your at plus one on the x axis, so you can see it. How do I make it so it will be one infront of you, no matter where your looking?

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I just told you.

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    76
    Could someone give some example code?

    (They don't have to do it all for me, but I don't have much idea what you are talking about)




    I'm using C++ with OpenGL, I can give sorce code if that helps.
    Also, yes you can look up and down, but the cube olny needs to move with the left/right view.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mouse Maze Problem
    By Furbiesandbeans in forum C++ Programming
    Replies: 13
    Last Post: 04-28-2008, 04:20 PM
  2. Having a problem!
    By Zildjian in forum C++ Programming
    Replies: 6
    Last Post: 10-18-2004, 09:40 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM