Random Astroids same coords
I have a class astroid and when I create multiple objects each appears in the same location what am I doing wrong?
Code:
// astroid.cpp
// author: Troy Curless
// Sunday September 5, 2004
// Definition of Astroid class member functions
#include <GL/glut.h>
#include <cstdlib>
#include <time.h>
#include "astroid.h"
extern const int SCREENWIDTH;
extern const int SCREENHEIGHT;
Astroid::Astroid()
{
srand(time(0));
xcoord=rand()%SCREENWIDTH+1;
ycoord=rand()%SCREENHEIGHT+1;
velocity = .1*(2-rand()%4);
}
void Astroid::draw() const{
glColor3f(256.0, 0.0 , 0.0);
glRecti(xcoord, ycoord,xcoord+10,ycoord+10);
}
void Astroid::rotate(){}
void Astroid::transform(){
glTranslatef(velocity,velocity,0);
}
Astroid::~Astroid(){}
I create the objects storing them in a vector of gameobjects
for (int i = 1; i<10; i++)
gameObjects[i] = new Astroid();
Just Started learning opengl and I have a couple other issues. I haven't learned how to transform individual objects. For instance my Astroid.transform() function actualy translates all the gameobjects so I need to read a bit more in the redbook to figure this one out but if anyone wants to post a quick and dirty explanation super. I assume translate is moving the view camera and hence all the objects.