XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

Track cube rotation

Last post 11/20/2009 9:45 AM by RyuMaster. 3 replies.
  • 11/19/2009 3:37 PM

    Track cube rotation

    Hi! I'm dealing with fairly simple task, but for some reason I'm stuck fo a long time, all my approaches fails, so I'm asking for an advice...

    I have simple cube, witch has 6 textures assigned to every side of it. This cube rotates around X and Y axises.

    I need to track, which side faces the camera mostly, and highligth that side.

    Is there any way to find, which side is nearest to the camera, without involving tracking rotations and comparing them to hardcoded values (like, if rotated by bla bla degrees, and bla bla degrees, then side facing == 3 and e.t.c)

    Cube is XnaModel, but I can't see any way to extra side's vertex position, for sample, and compare it to the camera or e.t.c Hmm...




  • 11/19/2009 5:15 PM In reply to

    Re: Track cube rotation

    You could break the cube down to its triangles, then check the center of all the triangles to see which one is closest to the camera position, then just check what face the closest triangle is on :)
    Bijaz of the Bene Tleilax
  • 11/19/2009 9:58 PM In reply to

    Re: Track cube rotation

    Answer
    Reply Quote
    I'm not sure that you even need to calculate the center of the triangles/sides. You should just be able to take the cumulative distance from the camera to the four corners of each side of the cube and pick the side with the smallest total distance.
  • 11/20/2009 9:45 AM In reply to

    Re: Track cube rotation

    Thanx, little by little I got problem solved.

    The hardest part was to figure, that I need to multiply every vertex with model transformation matrix, but now it woks fine.
Page 1 of 1 (4 items) Previous Next