Jump to content
  • Advertisement
Sign in to follow this  
Adam West

link 2005 error in project

This topic is 2412 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello again!

i have recently created an FPS camera system for my engine but i am having trouble implementing,
the errors are as follows:

Error 5 error LNK2005: "float camX" (?camX@@3MA) already defined in camera.obj C:\Users\adam\documents\visual studio 2010\Projects\PheonixEngine\PheonixEngine\main.obj
Error 6 error LNK2005: "float camY" (?camY@@3MA) already defined in camera.obj C:\Users\adam\documents\visual studio 2010\Projects\PheonixEngine\PheonixEngine\main.obj
Error 7 error LNK2005: "float camZ" (?camZ@@3MA) already defined in camera.obj C:\Users\adam\documents\visual studio 2010\Projects\PheonixEngine\PheonixEngine\main.obj
Error 8 error LNK2005: "float camYaw" (?camYaw@@3MA) already defined in camera.obj C:\Users\adam\documents\visual studio 2010\Projects\PheonixEngine\PheonixEngine\main.obj
Error 9 error LNK2005: "float camPitch" (?camPitch@@3MA) already defined in camera.obj C:\Users\adam\documents\visual studio 2010\Projects\PheonixEngine\PheonixEngine\main.obj
Error 10 error LNK2005: "bool mousein" (?mousein@@3_NA) already defined in camera.obj C:\Users\adam\documents\visual studio 2010\Projects\PheonixEngine\PheonixEngine\main.obj
Error 11 error LNK1169: one or more multiply defined symbols found C:\Users\adam\documents\visual studio 2010\Projects\PheonixEngine\Debug\PheonixEngine.exe 1


here is the related source:

main.cpp

#include "main.h"
#include "3dsloader.h"
#include "camera.h"

void lighting();
void initRendering();
void drawScene();
void mainLoop();
FPSCamera * camera;
Object* testcube;

int main(int argc, char **argv)
{
bool running = true;

InitializeWindow();

testcube = new Object("apex.3ds");

initRendering();
testcube->CreateVBO();
glOrtho(-20.0, 20.0, -110.0, 5.0, -30.0, 5.0);
mainLoop();

return 0;
}

void initRendering()
{
glTranslatef(0.0f, 0.0f, -5.0f); // translate camera
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
// Enable lighting and set the position of the light
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
GLfloat pos[] = { 0.0, 4.0, 4.0 };
glLightfv(GL_LIGHT0, GL_POSITION, pos);

}

void mainLoop(void)
{
// the time of the previous frame
double old_time = glfwGetTime();
// this just loops as long as the program runs
while(1)
{
// KEY EVENTS 1
// escape to quit,
if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS)
break;
if (glfwGetKey(GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)
mousein = true;
glfwDisable(GLFW_MOUSE_CURSOR);
break;
if (glfwGetKey('P')== GLFW_PRESS)
mousein = false;
glfwEnable(GLFW_MOUSE_CURSOR);
break;
camera->updateCamera();

// draw the figure
drawScene();

// swap back and front buffers
glfwSwapBuffers();
}
}
void drawScene()
{
//clear info from last draw
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
camera->Control(0.2,0.2,mousein);

// ADD SCENE OBJECTS TO RENDER HERE
testcube->Draw();
};
void shutdown()
{
glfwTerminate();
delete testcube;
delete camera;
exit(1);
}

main.h

//Include STD headers
#ifndef MAIN_H
#define MAIN_H
#include<GL/glew.h>
#include<GL/glfw.h>
#include<GL/freeglut.h>
#include <vector>
#include<algorithm>
#include <fstream>
#include<cstdio>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>


//Include GLM
#include <glm/glm.hpp>
using namespace glm;

extern void InitializeWindow();
extern void shutdown();
#endif

camera.h

#include "main.h"
#ifndef CAMERA_H
#define CAMERA_H
const double pi=3.14159265358979323846;
float camX= 0.0, camY=0.0, camZ=5.0;
float camYaw=0.0;
float camPitch=0.0;
bool mousein= false;
class FPSCamera
{
public:
void lockCamera();
void moveCamera(float,float);
void moveCameraUp(float,float);
void Control(float,float,bool);
void updateCamera();

};
#endif

