http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

3d help for an idiot... =o)



Hi guys, village idiot here.
I'm trying to learn 3d point plotting, and am trying to use this cam2scr() 
function I got from a tutorial one you guys posted a link to, to make a 3d 
starfield thingie like the screen saver that comes with windoze. Right now 
I'm having eye.* be fixed so I can get the program down before I give you 
the ability to pivot and move around. I tried making the stars[].x, 
stars[].y, and stars[].z, as well as screenx and screeny, as fixed, ints, 
and floats. Some gave me one of those memory leaks screens where it says 
"frame traceback bla bla bla", and in other tries it set the gfx mode and 
sat there with a blank screen 'til I pressed a key.

Here's the code. It's done using the allegro library, but even if you're not 
familiar with it, you can hopefully still figure out the basic gist of it 
and find what needs to be added/changed. Is this even close to working?
thx guyz. ~Stephan~

#include <stdio.h>
#include <allegro.h>

#define NUM_STARS 60

struct POINT{
  fixed x, y, z;
//  fixed screenx, screeny;
};

struct POINT stars[NUM_STARS];
struct POINT eye;
fixed screenx, screeny;
int i;

void cam2scr(int x, int y, int z, int *a, int *b){
  *a = eye.x + x * eye.z / (z + eye.z);
  *b = eye.y - y * eye.z / (z * eye.z);
} // end cam2scr() func

void init(){
  allegro_init();
  install_keyboard();
  set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);

  for(i=0;i<NUM_STARS;i++){
    stars[i].x = rand()%600; // <-- How do I make a rand()
    stars[i].y = rand()%400; // <-- number that's a fixed
    stars[i].z = rand()%400; // <-- or a float?
    }
  eye.x = 0.0;
  eye.y = 0.0;
  eye.z = 300.0;
} // end init() func

int main(){
  init();

  while(!keypressed()){
    vsync();
    clear(screen);
    for(i=0;i<NUM_STARS;i++){

      if(--(stars[i].z) < 0){
        stars[i].x = rand()%600;
        stars[i].y = rand()%400;
        stars[i].z = 400;
        } //end if

      cam2scr(stars[i].x, stars[i].y, stars[i].z, &screenx, &screeny);
      putpixel(screen, screenx, screeny, makecol(255, 255, 255));
      } // end for loop thru the stars..
    } // end while no keys pressed
  return 0;
} // end main

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once

To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html