Sign in to follow this  
Argo15

I'm getting this error.

Recommended Posts

Ok, I'm making this test OpenGL app to move a camera. So I made a new object. Class.h #ifndef __CAMERA_H__ #define __CAMERA_H__ class Camera { private: public: Camera(); virtual ~Camera(); void Init(); // Left, Up(forward), Down(backward), Right respectively bool MoveCamera[3]; bool RotateCamera[3]; float VerticalPosition; float HorizantalPosition; float VerticalAngle; float HorizantalAngle; void StartMovement(int Direction); void StartRotation(int Direction); void StopMovement(int Direction); void StopRotation(int Direction); void SetUpCamera(); void Prepare(float dt); }; #endif class.cpp #ifdef _WINDOWS #include <windows.h> #endif #include <gl/gl.h> #include <gl/glu.h> #include <math.h> #include "CGfxOpenGL.h" #include "Camera.h" Camera::Camera() { } Camera::~Camera() { } void Camera::Init() { for (int i = 0; i < 3; i++){ MoveCamera[i] = false; RotateCamera[i] = false; } } void Camera::StartMovement(int Direction) { MoveCamera[Direction] = true; } void Camera::StartRotation(int Direction) { RotateCamera[Direction] = true; } void Camera::StopMovement(int Direction) { MoveCamera[Direction] = false; } void Camera::StopRotation(int Direction) { RotateCamera[Direction] = false; } void Camera::Prepare(float dt) { if MoveCamera[0] = true HorizantalPosition -= 1 * dt; if MoveCamera[1] = true VerticalPosition -= 1 * dt; if MoveCamera[2] = true VerticalPosition += 1 * dt; if MoveCamera[3] = true HorizantalPosition += 1 * dt; if RotateCamera[0] = true HorizantalAngle += 1 * 30.0f * dt; if RotateCamera[1] = true VerticalAngle -= 1 * 30.0f * dt; if RotateCamera[2] = true VerticalAngle += 1 * 30.0f * dt; if RotateCamera[3] = true HorizantalAngle -= 1 * 30.0f * dt; } void Camera::SetUpCamera() { glPushMatrix(); glTranslatef(HorizantalPosition, 0.0f, VerticalPosition); glRotatef(HorizantalAngle, 0.0f, 1.0f, 0.0f); glRotatef(VerticalAngle, 1.0f, 0.0f, 0.0f); gluLookAt(0.0f, 0.0f, 10.0f, 0.0f, 0.0f, -100.0f, 0.0f, 1.0f, 0.0f); glPopMatrix(); } Now the only errors I am getting are, 1>c:\users\billy\desktop\cpp\opengl\camera\camera.cpp(49) : error C2061: syntax error : identifier 'MoveCamera' 1>c:\users\billy\desktop\cpp\opengl\camera\camera.cpp(51) : error C2061: syntax error : identifier 'MoveCamera' 1>c:\users\billy\desktop\cpp\opengl\camera\camera.cpp(53) : error C2061: syntax error : identifier 'MoveCamera' 1>c:\users\billy\desktop\cpp\opengl\camera\camera.cpp(55) : error C2061: syntax error : identifier 'MoveCamera' 1>c:\users\billy\desktop\cpp\opengl\camera\camera.cpp(58) : error C2061: syntax error : identifier 'RotateCamera' 1>c:\users\billy\desktop\cpp\opengl\camera\camera.cpp(60) : error C2061: syntax error : identifier 'RotateCamera' 1>c:\users\billy\desktop\cpp\opengl\camera\camera.cpp(62) : error C2061: syntax error : identifier 'RotateCamera' 1>c:\users\billy\desktop\cpp\opengl\camera\camera.cpp(64) : error C2061: syntax error : identifier 'RotateCamera' Which all take place in the Camera::Prepare function. I can't figure out why they arn't working, they seem like simple bools.

Share this post


Link to post
Share on other sites
The condition part of an if statement must be enclosed in parenthesis. Also, '=' is for assignment; '==' is for comparison. Finally, array indices are zero-based, so the indices should be 0, 1, 2, not 1, 2, 3.

It should be:

if (MoveCamera[0] == true) ...


EDIT: Actually, like SiCrane said, the '== true' part can be omitted.

Share this post


Link to post
Share on other sites
if (MoveCamera[0] == true)

The error is only related to the parentheses, but you'll want to use the comparison operator rather than assignment (if, as SiCrane mentioned, you must make it explicit).

[Edit: much too slow.]

Share this post


Link to post
Share on other sites
Quote:
Original post by Argo15
// Left, Up(forward), Down(backward), Right respectively
bool MoveCamera[3];


