我有下面的代码,它是一个保龄球游戏。此代码在 Eclipse 中运行良好,但我随后将其移至microsoft visual studio express 2012 for windows desktop,它给出了以下错误。
错误1 error C2470: 'cone1' : 看起来像函数定义,但没有参数列表;跳过明显的身体 c:\users\rockckky\documents\visual studio 2012\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 26 1 ConsoleApplication1
注意: - 我没有粘贴所有错误,它给出了相同的错误类型锥体已定义。
#include "stdafx.h"
#include "cstdlib"
#include "GL/glut.h"
#include "GL/glu.h"
#include "stdlib.h"
#include "vector"
using namespace std;
int refreshMillis = 30; // Refresh period in milliseconds
int windowWidth = 640; // Windowed mode's width
int windowHeight = 480; // Windowed mode's height
int windowPosX = 50; // Windowed mode's top-left corner x
int windowPosY = 50; // Windowed mode's top-left corner y
bool fullScreenMode = false; // Full-screen or windowed mode?
GLfloat ballSpeed = 0.150f; // Ball's speed in y directions
GLfloat speedLine;
GLfloat ballMaxSpeed = 0.550f, ballMinSpeed = 0.150f;
bool moveBallUp = false, moveBallDown = false, isCollision = false, resetCall =
false, moveRight = false, moveLeft = false, ballInRight = false,
ballInMiddle = true, ballInLeft = false;
GLfloat vp_x = 2.0f, vp_y = 10.0f, vp_z = 25.0f, vt_x = 2.0f, vt_y = 20.0f,
vt_z = 0.0f, vu_x = 0.0f, vu_y = 0.0f, vu_z = 1.0f;
//eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz
/* the cones in the center */
vector<GLfloat> cone1 { 0.0f, 0.0f, -21.0f, /*rotated*/60.0f, -1.5f, 0.0f, 0.0f };
vector<GLfloat> cone2 { 1.6f, 0.0f, -21.0f, /*rotated*/60.0f, -1.5f, 0.0, 0.0 };
vector<GLfloat> cone3 { -1.6f, 0.0f, -21.0f, /*rotated*/60.0f, -1.5f, 0.0, 0.0 };
/* the cones in the left */
vector<GLfloat> cone4 { -4.9f, 0.0f, -21.0f, /*rotated*/60.0f, -1.5f, 0.0, 0.0 };
vector<GLfloat> cone5 { -6.7f, 0.0f, -21.0f, /*rotated*/60.0f, -1.5f, 0.0, 0.0 };
vector<GLfloat> cone6 { -8.3f, 0.0f, -21.0f, /*rotated*/60.0f, -1.5f, 0.0, 0.0 };
/* the right cones */
vector<GLfloat> cone7 { 4.9f, 0.0f, -21.0f, /*rotated*/60.0f, -1.5f, 0.0, 0.0 };
vector<GLfloat> cone8 { 6.6f, 0.0f, -21.0f, /*rotated*/60.0f, -1.5f, 0.0, 0.0 };
vector<GLfloat> cone9 { 8.3f, 0.0f, -21.0f, /*rotated*/60.0f, -1.5f, 0.0, 0.0 };
vector<GLfloat> ball {/* X */0.0f, /* Y */0.0f, /* Z */-3.0f, /*sphere*/0.85f,
50.0, 50.0 };
//
void resetGame() {
resetCall = true;
cone1 = {0.0f, 0.0f, -21.0f, /*rotated*/60.0f, -1.5f, 0.0f, 0.0f};;
cone2= {1.6f, 0.0f, -21.0f, /*rotated*/60.0f, -1.5f, 0.0, 0.0};
cone3= {-1.6f, 0.0f, -21.0f, /*rotated*/60.0f, -1.5f, 0.0, 0.0};
/* the cones in the left */
cone4 = {-4.9f,0.0f, -21.0f, /*rotated*/60.0f, -1.5f, 0.0, 0.0};
cone5 = {-6.7f, 0.0f, -21.0f, /*rotated*/60.0f, -1.5f, 0.0, 0.0};
cone6 = {-8.3f, 0.0f, -21.0f, /*rotated*/60.0f, -1.5f, 0.0, 0.0};
/* the right cones */
cone7= {4.9f, 0.0f, -21.0f, /*rotated*/60.0f, -1.5f, 0.0, 0.0};
cone8 = {6.6f, 0.0f, -21.0f, /*rotated*/60.0f, -1.5f, 0.0, 0.0};
cone9= {8.3f, 0.0f, -21.0f, /*rotated*/60.0f, -1.5f, 0.0, 0.0};
ball = {/* X */0.0f, /* Y */0.0f, /* Z */-3.0f, /*sphere*/0.85f, 50.0,
50.0};
}
float ar;
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };
/* Called back when the timer expired */
void Timer(int value) {
if (moveBallUp) {
// ball[1] += ballSpeed;
ball[2] -= ballSpeed;
if (ballInRight)
ball[0] += 0.08;
if (ballInLeft)
ball[0] -= 0.08;
}
if (moveRight) {
if (ball[0] >= 4.0) {
moveRight = false;
ballInMiddle = false;
ballInLeft = false;
ballInRight = true;
}
ball[0] += 0.156;
if (ball[0] >= -0.02 && ball[0] <= 0.02) {
moveRight = false;
ballInLeft = false;
ballInRight = false;
ballInMiddle = true;
}
}
if (moveLeft) {
if (ball[0] <= -4.0) {
moveLeft = false;
ballInRight = false;
ballInMiddle = false;
ballInLeft = true;
}
ball[0] -= 0.156;
if (ball[0] >= -0.02 && ball[0] <= 0.02) {
moveLeft = false;
ballInLeft = true;
}
}
/* If ball reaches to Z coordinates of the all cones */
if (ball[2] <= cone1[2]) {
/* Now check ball's x axis that which set of cones has it hit */
/* check for the middle set of cones */
if (ball[0] >= cone3[0] && ball[0] <= cone2[0]) {
if (!isCollision /* isCollision ! = true */) {
cone1[0] -= 0.5;
cone1[4] -= 10.0;
cone1[5] += 10.0;
cone1[2] += -0.3;
cone2[0] += 0.5;
cone2[4] -= 10.0;
cone2[5] -= 10.0;
cone2[2] += -0.4;
cone3[0] += 0.5;
cone3[4] -= 10.0;
cone3[5] -= 10.0;
cone3[2] += -0.4;
}
isCollision = true;
moveBallUp = false; // stop moving the ball
}
/* check if ball is in the range of x axis of right set of cones */
if (ball[0] >= cone6[0] && ball[0] <= cone4[0]) {
if (!isCollision /* isCollision ! = true */) {
cone4[0] -= 0.5;
cone4[4] -= 10.0;
cone4[5] += 10.0;
cone4[2] += -0.3;
cone5[0] += 0.5;
cone5[4] -= 10.0;
cone5[5] -= 10.0;
cone5[2] += -0.4;
cone6[0] += 0.5;
cone6[4] -= 10.0;
cone6[5] -= 10.0;
cone6[2] += -0.4;
}
isCollision = true;
moveBallUp = false; // stop moving the ball
}
if (ball[0] >= cone7[0] && ball[0] <= cone9[0]) {
if (!isCollision /* isCollision ! = true */) {
cone7[0] -= 0.5;
cone7[4] -= 10.0;
cone7[5] += 10.0;
cone7[2] += -0.3;
cone8[0] += 0.5;
cone8[4] -= 10.0;
cone8[5] -= 10.0;
cone8[2] += -0.4;
cone9[0] += 0.5;
cone9[4] -= 10.0;
cone9[5] -= 10.0;
cone9[2] += -0.4;
}
isCollision = true;
moveBallUp = false; // stop moving the ball
}
}
if (resetCall) {
if (ball[2] >= -3.0f) {
resetCall = false;
isCollision = false;
}
else {
if (ballInRight)
ball[0] -= 0.08;
if (ballInLeft)
ball[0] += 0.08;
ball[2] -= ballSpeed;
}
}
glutPostRedisplay(); // Post a paint request to activate display()
glutTimerFunc(refreshMillis, Timer, 0); // subsequent timer call at milliseconds
}
void keyboard(unsigned char key, int x, int y) {
switch (key) {
case 27: // ESC key
exit(0);
break;
case 'r':
resetGame();
break;
case 'i':
vp_x += 0.5;
break;
case 'I':
vp_x -= 0.5;
break;
/*GLfloat vp_x = 3.0f, vp_y = 10.0f, vp_z = 10.0f, vt_x = 0.0f, vt_y = 0.0f,
vt_z = 0.0f, vu_x = 0.0f, vu_y = 0.0f, vu_z = -1.0f;*/
case 'o':
vp_y += 0.5;
break;
case 'O':
vp_y -= 0.5;
break;
case 'p':
vp_z += 0.5;
break;
case 'P':
vp_z -= 0.5;
break;
case 'j':
vt_x += 0.5;
break;
case 'J':
vt_x -= 0.5;
break;
case 'k':
vt_y += 0.5;
break;
case 'K':
vt_y -= 0.5;
break;
case 'l':
vt_z += 0.5;
break;
case 'L':
vt_z -= 0.5;
break;
case 'b':
vu_x += 0.5;
break;
case 'B':
vu_x -= 0.5;
break;
case 'n':
vu_y += 0.5;
break;
case 'N':
vu_y -= 0.5;
break;
case 'm':
vt_z += 0.5;
break;
case 'M':
vu_z -= 0.5;
break;
}
glutPostRedisplay();
}
void specialKeys(int key, int x, int y) {
switch (key) {
case GLUT_KEY_F1: // F1: Toggle between full-screen and windowed mode
fullScreenMode = !fullScreenMode; // Toggle state
if (fullScreenMode) { // Full-screen mode
windowPosX = glutGet(GLUT_WINDOW_X ); // Save parameters for restoring later
windowPosY = glutGet(GLUT_WINDOW_Y );
windowWidth = glutGet(GLUT_WINDOW_WIDTH );
windowHeight = glutGet(GLUT_WINDOW_HEIGHT );
glutFullScreen(); // Switch into full screen
} else { // Windowed mode
glutReshapeWindow(windowWidth, windowHeight); // Switch into windowed mode
glutPositionWindow(windowPosX, windowPosX); // Position top-left corner
}
break;
case GLUT_KEY_UP:
if (!isCollision)
moveBallUp = true;
break;
case GLUT_KEY_PAGE_UP:
if (ballSpeed >= ballMaxSpeed)
break;
ballSpeed *= 1.1f;
break;
case GLUT_KEY_PAGE_DOWN:
if (ballSpeed <= ballMinSpeed)
break;
ballSpeed *= 0.95f;
break;
case GLUT_KEY_RIGHT:
if (ball[0] >= 4.0)
break;
moveRight = true;
break;
case GLUT_KEY_LEFT:
if (ball[0] <= -4.0)
break;
moveLeft = true;
break;
}
}
static void display(void) {
int const width = glutGet(GLUT_WINDOW_WIDTH );
int const height = glutGet(GLUT_WINDOW_HEIGHT );
const float ar = (float) width / (float) height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-ar, ar, -ar, ar, 1.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(vp_x, vp_y, vp_z, vt_x, vt_y, vt_z, vu_x, vu_y, vu_z);
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
/* Center */
glColor3d(1, 1, 0);
glPushMatrix();
glTranslated(cone1[0], cone1[1], cone1[2]);
glRotated(cone1[3], cone1[4], cone1[5], cone1[6]);
glutSolidCone(0.8, 2, 50, 50);
glPopMatrix();
glColor3d(1, 0, 1);
glPushMatrix();
glTranslated(cone2[0], cone2[1], cone2[2]);
glRotated(cone2[3], cone2[4], cone2[5], cone2[6]);
glutSolidCone(0.8, 2, 50, 50);
glPopMatrix();
glColor3d(0, 0, 1);
glPushMatrix();
glTranslated(cone3[0], cone3[1], cone3[2]);
glRotated(cone3[3], cone3[4], cone3[5], cone3[6]);
glutSolidCone(0.8, 2, 50, 50);
glPopMatrix();
/************************************************************/
/* Left cones */
glColor3d(1, 1.5, 0.6);
glPushMatrix();
glTranslated(cone4[0], cone4[1], cone4[2]);
glRotated(cone4[3], cone4[4], cone4[5], cone4[6]);
glutSolidCone(0.8, 2, 50, 50);
glPopMatrix();
glColor3d(1, 1.5, 0.6);
glPushMatrix();
glTranslated(cone5[0], cone5[1], cone5[2]);
glRotated(cone5[3], cone5[4], cone5[5], cone5[6]);
glutSolidCone(0.8, 2, 50, 50);
glPopMatrix();
glColor3d(1, 1.5, 0.6);
glPushMatrix();
glTranslated(cone6[0], cone6[1], cone6[2]);
glRotated(cone6[3], cone6[4], cone6[5], cone6[6]);
glutSolidCone(0.8, 2, 50, 50);
glPopMatrix();
/*******************************************************/
/* Right cones */
glColor3d(1, 1.5, 0.6);
glPushMatrix();
glTranslated(cone7[0], cone7[1], cone7[2]);
glRotated(cone7[3], cone7[4], cone7[5], cone7[6]);
glutSolidCone(0.8, 2, 50, 50);
glPopMatrix();
glColor3d(1, 1.5, 0.6);
glPushMatrix();
glTranslated(cone8[0], cone8[1], cone8[2]);
glRotated(cone8[3], cone8[4], cone8[5], cone8[6]);
glutSolidCone(0.8, 2, 50, 50);
glPopMatrix();
glColor3d(1, 1.5, 0.6);
glPushMatrix();
glTranslated(cone9[0], cone9[1], cone9[2]);
glRotated(cone9[3], cone9[4], cone9[5], cone9[6]);
glutSolidCone(0.8, 2, 50, 50);
glPopMatrix();
/****************************/
/* THE BALLING BALL */
glColor3d(1, 0, 0);
glPushMatrix();
glTranslated(ball[0], ball[1], ball[2]);
glutSolidSphere(ball[3], ball[4], ball[5]);
glPopMatrix();
/******* Floor ********/
//glPushMatrix();
glColor3d(0.4, 1, 0.20);
glBegin(GL_QUADS);
glVertex3f(21.0, -1.0, -25.0);
glVertex3f(-21.0, -1.0, -25.0);
glVertex3f(-20.0, -1.0, -4.0);
glVertex3f(20.0, -1.0, -4.0);
glEnd();
/** wall at the back **/
glColor3d(0, 1, 1);
glBegin(GL_QUADS);
glVertex3f(21.0, 10.0, -25.0);
glVertex3f(-21.0, 10.0, -25.0);
glVertex3f(-21.0, -1.0, -25.0);
glVertex3f(21.0, -1.0, -25.0);
glEnd();
/* // speed line
glColor3d(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glVertex3f(7.0, 7.0, -24.9999);
glVertex3f(7.5, 7.0, -24.9999);
glVertex3f(6.0, -4.0, -4.9999);
glVertex3f(6.0, -4.0, -4.9999);
glEnd();
Lines between three
glColor3d(0.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glVertex3f(-7.5, 7.0, -24.9999);
glVertex3f(-7.0, 7.0, -24.9999);
glVertex3f(-2.0, -4.0, -4.9999);
glVertex3f(-1.5, -4.0, -4.9999);
glEnd();
Speed line
glLineWidth(8.0f);
glColor3d(1.0f, 0.0f, 0.0f);
glBegin(GL_LINE_STRIP);
%age from the range of speed by the current speed
speedLine = (100 / (ballMaxSpeed - ballMinSpeed)) * ballSpeed;
speedLine = (3.0 / 100) * speedLine;
glVertex3f(6.0, speedLine, -5.0);
glVertex3f(6.0, 0.0, -4.999);
glEnd();
*/
//glPopMatrix();
glutSwapBuffers();
}
/* Program entry point */
int main(int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitWindowSize(windowWidth, windowHeight); // Initial window width and height
glutInitWindowPosition(windowPosX, windowPosY); // Initial window top-left corner (x, y)
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Balling Game 3d");
glutDisplayFunc(display);
glutTimerFunc(0, Timer, 0); // First timer call immediately
glutSpecialFunc(specialKeys); // Register callback handler for special-key event
glutKeyboardFunc(keyboard); // Register callback handler for special-key event
glutMainLoop();
return 1;
}