camera.cpp

#include "camera.h"

void FPSCamera::lockCamera()
{

if(camPitch>90)
camPitch = 90;
if(camPitch<-90)
camPitch=-90;
if(camYaw<0.0)
camYaw+=360.0;
if(camYaw>360.0)
camYaw-=360;
}
void FPSCamera::moveCamera(float distance,float direction)
{
float rad=(camYaw+direction)*pi/180.0;
camX-=sin(rad)*distance;
camZ-=cos(rad)*distance;
}
void FPSCamera::moveCameraUp(float distance, float direction)
{
float rad=(camPitch+direction)*pi/180.0;
camY+=sin(rad)*distance;
}
void FPSCamera::Control(float moveveloicty, float mousevelocity, bool mousein)
{
if(mousein)
{
int MidX=320; //change to resolution divied by 2
int MidY=240;
glfwDisable(GLFW_MOUSE_CURSOR);
int tmpx, tmpy;
glfwGetMousePos(&tmpx, &tmpy);
camYaw+=mousevelocity*(MidX-tmpx);
camPitch+=mousevelocity*(MidY-tmpy);
lockCamera();
glutWarpPointer(MidX,MidY);
glfwSetMousePos(MidX,MidY);

if(glfwGetKey('W') == GLFW_PRESS)
{
if(camPitch!=90 && camPitch!=-90)
moveCamera(moveveloicty,0.0);
moveCameraUp(moveveloicty,0.0);
}

if(glfwGetKey('S') == GLFW_PRESS)
{
if(camPitch!=90 && camPitch!=-90)
moveCamera(moveveloicty,180.0);
moveCameraUp(moveveloicty,180.0);
}

if(glfwGetKey('A') == GLFW_PRESS)
{
moveCamera(moveveloicty,90.0);
}
if(glfwGetKey('D') == GLFW_PRESS)
{
moveCamera(moveveloicty,270.0);
}
glRotatef(-camPitch,1.0,0.0,0.0);
glRotatef(-camYaw,0.0,1.0,0.0);
}
}
void FPSCamera::updateCamera()
{
glTranslatef(-camX,-camY,-camZ);
}



looking forward to hearing your input :P

Share this post


Link to post
Share on other sites
Advertisement
The linker gives you a hint: some symbols have been defined multiple times. Those float globals in Camera.h can be declared there, but you shoud define them somewhere else, best place is in Camera.cpp. The header should contain float camX, camY, camZ. The cpp should contain float camX = 0.0f;


Now some (constructive!) criticism towards your code:

Why does your FPSCamera class use those global variables? Only use globals when you absolutely have to, or they will come back to bite you in the behind. In this case, camX ect. should be members of the FPSCamera class. Remove the globals in main.cpp too.

Pi is indeed a good candidate for a const global, but doesn't belong in Camera.h. Ask yourself this: you need Pi for some calculations, does it make sense if you have to include Camera.h?

Camera.h includes main.h. Why? Has the camera a dependency on main? Include as little as possible in the header. In this case, you don't have to include anything. Include what you need for the implementation on your cpp file.

Use smart pointers instead of raw pointers.

I may be missing something, but you don't appear to be using shutdown(). Remove this function, move the call to glfwTerminate to the end of main().

Terminate the application by changing 'while(1)' in the main loop to 'while(running)' where running is a bool. When the user presses escape, set running to false. Try to avoid using exit(), it makes it harder to reason about code.

Add parameter names to your function declarations. They're a form of documentation. When peeking at the header, I have no idea what I should pass to moveCamera(float, float).

Never put 'using namespace x' in a header, this kills the benefits of namespaces in every file that includes it, directly or indirectly.

Don't handle keypresses in your camera class. Add functions to the class which allow you to move the camera, call these from another place where you handle all user input.


There is more I can find, but this should be enough for now. Please let me know if you have any more questions.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!