• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Adam West

link 2005 error in project

1 post in this topic

Hello again!

i have recently created an FPS camera system for my engine but i am having trouble implementing,
the errors are as follows:
[CODE]
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
[/CODE]

here is the related source:

main.cpp
[CODE]
#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);
}
[/CODE]
main.h
[CODE]
//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
[/CODE]
camera.h
[CODE]
#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
[/CODE]
camera.cpp
[CODE]
#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);
}
[/CODE]


looking forward to hearing your input :P
0

Share this post


Link to post
Share on other sites
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.
2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0