Thread: should I build my own vector and matrix classes?

  1. #16
    Shadow12345
    Guest
    Like I said I'm just going to keep this thread alive as a general purpose math/geometry etc questions place. Here is a line of code I'm not too sure on. We are finding the vector to rotate our up/down view about. I dont' understand why the position is subtracted from the view when calculating the cross product

    Code:
    CVector3 vAxis = Cross(m_vView - m_vPosition, m_vUpVector);
    		vAxis = Normalize(vAxis);
    
    		// Rotate around our perpendicular axis and along the y-axis
    		RotateView(angleZ, vAxis.x, vAxis.y, vAxis.z);
    Again, this is from a tutorial. I don't know if you can answer this question, i.e if you don't know yourself then there must be something I have missed in the tutorial.

    EDIT: Incidentally the author's name is 'DigiBen'
    Last edited by Shadow12345; 01-04-2003 at 04:11 PM.

  2. #17
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330

    _

    Yeah I'm still trying to figure those tutorials out. The camera ones right?

    You can do essentially the same thing that the camera tutorials do in 1/10 the amount of code:

    Code:
        float cosYaw = (float)cos(radAngle);
        float sinYaw = (float)sin(radAngle);
        float sinPitch = (float)sin(57.29577952 * LookUpDown));
    
        float lookAtx = pos.x + cosYaw;
        float lookAty = pos. + sinPitch;
        float lookAtz = pos.z + sinYaw;
    
        // set the camera
        gluLookAt(pos.x, yCam, pos.z,
                 lookAtx, lookAty, lookAtz,
                 0.0, 1.0, 0.0);
    but I don't know how to do collision detection with my camera... = /

    As for your vector class, I'd have the functions take const Vector3D references so you don't waste any time making a copy... also for functions where you're dividing the x, y and z by the same value, instead calculate the reciprocal once and multiply by that, you'll get a speed boost.

  3. #18
    Shadow12345
    Guest
    ok I'm kind of changing the subject but this is still a math oriented thread. Anyway, I think I understand how to determine which verticies of a polygon are on which side (front, back, or on) a plane. This is just a confirmation (I am going to confirm most of the things I do before I use it).

    To determine if a vertex is on in front or behind a plane use the following equation:

    Ax + By + Cz + D = 0;

    If it is 0, then the vertex substituted for the x,y,and z values are exactly on the plane, if it is greater than 0 then it is in front of the plane and it will give the distance from the plane, if it is negative it is behind the plane and it gives the distance from the plane.
    This must be how John Carmack (and other developers) split polygons when doing binary space partitioning when a cutting plane intersects through a polygon (which is different from how you did it, Poly).


    The A, B, and C values represent the normal vector of the plane, D represents any vertex that is known to be on the plane.

    If any of that is inaccurate someone please explain why. Thanks.

  4. #19
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by Shadow12345

    To determine if a vertex is on in front or behind a plane use the following equation:

    Ax + By + Cz + D = 0;

    If it is 0, then the vertex substituted for the x,y,and z values are exactly on the plane, if it is greater than 0 then it is in front of the plane and it will give the distance from the plane, if it is negative it is behind the plane and it gives the distance from the plane.
    This must be how John Carmack (and other developers) split polygons when doing binary space partitioning when a cutting plane intersects through a polygon (which is different from how you did it, Poly).


    The A, B, and C values represent the normal vector of the plane, D represents any vertex that is known to be on the plane.

    If any of that is inaccurate someone please explain why. Thanks.
    Almost. Yeah, that's how it's done, but you are confused about D.

    How could D be a point? a point has 3 components in 3-space.

    D is the positive or negative distance from the plane to the origin in units defined by the length of the normal defined by a, b, and c

  5. #20
    Shadow12345
    Guest
    Okay that makes a bit more sense, I was a little confused about that, but I thought that's what a tutorial said, here's the confusion

    For those not familiar with the plane equation, The values A, B, and C are the coordinate values of the normal vector. D can be calculated by substituting a point known to be on the plane for x, y, and z.
    that is just saying D can be calculated by substituting a known point on the plane, not that it is actually a known point on the plane. Thanks again poly. This stuff is pretty cool, actually, I thought it would be insanely hard, which it isn't the easiest stuff i've ever done, but I think I'll live.

    Also, a zero dimensional vector is basically just a point, right?

  6. #21
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    No, a 0-dimensional vector has no location, no direction, and no magnitude. Vectors never have a location and so they can never be a point. A 0-dimensional vector is still just as much a vector as a 2 or 3 dimensional vector and is still very different from a point.

    One of the only uses of a 0-Dimensional vector is to represent a translation of a point in no direction with no magnitude (IE, the translation does nothing). It's equivalent in value (though not in logic) to a 3D vector with each of its components set to 0. It doesn't sound like it's of much importance, but it can be useful sometimes.

  7. #22
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    There are directional vectors which are
    sort of like points. Talking about 0 vectors... your code
    divides by 0 if you try to normalize one. I'm not sure
    how you would want to handle that in your code.

  8. #23
    Shadow12345
    Guest
    I dont' see how a vector or plane can have a distance from the origin. What does that mean exactly? It doesn't even seem possible to compare planes/vectors to the origin because the origin is a single point, vectors and planes are not, so I don't see how there can be a 'distance' from the plane to the origin...frig...

  9. #24
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    of course it can have a distance. Take a piece of paper and some object in your room. The distance is how far away from the paper it is at the closest point. The closest point on a plane to a point is where the line with direction defined by the normal starting from a spot on the plane intersects with the point.

  10. #25
    Shadow12345
    Guest
    Ok the closest point makes much more sense, I should've figured as much. Isn't there a name for that, like the apothem or something?

    EDIT: What books do you have on geometry and stuff that would entail all of these types of questions I'm asking? Would it fit under analytical geometry or something? We don't get to do any of this stuff in my high school so I have to do it on my own.

  11. #26
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    I think it's called the locus point.

    EDIT: What books do you have on geometry and stuff that would entail all of these types of questions I'm asking? Would it fit under analytical geometry or something? We don't get to do any of this stuff in my high school so I have to do it on my own.
    The beginning chapters of a multivariable calculus covers
    vectors and stuft.

  12. #27
    Shadow12345
    Guest
    I think it's called the locus point.
    I knew it's not actually called the apothem, the apothem is the shortest distance from the middle of an object to the edge, i.e the radius of a sphere is an apothem. I would like to know what poly has for books, basically because he is already going to the school I am hoping to get into.
    Last edited by Shadow12345; 01-13-2003 at 08:44 PM.

Popular pages Recent additions subscribe to a feed