# should I build my own vector and matrix classes?

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 01-04-2003
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' :)
• 01-04-2003
rmullen3
_
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.
• 01-09-2003
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.
• 01-09-2003
Polymorphic OOP
Quote:

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
• 01-09-2003
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

Quote:

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?
• 01-09-2003
Polymorphic OOP
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.
• 01-09-2003
Nick
There are directional vectors which are
divides by 0 if you try to normalize one. I'm not sure
how you would want to handle that in your code.
• 01-13-2003
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...
• 01-13-2003
Polymorphic OOP
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.
• 01-13-2003
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.
• 01-13-2003
Nick
I think it's called the locus point.

Quote:

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.
• 01-13-2003