Problem with my rotation code?

This is a discussion on Problem with my rotation code? within the Game Programming forums, part of the General Programming Boards category; Isn't there a more efficient way of doing things? cause basically from what you're telling is that I have to ...

  1. #31
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    Isn't there a more efficient way of doing things? cause basically from what you're telling is that I have to translate to where the center of my needed rotation is for every single object that needs rotated? what is the computational expense by doing it?

    Also, it means I will have to restructure my math yet again, as if I had two points, <0,0,-24> and <10,0,-24> (stored in vectors)and I wanted to rotate around the y-axis, translating to <0,0,-24>, then that second point would be way off in its rotation, as it should then be <10,0,0>, as <0,0,-24> is the new origin for it(however, I could just write out my objects so that each object has a center point, and all the rest of its points are relative to that center).

    P.S.

    Silvercord:

    thank god for you recommending that book, as it has all the collision detection I could ever need, and it leaves the implementation codewise up to the individual pretty much.

    A little NOTE: I am thinking that in a little bit I might need help with some of the collision detection, as most of it uses time to predict the collision, instead of distance; however I dont know how I could implement time into consideration(unless I always solve for "t" in my equations and when "t" is almost equal to 0 count it as a collision)

  2. #32
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    I don't like the way they explain collision detection in that book, however ultimately it's very close to what i actually do.

    If you plan on implementing quake3 BSP, you are going to need to learn the brush collision detection algorithm for colliding against the world. Also, collision detection was one of the more complicated things I had to code up. Ultimately the tutorials you'll read all have problems which I've had to work around or solve.

  3. #33
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    You are creating your objects around 0,0,0 aren't you? In local space that is or model space? If you create a model around another point when you create it, you are asking for troubles because every rotation you do is compounded upon the fact that the original model was not built around 0,0,0.

  4. #34
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    blade i don't know what your problem is with the rotations/translations.

  5. #35
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    blade i don't know what your problem is with the rotations/translations.
    I'm trying to remake the wheel(trying to code up my own solutions) it seems....it's something I unfortunatly do sometimes(AKA making things harder than they are).

    so besides the practice I get by doing this coding, is there even a real purpose for it?

  6. #36
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    what exactly are you doing, and what exactly is the problem? a little bit of intuition here and there never hurt anybody, but, like, I have no clue what you are trying to actually accomplish.

  7. #37
    Registered User grady's Avatar
    Join Date
    Oct 2003
    Posts
    27
    then that second point would be way off in its rotation
    Right, like I said:
    Originally posted by grady
    Code:
    struct angvelocity
    {
    	float x,y,z,degrees;
    };
    [snip]
    So in addition to the above struct, you have to specify a point to adjust the axis away from the origin of the scene. Rotating not through the origin also makes you have to do a little pre and post processing on the vertex you are rotating.
    Bubba is right but he left out what I referred to as the post processing. first tranlate to (x,y,z), rotate, then translate to (-x,-y,-z). This puts your rotated vector back in its proper place.

    There's an extremely easy way to do this....
    I like that, but it only works if the velocity vector is the axis of rotation. There is no reason to assume in advance that a torque applied to your object will rotate the object about the velocity vector. The axis of rotation can point in any direction depending on where the torque is applied on the object.
    Last edited by grady; 12-20-2003 at 01:43 PM.

  8. #38
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    grady, I'm just wondering, have you ever programmed anything? If so, post it. Otherwise, I'm just going to continue ignoring absolutely everything you say.

  9. #39
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    I am trying to program up Rotation code for the purpose of rotating the view vector of a camera, unless one could use a combination of Translating and rotating to do that.

  10. #40
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Code:
    void Translate(double dx,double dy,double dz)
    {
    
      double trans[4][4];
      double result[4][4];
      
      trans[0][0]=1.0;
      trans[0][1]=0.0;
      trans[0][2]=0.0;
      trans[0][3]=dx;
    
      trans[1][0]=0.0;
      trans[1][1]=1.0;
      trans[1][2]=0.0;
      trans[1][3]=dy;
    
      trans[2][0]=0.0;
      trans[2][1]=0.0;
      trans[2][2]=1.0;
      trans[2][3]=dz;
    
      trans[3][0]=0.0;
      trans[3][1]=0.0;
      trans[3][2]=0.0;
      trans[3][3]=1.0;
    
      MatMult(trans,master,result);
      MatCopy(result,master);
    }
    
    //Would be faster for one-dimensional array
    void MatMult(double m1[4][4], double m2[4][4], double r[4][4])
    {
      for (int i=0;i<4;i++)
      {
         for (int j=0;j<4;j++
         {
            result[i][j]=((m1[i][0]*m2[0][j])+(m1[i][1]*m2[1][j])+(m1[i][2]*m2[2][j])+(m1[i][3]*m2[3][j]));
         }
      }
    }
    
    void MatCopy(double source[4][4],double target[4][4])
    {
      for (int i=0;i<4;i++)
      {
         target[i][0]=source[i][0];
         target[i][1]=source[i][1];
         target[i][2]=source[i][2];
         target[i][3]=source[i][3];
       }
    }
    This is part of my DOS 3D engine setup. Now OpenGL and DirectX both do this stuff for you. Before you transform your object - translate it to where you want it. Then rotate it and transform it.

    The -x,-y,-z comes into play when you wish to move your player through the world - translate all objects by the negative vector of the player.

  11. #41
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    I'm just not sure what you are asking. I thought you were trying to rotate an object around a certain point.

    Rotating the camera view vector and rotating an object around a set point are two different things.

  12. #42
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    Rotating the camera view vector and rotating an object around a set point are two different things.
    I've been needing both...

    the question is, is there any advantage of making one's own rotating function(for rotation around points) over using glRotate3f()?

  13. #43
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    You do not need a separate rotation function for rotating around points.


    Here is what you need to determine:

    In your world, what objects need to rotate around certain points?

    Create a base class for this type of object that will auto-translate them to their correct position in local space and then derive from this class.

    I have no idea as to your structure for vertexes, polies, complete 3D objects, etc.

  14. #44
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    So your saying for each object, have a center point for which the rest of the object is placed in relationship to it?

  15. #45
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Essentially, yes, but you do not need a function to do this. Simply translate the entire object by the distance you want. Remember that the points are already correctly translated with respect to the origin of the object.

    Imagine adding 100 to every x component of your vertexes. Those at -10 would then become 90 and those at 100 would then become 200. But the distance between them remains the same - the object is still intact.

    You arm is correctly translated in relation to the center of your body. No matter how you rotate yourself or move, your arm should always remain relatively in the same place - given that you do not move it.

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with game code.
    By ajdspud in forum C++ Programming
    Replies: 5
    Last Post: 02-14-2006, 06:39 PM
  2. Replies: 5
    Last Post: 12-03-2003, 05:47 PM
  3. Help with code for simple Y2K problem
    By Mule in forum C++ Programming
    Replies: 3
    Last Post: 03-06-2003, 12:53 AM
  4. Problem multiplying rotation matrices together
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 03-04-2003, 09:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21