Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Yet another "help me with a singleton" thread

Reply
Thread Tools

Yet another "help me with a singleton" thread

 
 
GW2 GW2 is offline
Junior Member
Join Date: Dec 2011
Posts: 1
 
      12-15-2011
Okay, so I'm trying to implement a singleton into my code for the use of the camera. I don't ever want more than one camera so it makes sense (also we get bonus marks for using a singleton camera, I'm a programming student by the way). I have been trying this for about 2 hours and I just cannot seem to get it to work. Here are the errors I am getting:

Error 1 error LNK2019: unresolved external symbol "public: static class Camera * __cdecl Camera::GetInstance(void)" (?GetInstance@Camera@@SAPAV1@XZ) referenced in function "void __cdecl ChangeSize(int,int)" (?ChangeSize@@YAXHH@Z) C:\Users\GW2\Desktop\Scotts Class Project\Scotts Class Project\Main.obj

Error 2 error LNK1120: 1 unresolved externals C:\Users\GW2\Desktop\Scotts Class Project\Debug\Scotts Class Project.exe 1

The code is below and any and all input is greatly appreciated.

Main.cpp
Code:
#include <glut.h>
#include <stdio.h>
#include "Particles.h"
#include "DotGrid.h"
#include "Particle.h"
#include "V_randomizer.h"
#include "Camera.h"
//#include "V_randomizer.h"
#define ARRAY_AMMOUNT 1000
/// Simple prototypes for the callbacks
void RenderScene(void);
void HandleTimer(int ID);
void FunctionKeys(int key, int x, int y);
void Keyboard(unsigned char key, int x, int y);
void ChangeSize(GLsizei w, GLsizei h);
//Particle* p;
Particles pp(ARRAY_AMMOUNT); 
DotGrid d(0.9,8);
V_Randomizer* random;
//V_Randomizer* rand;
double x,y,z,rotation;

void init(void) 
{
   GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
   GLfloat mat_shininess[] = { 150.0 };
   GLfloat light_position[] = { 1.0, 200.0, 1.0, 10.0 };
   glClearColor (0.0, 0.0, 0.0, 0.0);
   glShadeModel (GL_SMOOTH);
   glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
   glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
   glLightfv(GL_LIGHT0, GL_POSITION, light_position);
   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);
   glEnable(GL_DEPTH_TEST);
}
void main(int argc, char **argv){
	//p = new Particle();
	random = new V_Randomizer();
	//p->vy = random->box_muller(0.0,2.0);
	rotation = 45.0;
	//create a pointer for the particle 
	glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(500, 500);
	glutCreateWindow("This is the window title");
	init ();
	/// Java does the same sort of thing here, 
	/// simply pass the name of a function that should
	/// be called whenever an event occurs. 
	glutReshapeFunc(ChangeSize);
	glutDisplayFunc(RenderScene);
	glutKeyboardFunc(Keyboard);
	glutSpecialFunc(FunctionKeys);
	glutTimerFunc(1000,HandleTimer,1);/// See HandleTimer(...)
	//rand = new V_Randomizer();
	//pp = new Particles(ARRAY_AMMOUNT); //creates the particle array
	//for (int i = 0; i < ARRAY_AMMOUNT; i++)
	//{
	//	pp[i] = new Particle(rand->box_muller(-4,10) , rand->box_muller(-6,8) , rand->box_muller(-9,9)); //fills the array
	//}			

	glutMainLoop(); /// This starts the main loop which will 
					/// call the appropreate subroutine 
					/// given the event
	//delete pp; //gets the particle the heck out of dodge
}

/// If the window changes size this subroutine will be called 
/// note: This subroutine will be called upon the creation of the window since, logically,
/// the window has changed from nothing to something	

void ChangeSize(GLsizei w, GLsizei h){
	Camera::GetInstance();
}

/// Whenever the scene needs to be redrawn this function is called

void RenderScene(void){
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);/// Clears the screen
	/// PLACE DRAWING CODE HERE
	glPushMatrix();
	glutSolidSphere (1.0, 20, 16);
	//p->render();
	glRotated(rotation, 1.0,0.0,0.0);
	d.createGrid();
	//for (int i = 0; i < ARRAY_AMMOUNT; i++){		
	//	pp.render();
	//}
	glPopMatrix();
	glFlush(); ///Shove everything through the "pipeline" 
}

void HandleTimer(int ID){
	pp.update(0.033);
	//p->update(0.033);
	/// This function send a message to the main loop that it's time to call
	/// the DisplayFunc which I called "RenderScene"
	glutPostRedisplay();
	/// The first value is the number of millseconds before the next event
	/// The second arg is a pointer to the callback function
	/// The third is the ID number of this timer 	
	glutTimerFunc(0.033,HandleTimer,1);
}

void FunctionKeys(int key, int x, int y){
	/// this function is called whenever a button off the standard keybord is pressed
	/// for example the function keys or the arrow keys - hint
	/// Look for the following
		if(key == GLUT_KEY_UP) 
		{
			printf("UP arrow\n");
			rotation+=1;
			printf("%lf", rotation);
		}
		if(key == GLUT_KEY_DOWN)
		{
			printf("DOWN arrow\n");
			rotation+=-1;
			printf("%lf", rotation);
		}		
		/// GLUT_KEY_DOWN
		/// GLUT_KEY_RIGHT
		/// GLUT_KEY_LEFT
}

void Keyboard(unsigned char key, int x, int y){
	printf("%c<%d> %d %d\n",key,key,x,y);
	if(key=='q' || key=='Q' || key == 27) exit(0);	
}
Camera.h
Code:
class Camera{
private:
	Camera();
	~Camera();
	Camera* Instance;
public:
	void Render(GLsizei w, GLsizei h);
	void Update(double _time);
	void Pan();
	static Camera* GetInstance();
};
Camera.cpp
Code:
#include "Camera.h"
#include <stdio.h>
#include <glut.h>
Camera* Camera::Instance = 0;
class Camera{
	//Camera* Camera::Instance = 0;

	Camera::Camera(){
	}

	Camera::~Camera(){
	}

	void Render(GLsizei w, GLsizei h)
	{
		//x = 0.0;
		//y = 3.0;
		//z = -10.0;
		glViewport(0,0,w,h);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		GLfloat aspectRatio = (GLfloat)w /(GLfloat)h;
		/*if(w < h){
			glOrtho(-10.0,10.0,-10.0 / aspectRatio, 10.0 / aspectRatio,10.0,-10.0);
		}else{
			glOrtho(-10.0* aspectRatio,10.0 * aspectRatio,-10.0 , 10.0 ,10.0,-10.0);
		}*/
		gluPerspective(120.0,aspectRatio,1.0,500.0);
		::gluLookAt(x,y,z,0.0,0.0,0.0,0.0,1.0,0.0);
	}

	void Update(double _time)
	{
	}

	void Pan()
	{
	}

	Camera GetInstance()
	{
		if(Instance == 0)
		{
			Instance = new Camera();
		}
		return Instance;
	}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What wireless ATA router? - yet another "What ATA?" thread Theo Markettos UK VOIP 10 07-23-2007 12:00 PM
Yet another Blockbuster vs Netflix thread wunnuy@netzero.net DVD Video 2 11-29-2005 11:21 PM
Yet another book recommendation, but for someone who can program and yet does not the terminology well Berehem C Programming 4 04-28-2005 05:25 PM
YACT: Yet another CEF thread.. ForceSHO Cisco 2 02-04-2005 04:51 PM
YYAT (Yet Another Acronym Thread) Tak-Shing Chan C Programming 89 12-19-2003 05:53 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57