Results 1 to 2 of 2

Thread: 3D Points Equation

  1. #1

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    3D Points Equation

    I am programming a game in DirectX7 Immediate and I am having a little problem with proper collision detection.

    Now the origin of my object is the middle, so to get the 4 points of a rect around the object I need to add/subtract half the width/depth.

    Now my object is rotating:
    0 it is pointing right,
    90 pointing north sitting directly on the z axis)
    180 it is pointing left
    270 pointing south on the z-axis

    Now, how em I suppose to add the width and depth to the origin x,z when the object is no longer sitting on angle 0.
    I realize I need to use trig, but I do not know how.
    "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

  2. #2
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    I'm not sure about the coordinate system you're using. I'm assuming you're using a left hand coordinate system, with the x-axis pointing to the right, y-axis to the top and z-axis into the screen.

    Suppose the location of the object is P. The rectangle is bounded by the points A (bottom left), B (top left), C (top right) and D (bottom right). Fruthermore, W = width and H = height of the rectangle.
    When angle = 0, then A = (P.x, P.y - 0.5H, P.z + 0.5W), B = (P.x, P.y + 0.5H, P.z + 0.5W), C = (P.x, P.y + 0.5H, P.z - 0.5W), D = (P.x, P.y - 0.5H, P.z - 0.5W).
    The y-values of the points remain the same all the time, since you're rotating about the y-axis. The valus of the x- and z-axes change with the angle.
    Here are the formulas
    A = (P.x - 0.5W * sin(angle), P.y - 0.5H, P.z + 0.5W * cos(angle)),
    B = (P.x - 0.5W * sin(angle), P.y + 0.5H, P.z + 0.5W * cos(angle)),
    C = (P.x + 0.5W * sin(angle), P.y + 0.5H, P.z - 0.5W * cos(angle)),
    D = (P.x + 0.5W * sin(angle), P.y - 0.5H, P.z - 0.5W * cos(angle))

    I hope this works, since I can't test it in DirectX. These formulas might need some sign reversals, if my assumption on the coordinate system is incorrect.

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