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