Results 1 to 3 of 3

Thread: Rotating Objects: move at strange angle

  1. #1

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Rotating Objects: move at strange angle

    I am trying to move a Mesh of a car about, everything works perfectly except when i try and turn it though an angle of about 45deg then the movement path doesnt match the direct of the mesh.

    Code:
     car.X = (float)(Math.Cos((double)car.DegToRad(car.Rotation - 90.0f))*50.0f) + car.X;
    Its only happens when the cars Rotation is inbetween -0.45 and 0.45, other that it acts weirdly.

  2. #2
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Rotating Objects: move at strange angle

    Look's like the formula's wrong:

    car.X = (float)(Math.Cos((double)car.DegToRad(car.Rotation - 90.0f))*50.0f) + car.X;

    Here's the right way to do it.

    Car.X = Car.X + Cos((Pi * Degree)/180) * Rotation_Speed
    Car.Y = Car.Y + Sin((Pi * Degree)/180) * Rotation_Speed

    So try this:

    car.X += (float)(Math.Cos((double)car.DegToRad(car.Rotation))) * 50.0f;
    car.Y += (float)(Math.Sin((double)car.DegToRad(car.Rotation))) * 50.0f;

    Notice now that (* 50.0f) is outside the parenthesis, and also notice I added Y rotation.

  3. #3
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    Re: Rotating Objects: move at strange angle

    This is an exactly of moving forward at whatever angle.

    m_VectorCircle is an array size of 360.

    This is the ideal way to do it. This is the mathematically correct way to move in 3D. If you change upAngle to anything but 0 you will start to angle into the air....
    Also, the cos/sin time can get as high as 500ms I believe...So it is best to make a lookup table.
    PHP Code:
    //----------------
    //Generate Vector Circles -- Fills the cos/sin lookup table 
    //----------------
    void MoveableObject::GenerateVectorCircle()
    {
        
    float Theta=0;
        
    float PI 3.14159265358979f;
        
    float ToRad PI 180;

        for (
    int i 0;360;i++)
        {
            
    Theta ToRad;
            
    m_VectorCircle[i].cosf(Theta);
            
    m_VectorCircle[i].sinf(Theta);
        }
    }


    //Within the unit movement function
    if (m_Actions.MoveNorth)
    {
            
    m_Pos.m_Pos.+ (m_VectorCircle[m_Angle].m_Velocity) * (m_VectorCircle[m_UpAngle].u);
            
    m_Pos.m_Pos.+ (m_VectorCircle[m_UpAngle].m_Velocity);
            
    m_Pos.m_Pos.+ (m_VectorCircle[m_Angle].m_Velocity) * (m_VectorCircle[m_UpAngle].u);

    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width