Hi i am mostly done with my assignment where u have to make a simple object viewer. one of the requirements require you to use multiple instantiation of objects from the same class which i do not know what to do about it. This is my code for main.cpp
#include <iostream>
#include "freeglut.h"
#include "main_class.h"
#include "cube.h"
#include "pyramid.h"
#include "cuboid.h"
using namespace std;
int speed;
void MyDisplay (void);
void init (void) {
glClearColor (0.0, 0.0, 0.0, 0.0); // set background colour to black
glEnable (GL_CULL_FACE);
glShadeModel (GL_FLAT);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (50.0, 1.45, 1.0, 1000.0);
glMatrixMode (GL_MODELVIEW);
gluLookAt (100.0, 100.0, 100.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}
void rescale (GLsizei w, GLsizei h) {
glViewport (0, 0, w, h);
}
void cube :: render (void)
{
glBegin (GL_QUADS);
//red
glColor3f (1.0, 0.0, 0.0);
glVertex3f (-10.0, 10.0, 10.0);
glVertex3f (-10.0, -10.0, 10.0);
glVertex3f (10.0, -10.0, 10.0);
glVertex3f (10.0, 10.0, 10.0);
//green
glColor3f (0.0, 1.0, 0.0);
glVertex3f (10.0, 10.0,10.0);
glVertex3f (10.0, -10.0, 10.0);
glVertex3f (10.0, -10.0, -10.0);
glVertex3f (10.0, 10.0, -10.0);
//blue
glColor3f (0.0, 0.0, 1.0);
glVertex3f (-10.0, 10.0, 10.0);
glVertex3f (10.0, 10.0, 10.0);
glVertex3f (10.0, 10.0, -10.0);
glVertex3f (-10.0, 10.0, -10.0);
//yellow
glColor3f (1.0, 1.0, 0.0);
glVertex3f (-10.0, 10.0, -10.0);
glVertex3f (10.0, 10.0, -10.0);
glVertex3f (10.0, -10.0, -10.0);
glVertex3f (-10.0, -10.0, -10.0);
glColor3f (0.0, 1.0, 1.0);
glVertex3f (-10.0, -10.0, -10.0);
glVertex3f (10.0, -10.0, -10.0);
glVertex3f (10.0, -10.0, 10.0);
glVertex3f (-10.0, -10.0, 10.0);
glColor3f (1.0, 0.0, 1.0);
glVertex3f (-10.0, 10.0, 10.0);
glVertex3f (-10.0, 10.0, -10.0);
glVertex3f (-10.0, -10.0, -10.0);
glVertex3f (-10.0, -10.0, 10.0);
glEnd ();
}
void cuboid::render(void)
{
glBegin (GL_QUADS);
//red
glColor3f (1.0, 0.0, 0.0);
glVertex3f (-10.0, 10.0, 20.0);
glVertex3f (-10.0, -10.0, 20.0);
glVertex3f (10.0, -10.0, 20.0);
glVertex3f (10.0, 10.0, 20.0);
//green
glColor3f (0.0, 1.0, 0.0);
glVertex3f (10.0, 10.0,20.0);
glVertex3f (10.0, -10.0, 20.0);
glVertex3f (10.0, -10.0, -10.0);
glVertex3f (10.0, 10.0, -10.0);
//blue
glColor3f (0.0, 0.0, 1.0);
glVertex3f (-10.0, 10.0, 20.0);
glVertex3f (10.0, 10.0, 20.0);
glVertex3f (10.0, 10.0, -10.0);
glVertex3f (-10.0, 10.0, -10.0);
//yellow
glColor3f (1.0, 1.0, 0.0);
glVertex3f (-10.0, 10.0, -10.0);
glVertex3f (10.0, 10.0, -10.0);
glVertex3f (10.0, -10.0, -10.0);
glVertex3f (-10.0, -10.0, -10.0);
//cyan
glColor3f (0.0, 1.0, 1.0);
glVertex3f (-10.0, -10.0, -10.0);
glVertex3f (10.0, -10.0, -10.0);
glVertex3f (10.0, -10.0, 20.0);
glVertex3f (-10.0, -10.0, 20.0);
//purple
glColor3f (1.0, 0.0, 1.0);
glVertex3f (-10.0, 10.0, 20.0);
glVertex3f (-10.0, 10.0, -10.0);
glVertex3f (-10.0, -10.0, -10.0);
glVertex3f (-10.0, -10.0, 20.0);
glEnd ();
}
void pyramid::render(void)
{
glBegin (GL_TRIANGLES);
//red triangle
glColor3f (1.0, 0.0, 0.0);
glVertex3f (5.0, 0.0, 0.0);
glVertex3f(15.0, 0.0, 0.0);
glVertex3f(10.0, 10.0, -5.0);
//green triangle
glColor3f(0.0, 1.0, 0.0);
glVertex3f(10.0, 10.0, -5.0);
glVertex3f (15.0, 0.0, 0.0);
glVertex3f(15.0, 0.0, -10.0);
//blue triangle
glColor3f(0.0, 0.0, 1.0);
glVertex3f(10.0, 10.0, -5.0);
glVertex3f(15.0, 0.0, -10.0);
glVertex3f(5.0, 0.0, -10.0);
//yellow triangle
glColor3f(1.0, 1.0, 0.0);
glVertex3f(10.0, 10.0, -5.0);
glVertex3f(5.0, 0.0, -10.0);
glVertex3f(5.0, 0.0, 0.0);
glEnd ();
glBegin(GL_QUADS);
//white square
glColor3f(1.0, 1.0, 1.0);
glVertex3f(5.0, 0.0, -10.0);
glVertex3f(15.0, 0.0, -10.0);
glVertex3f(15.0, 0.0, 0.0);
glVertex3f(5.0, 0.0, 0.0);
glEnd();
}
void simpleAxes (void) {
glBegin (GL_LINES);
glColor3f (1.0, 0.0, 0.0);
glVertex3f (-100.0, 0.0, 0.0);
glVertex3f (100.0, 0.0, 0.0);
glColor3f (0.0, 1.0, 0.0);
glVertex3f (0.0, -100.0, 0.0);
glVertex3f (0.0, 100.0, 0.0);
glColor3f (0.0, 0.0, 1.0);
glVertex3f (0.0, 0.0, -100.0);
glVertex3f (0.0, 0.0, 100.0);
glEnd ();
}
void MyDisplay (void) {
cube box;
pyramid tri;
cuboid rect;
shape *temp = p;
while(temp)
{
temp -> draw();
temp = temp -> getNext();
}
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
simpleAxes ();
//pyramid
glPushMatrix();
glRotatef(getRate(), 0, 1, 0);
glTranslatef(-10.0, 0.0, 5.0);
tri.render();
glPopMatrix();
//cube
glPushMatrix();
glTranslatef(30.0, 10.0, 0.0);
glRotatef(speed, 0, 1, 0);
box.render ();
speed ++;
glPopMatrix();
//cuboid
glPushMatrix();
glTranslatef(-40.0, 10.0, 0.0);
glRotatef(speed, 0, 1, 0);
rect.render();
speed++;
glPopMatrix();
glutSwapBuffers ();
glutPostRedisplay ();
}
int main (int argc, char * argv[]) {
shape shape;
cube *b1 = new cube();
cube *b2 = new cube();
pyramid *p1 = new pyramid();
cuboid *c1 = new cuboid();
b1->setPosition(10,0,0);
b1->setRate(1);
b2->setPosition(10,-10,0);
b2->setRate(3);
p = b1;
b1-> next = b2;
b2-> next = p1;
p1-> next = c1;
c1-> next = NULL;
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (800, 600);
glutInitWindowPosition (100, 100);
glutCreateWindow ("My First OpenGL Window");
glutDisplayFunc (MyDisplay);
glutReshapeFunc (rescale); // to be called when window size has changed
init ();
glutMainLoop ();
return 0;
}
This is my code for main_class.h
struct position
{
float x, y, z;
} ;
struct rotation
{
float a, x, y, z;
};
class shape
{
private:
position pos;
rotation orientation;
float rate;
public:
shape * next;
void draw (void);
void setNext(shape * n)
{
next = n;
};
shape* getNext(void)
{
return next;
};
void setPosition(float x ,float y ,float z)
{
pos.x = x;
pos.y = y;
pos.z = z;
}
void setRate(float r)
{
rate = r;
};
int getRate(void)
{
return setRate();
}
};
void shape::draw (void)
{
glPushMatrix();
glTranslatef (pos.x, pos.y, pos.z);
glRotatef(orientation.a, orientation.x, orientation.y, orientation.z);
void render(void);
glPopMatrix();
orientation.a += rate;
if (orientation.a >= 360)
{
orientation.a -= 360;
}
}
shape * p;
if i try to build this, the compiler gives me 2 errors saying
main_class.h(40) : error C2660: 'shape::setRate' : function does not take 0 arguments
main.cpp(188) : error C3861: 'getRate': identifier not found
Any help or tip would be greatly appreciated