Please could you explain the following code in detail as i am so baffled and i do not know what this code exactly does. This is a game that basically draws multiple 3d objects i don't understand how and where the drawings were achieved so could you please explain thank you in advance
here is the code:
Code:
#ifndef _GAME_OBJECTS_H_
#define _GAME_OBJECTS_H_
class GameObjects
{
public:
GameObjects();
virtual void Update()=0;
virtual void Draw()=0;
const float* GetPos();
void SetPos(float x, float y, float z );
bool m_deleteMe;
protected:
float m_pos[3];
};
#endif
This is a cpp file that i think it is also linked to the drawing of the 3d object
Code:
GameObjects::GameObjects()
{
m_deleteMe = false;
m_pos[0] = m_pos[1] = m_pos[2] = 0.0f;
}
const float* GameObjects::GetPos(){
return m_pos;
}
void GameObject::SetPos(float x, float y, float z ){
m_pos[0] = x;
m_pos[1] = y;
m_pos[2] = z;
}
This is the 1st 3d object that I do not understand how it was drawn
Code:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "glut.h"
#include "Object.h"
Object::Object()
{
m_pos[2] = -2.8;
}
void Object::Update(){
}
void Object::Draw(){
float color[] = {0.2,1.0,0.2,1.0};
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
glPushMatrix();
glTranslatef(m_pos[0],m_pos[1],m_pos[2]);
glPushMatrix();
glutSolidCone(0.4,0.4f,12,12);
glPopMatrix();
for(int i=0; i<4; i++){
glPushMatrix();
glTranslatef(0,0,-0.15*(i+1));
glutSolidCone(0.3f,0.4f,12,12);
glPopMatrix();
}
glPushMatrix();
glTranslatef(0,0,-0.15*5);
glutSolidCone(0.5f,0.4f,12,12);
glPopMatrix();
glPopMatrix();
}
Please help guys