Thread: Random Astroids same coords

  1. #1
    Registered User
    Join Date
    Jul 2003

    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?
    // 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;
      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(){
    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.

  2. #2
    Registered User
    Join Date
    Aug 2003
    I dont know how much this helps but call srand only once in your program.

  3. #3
    Teenage Mutant Ninja Nerd MMD_Lynx's Avatar
    Join Date
    Aug 2004
    yes that should probably help a lil
    bool init_rand = false;
       if(init_rand == false)
          init_rand = true;
       //rest of the code
    P.S. Post #50
    Stupid people are useful. You can make them do all the mindless tasks you are too lazy to do yourself.

    Sphynx cats are just bald and wrinkly, like old people, and we don't reject them.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. random to int?
    By psyadam in forum C# Programming
    Replies: 7
    Last Post: 07-22-2008, 08:09 PM
  2. Lesson #3 - Math
    By oval in forum C# Programming
    Replies: 2
    Last Post: 04-27-2006, 08:16 AM
  3. Another brain block... Random Numbers
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 01-23-2005, 05:51 PM
  4. How do I restart a random number sequence.
    By jeffski in forum C Programming
    Replies: 6
    Last Post: 05-29-2003, 02:40 PM
  5. Best way to generate a random double?
    By The V. in forum C Programming
    Replies: 3
    Last Post: 10-16-2001, 04:11 PM