No. The number in the square brackets is the number of elements of the array. Count: left, up, down, right. That is four things.

But this is a clumsy way to do it anyway: what if I ask for both left and right movement? And it's not particularly easy to keep the order straight, either.

Instead, store a horizontal (note spelling BTW) and vertical speed, and provide just one function to set them both at once. (You can stop the camera by setting both to zero.) Similarly for angle.

Share this post


Link to post
Share on other sites
Haha, that was dumb. Anyway I'm getting another error when i debug my sucessfully built program.
Unhandled exception at 0x00432edd in OpenGLProject.exe: 0xC0000005: Access violation reading location 0x00000000.

Share this post


Link to post
Share on other sites
I built my file correctly, but when I run the exe it came up with.
[img]http://i21.photobucket.com/albums/b287/cardswordsman/Untitled.jpg?t=1203540344[/img]
When i debug it, I recieve the previous message in a popup and this in the debug window.
First-chance exception at 0x00432edd in OpenGLProject.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x00432edd in OpenGLProject.exe: 0xC0000005: Access violation reading location 0x00000000.

Share this post


Link to post
Share on other sites
alright, well, i'm using Dave Astle's Timer.h file so the camera can move based on time.

/****************************************************************************
HiResTimer.h

Wrapper for the high-resolution timer. Can't be used if the hi-res timer
doesn't exist.

Author : Dave Astle
Date : 2/1/2001

Written for OpenGL Game Programming
*****************************************************************************/

#ifndef __TIMER_H_INCLUDED__
#define __TIMER_H_INCLUDED__

#include <windows.h>


class CHiResTimer
{
public:
CHiResTimer() {}
~CHiResTimer() {}

/*****************************************************************************
Init()

If the hi-res timer is present, the tick rate is stored and the function
returns true. Otherwise, the function returns false, and the timer should
not be used.
*****************************************************************************/
bool Init()
{
if (!QueryPerformanceFrequency(&m_ticksPerSecond))
{
// system doesn't support hi-res timer
return false;
}
else
{
QueryPerformanceCounter(&m_startTime);
return true;
}
} // end Init()


float GetElapsedSeconds(unsigned long elapsedFrames = 1)
{
static LARGE_INTEGER s_lastTime = m_startTime;
LARGE_INTEGER currentTime;

QueryPerformanceCounter(¤tTime);

float seconds = ((float)currentTime.QuadPart - (float)s_lastTime.QuadPart) / (float)m_ticksPerSecond.QuadPart;

// reset the timer
s_lastTime = currentTime;

return seconds;
} // end GetElapsedSeconds()


/***************************************************************************
GetFPS()

Returns the average frames per second over elapsedFrames, which defaults to
one. If this is not called every frame, the client should track the number
of frames itself, and reset the value after this is called.
***************************************************************************/
float GetFPS(unsigned long elapsedFrames = 1)
{
static LARGE_INTEGER s_lastTime = m_startTime;
LARGE_INTEGER currentTime;

QueryPerformanceCounter(¤tTime);

float fps = (float)elapsedFrames * (float)m_ticksPerSecond.QuadPart / ((float)currentTime.QuadPart - (float)s_lastTime.QuadPart);

// reset the timer
s_lastTime = currentTime;

return fps;
} // end GetFPS


/***************************************************************************
LockFPS()

Used to lock the frame rate to a set amount. This will block until enough
time has passed to ensure that the fps won't go over the requested amount.
Note that this can only keep the fps from going above the specified level;
it can still drop below it. It is assumed that if used, this function will
be called every frame. The value returned is the instantaneous fps, which
will be <= targetFPS.
***************************************************************************/
float LockFPS(unsigned char targetFPS)
{
if (targetFPS == 0)
targetFPS = 1;

static LARGE_INTEGER s_lastTime = m_startTime;
LARGE_INTEGER currentTime;
float fps;

// delay to maintain a constant frame rate
do {
QueryPerformanceCounter(¤tTime);
fps = (float)m_ticksPerSecond.QuadPart/((float)(currentTime.QuadPart - s_lastTime.QuadPart));
} while (fps > (float)targetFPS);

// reset the timer
s_lastTime = m_startTime;

return fps;
} // end LockFPS()


private:
LARGE_INTEGER m_startTime;
LARGE_INTEGER m_ticksPerSecond;
};

#endif // __TIMER_H_INCLUDED_








Bolded is the section that it stops at.

Share this post


Link to post
Share on other sites
My guess is that the instance of CHiResTimer is NULL, meaning that you have an uninitialised pointer of type CHiResTimer and you are calling GetElapsedSeconds on it. Look at the article I linked, it will give you an idea of how to use your debugger to solve the problem. Hint: an important term is 'back trace'.

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