Hello. I have made a .h file called "Vector.h" in order to store some of the commonly used operations I perform on vectors, as they don't seem to automatically be included. Here is a segment of the code:
//This extends the vectors functions
//Make a 3D version of POINT
struct POINT3 : POINT
float length(D3DXVECTOR2 v)
return sqrt( pow(v.x, 2) + pow(v.y, 2) );
float length(D3DXVECTOR3 v)
return sqrt( pow(v.x, 2) + pow(v.y, 2) + pow(v.z, 2) );
//...more after this point
Basically, each function is duplicated for a 2D and 3D DirectX vector. Now, up until recently I only #include-ed this file in a .cpp file for a class. However, I now find that I need that classes header file to include it too:
#define DIST 300 //How far we can "see" ahead of us. Set it back to 200 once you're done.
#define VIEWT 33 //Angle +/- for top view... May need tweaking.
#define VIEWS 22.5 //Angle +/- for side view
#define PREC 0.001 //Precision for which to check the triangle
#define PI 3.14159265
Player::Player(Camera* _camera, Overlay* _overlay)
camera = _camera;
overlay = _overlay;
modSphere = new Model("data/example/model/mod_debug.x",
new Texture("data/example/texture/tex_room.png" ) );
x = camera->getX();
y = camera->getZ();
z = -camera->getY();
Any help would be appreciated. I just can't figure out where to even start with this problem.
The errors you're seeing are not a compile error, but rather a linker error.
The linker is telling you that it found the same functions (length) multiple times.
Once in main.obj and once in player.obj.
The linker considers this an error since it doesn't know that they are the same.
This occured because you defined the two length functions in a .h file that was included in both main.cpp and player.cpp, therefore the functions were compiled twice.
It's not a good practice to define functions (or variables) in multiple places.
There is a linker switch that can tell the linker to ignore such errors, but I don't recommend that. Your best course of action is to put the two length functions in their own .cpp file.