declaring a 2d array...seems impossible.
I'm trying to simply declare a 2d array. It has 3 columns, 14 rows.
//3x14 array. 3 columns, 14 rows
GLfloat trans[14][3];
//translations for neck
trans[0][0]= {0.0f};
trans[0][1]= {10.0f};
trans[0][2]= {0.0f};
I always receive the error message:
"error C2466: cannot allocate an array of constant size 0" at line "trans[0][0]= {0.0f};" And on down...what am I doing wrong?
dont use the { };
//3x14 array. 3 columns, 14 rows
GLfloat trans[14][3];
//translations for neck
trans[0][0]= 0.0f;
trans[0][1]= 10.0f;
trans[0][2]= 0.0f;
//3x14 array. 3 columns, 14 rows
GLfloat trans[14][3];
//translations for neck
trans[0][0]= 0.0f;
trans[0][1]= 10.0f;
trans[0][2]= 0.0f;
GLfloat trans[14][3];
//translations for neck
trans[0][0]= 0.0f;
trans[0][1]= 10.0f;
trans[0][2]= 0.0f;
tried it, same error.
//translations for neck
trans[0][0]= 0.0f;
trans[0][1]= 10.0f;
trans[0][2]= 0.0f;
tried it, same error.
Well here's an interesting update. It compiles...just not on my computer...I'm using a windows xp pc. It has Opengl and GLUT on it...as far as I know (it's a lab pc). Would anyone know why i'm receiving this error?
Post more code, the error's context is elsewhere. What compiler is this?
One thing that it could be is that that snippet of code might not be inside a function. Every line there except "GLfloat trans[14][3];" (which is declaration) is an executable expression. These must be inside functions, they can't just be floating around at global scope.
If you want to initialize your array, you need to do something like:
One thing that it could be is that that snippet of code might not be inside a function. Every line there except "GLfloat trans[14][3];" (which is declaration) is an executable expression. These must be inside functions, they can't just be floating around at global scope.
If you want to initialize your array, you need to do something like:
GLfloat trans[14][3] ={ { a, b, c, ... }, { a, b, c, ... }, ...}
The compiler i'm using is Visual C++ 2008 express edition. Here is the entire program:
#include <stdlib.h>
#include <GL/glut.h>
//this program creates a 3d figure, who is able to be manipulated via mouse
//(yet to be finished). The 3 x 14 array is supposed to hold the variables for //all of the rotating areas of the figure
//3x14 array. 3 columns, 14 rows
GLfloat translate[14][3];
//translations for neck
translate[0] = {0.0f, 10.0f, 0.0f};
//translations for leg L
translate[1][0]= 3.0;
translate[1][1]= -5.0;
translate[1][2]= 0.0;
//translations for Leg R
translate[2][0]= -3.0;
translate[2][1]= -5.0;
translate[2][2]= 0.0;
//translations for Arm ball L
translate[3][0]= 4.0;
translate[3][1]= 4.0;
translate[3][2]= 0.0;
//translations for Arm ball R
translate[4][0]= -4.0;
translate[4][1]= 4.0;
translate[4][2]= 0.0;
//translations for Elbow ball L
translate[5][0]= -12.0;
translate[5][1]= -3.0;
translate[5][2]= 0.0;
//translations for Elbow ball R
translate[6][0]= 12.0;
translate[6][1]= -3.0;
translate[6][2]= 0.0;
//translations for Knee ball R
translate[7][0]= 6.0;
translate[7][1]= -15.0;
translate[7][2]= 0.0;
//translations for Ankle ball R
translate[8][0]= 7.0;
translate[8][1]= -20.0;
translate[8][2]= 0.0;
//translations for Knee ball L
translate[9][0]= -6.0;
translate[9][1]= -15.0;
translate[9][2]= 0.0;
//translations for Ankle ball L
translate[10][0]= -6.0;
translate[10][1]= -20.0;
translate[10][2]= 0.0;
//translations for body(torso)
translate[11][0]= 0.0;
translate[11][1]= 0.0;
translate[11][2]= 0.0;
//translations for wrist L
//translate[12][0]
//translate[12][1]
//translate[12][2]
//translations for wrist R
//translate[13][0]
//translate[13][1]
//translate[13][2]
void display()
{
/* display callback, clear frame buffer and z buffer,
rotate cube and draw, swap buffers */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluOrtho2D(0.0, 50.0, 0.0, 50.0);
glMatrixMode(GL_MODELVIEW);
//neck
glPushMatrix();
glTranslatef(translate[0][0],translate[0][1],translate[0][2]);
gluSphere(gluNewQuadric(),5,head_radius,20);
glPopMatrix();
//body
glPushMatrix();
glTranslatef(translate[11][0],translate[11][1],translate[11][2]);
gluCylinder(gluNewQuadric(),2,5,5,10,10);
glPopMatrix();
glPushMatrix();
//Leg L
glTranslatef(translate[1][0],translate[1][1],translate[1][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Left Leg
glPushMatrix();
//rotates leg along the z axis
glRotatef(15.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,10.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//leg R
glTranslatef(translate[2][0],translate[2][1],translate[2][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Right Leg
glPushMatrix();
//rotates leg along the z axis
glRotatef(-15.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,10.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Arm ball L
glTranslatef(translate[3][0],translate[3][1],translate[3][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Left Arm
glPushMatrix();
//rotates arm along the z axis
glRotatef(-130.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(-90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,10.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Arm ball R
glTranslatef(translate[4][0],translate[4][1],translate[4][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Right Arm
glPushMatrix();
//rotates arm along the z axis
glRotatef(130.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(-90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,10.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Elbow ball L
glTranslatef(translate[5][0],translate[5][1],translate[5][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Leftt Elbow to hand
glPushMatrix();
//rotates hand along the z axis
glRotatef(70.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(-90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,5.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Elbow ball R
glTranslatef(translate[6][0],translate[6][1],translate[6][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Right Elbow to hand
glPushMatrix();
//rotates hand along the z axis
glRotatef(90.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,5.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Knee ball R
glTranslatef(translate[7][0],translate[7][1],translate[7][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Right Knee to Ankle
glPushMatrix();
//rotates Knee/Foot along the z axis
glRotatef(10.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,5.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Ankle ball R
glTranslatef(translate[8][0],translate[8][1],translate[8][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Right Ankle to Foot
glPushMatrix();
//rotates Knee/Foot along the z axis
glRotatef(45.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,5.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Knee ball L
glTranslatef(translate[9][0],translate[9][0],translate[9][0]);
gluSphere(gluNewQuadric(),1,40,20);
//Left Ankle to Foot
glPushMatrix();
//rotates Knee/Foot along the z axis
glRotatef(-5.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,5.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Ankle ball L
glTranslatef(translate[10][0],translate[10][1],translate[10][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Left Ankle to Foot
glPushMatrix();
//rotates Knee/Foot along the z axis
glRotatef(-40.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,5.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Wrist L
glTranslatef(translate[12][0],translate[12][1],translate[12][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Left Ankle to Foot
glPushMatrix();
//rotates Wrist along the z axis
glRotatef();
//rotates along x axis
glRotatef();
gluCylinder(gluNewQuadric(),.5f,.5f,5.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Wrist R
glTranslatef(translate[13][0],translate[13][1],translate[13][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Left Ankle to Foot
glPushMatrix();
//rotates Wrist along the z axis
glRotatef();
//rotates along x axis
glRotatef();
gluCylinder(gluNewQuadric(),.5f,.5f,5.0f,32,32);
glPopMatrix();
glPopMatrix();
glFlush();
glutSwapBuffers();
}
//float [] [] translations;
//check what was clicked on. and compare it to where it is moved to.
//void mymouse(int btn, int state, int x, int y){
// old_mouse_coords = (x,y)
// mousepos[0] = x;
// mousepos[1] = y;
// if((mousepos[0] < (translate [0][0] + head_raid) && (translate[0][0]> translate[[0][0] - head_raid) &&
// (translate[0][1] < translate[0][1] + head_raid) && (translate[0][1] > translate[0][1] - head_raid)
// ))
//}}
void myReshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w,
2.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0);
else
glOrtho(-2.0 * (GLfloat) w / (GLfloat) h,
2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
/* need both double buffering and z buffer */
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow("Project 2 - Figure Man");
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
//glutMouseFunc(mouseclick);
glEnable(GL_DEPTH_TEST); /* Enable hidden-surface removal */
glutMainLoop();
}
#include <stdlib.h>
#include <GL/glut.h>
//this program creates a 3d figure, who is able to be manipulated via mouse
//(yet to be finished). The 3 x 14 array is supposed to hold the variables for //all of the rotating areas of the figure
//3x14 array. 3 columns, 14 rows
GLfloat translate[14][3];
//translations for neck
translate[0] = {0.0f, 10.0f, 0.0f};
//translations for leg L
translate[1][0]= 3.0;
translate[1][1]= -5.0;
translate[1][2]= 0.0;
//translations for Leg R
translate[2][0]= -3.0;
translate[2][1]= -5.0;
translate[2][2]= 0.0;
//translations for Arm ball L
translate[3][0]= 4.0;
translate[3][1]= 4.0;
translate[3][2]= 0.0;
//translations for Arm ball R
translate[4][0]= -4.0;
translate[4][1]= 4.0;
translate[4][2]= 0.0;
//translations for Elbow ball L
translate[5][0]= -12.0;
translate[5][1]= -3.0;
translate[5][2]= 0.0;
//translations for Elbow ball R
translate[6][0]= 12.0;
translate[6][1]= -3.0;
translate[6][2]= 0.0;
//translations for Knee ball R
translate[7][0]= 6.0;
translate[7][1]= -15.0;
translate[7][2]= 0.0;
//translations for Ankle ball R
translate[8][0]= 7.0;
translate[8][1]= -20.0;
translate[8][2]= 0.0;
//translations for Knee ball L
translate[9][0]= -6.0;
translate[9][1]= -15.0;
translate[9][2]= 0.0;
//translations for Ankle ball L
translate[10][0]= -6.0;
translate[10][1]= -20.0;
translate[10][2]= 0.0;
//translations for body(torso)
translate[11][0]= 0.0;
translate[11][1]= 0.0;
translate[11][2]= 0.0;
//translations for wrist L
//translate[12][0]
//translate[12][1]
//translate[12][2]
//translations for wrist R
//translate[13][0]
//translate[13][1]
//translate[13][2]
void display()
{
/* display callback, clear frame buffer and z buffer,
rotate cube and draw, swap buffers */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluOrtho2D(0.0, 50.0, 0.0, 50.0);
glMatrixMode(GL_MODELVIEW);
//neck
glPushMatrix();
glTranslatef(translate[0][0],translate[0][1],translate[0][2]);
gluSphere(gluNewQuadric(),5,head_radius,20);
glPopMatrix();
//body
glPushMatrix();
glTranslatef(translate[11][0],translate[11][1],translate[11][2]);
gluCylinder(gluNewQuadric(),2,5,5,10,10);
glPopMatrix();
glPushMatrix();
//Leg L
glTranslatef(translate[1][0],translate[1][1],translate[1][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Left Leg
glPushMatrix();
//rotates leg along the z axis
glRotatef(15.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,10.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//leg R
glTranslatef(translate[2][0],translate[2][1],translate[2][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Right Leg
glPushMatrix();
//rotates leg along the z axis
glRotatef(-15.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,10.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Arm ball L
glTranslatef(translate[3][0],translate[3][1],translate[3][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Left Arm
glPushMatrix();
//rotates arm along the z axis
glRotatef(-130.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(-90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,10.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Arm ball R
glTranslatef(translate[4][0],translate[4][1],translate[4][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Right Arm
glPushMatrix();
//rotates arm along the z axis
glRotatef(130.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(-90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,10.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Elbow ball L
glTranslatef(translate[5][0],translate[5][1],translate[5][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Leftt Elbow to hand
glPushMatrix();
//rotates hand along the z axis
glRotatef(70.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(-90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,5.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Elbow ball R
glTranslatef(translate[6][0],translate[6][1],translate[6][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Right Elbow to hand
glPushMatrix();
//rotates hand along the z axis
glRotatef(90.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,5.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Knee ball R
glTranslatef(translate[7][0],translate[7][1],translate[7][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Right Knee to Ankle
glPushMatrix();
//rotates Knee/Foot along the z axis
glRotatef(10.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,5.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Ankle ball R
glTranslatef(translate[8][0],translate[8][1],translate[8][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Right Ankle to Foot
glPushMatrix();
//rotates Knee/Foot along the z axis
glRotatef(45.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,5.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Knee ball L
glTranslatef(translate[9][0],translate[9][0],translate[9][0]);
gluSphere(gluNewQuadric(),1,40,20);
//Left Ankle to Foot
glPushMatrix();
//rotates Knee/Foot along the z axis
glRotatef(-5.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,5.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Ankle ball L
glTranslatef(translate[10][0],translate[10][1],translate[10][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Left Ankle to Foot
glPushMatrix();
//rotates Knee/Foot along the z axis
glRotatef(-40.0f,0.0f,0.0f,1.0f);
//rotates along x axis
glRotatef(90.0f,1.0f,0.0f,0.0f);
gluCylinder(gluNewQuadric(),.5f,.5f,5.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Wrist L
glTranslatef(translate[12][0],translate[12][1],translate[12][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Left Ankle to Foot
glPushMatrix();
//rotates Wrist along the z axis
glRotatef();
//rotates along x axis
glRotatef();
gluCylinder(gluNewQuadric(),.5f,.5f,5.0f,32,32);
glPopMatrix();
glPopMatrix();
glPushMatrix();
//Wrist R
glTranslatef(translate[13][0],translate[13][1],translate[13][2]);
gluSphere(gluNewQuadric(),1,40,20);
//Left Ankle to Foot
glPushMatrix();
//rotates Wrist along the z axis
glRotatef();
//rotates along x axis
glRotatef();
gluCylinder(gluNewQuadric(),.5f,.5f,5.0f,32,32);
glPopMatrix();
glPopMatrix();
glFlush();
glutSwapBuffers();
}
//float [] [] translations;
//check what was clicked on. and compare it to where it is moved to.
//void mymouse(int btn, int state, int x, int y){
// old_mouse_coords = (x,y)
// mousepos[0] = x;
// mousepos[1] = y;
// if((mousepos[0] < (translate [0][0] + head_raid) && (translate[0][0]> translate[[0][0] - head_raid) &&
// (translate[0][1] < translate[0][1] + head_raid) && (translate[0][1] > translate[0][1] - head_raid)
// ))
//}}
void myReshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w,
2.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0);
else
glOrtho(-2.0 * (GLfloat) w / (GLfloat) h,
2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
/* need both double buffering and z buffer */
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow("Project 2 - Figure Man");
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
//glutMouseFunc(mouseclick);
glEnable(GL_DEPTH_TEST); /* Enable hidden-surface removal */
glutMainLoop();
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement