|
||
|
GP Mailing List
ATXGPSIG List
|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: 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.
*** not being very familiar with Allegro ( besides know that it was designed
to be used with gnu compliers ), I can give it a shot. I didn't notice any
intalization of a back buffer, so that kills my "you forgot to flip pages"
theroy.....
>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;
*** note these variables are never initalized to anything.....
>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();
*** does this call create a back buffer? If so, then you have to flip the
offscreen page on to the screen before displaying the next screen....
> 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?
> }
*** You can always get a random interger and divide it by another random
interger to get a random float ( be sure implement error check; div by 0 )
> 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);
*** Note: screenx and screeny have yet to be initalized.... I am assuming
that they are in a header somewhere....
> putpixel(screen, screenx, screeny, makecol(255, 255, 255));
> } // end for loop thru the stars..
> } // end while no keys pressed
> return 0;
>} // end main
*** You can look through what I have written in your source for possible
things you may have missed. I do however have a bit of a time finding the
purpose of this function:
void cam2scr(int x, int y, int z, int *a, int *b)
I am assuming that this projects a vector so that it may be displayed on the
screen. I think that it would be in better style if you changed it like so:
POINT cam2scr(POINT projectMe)
// note: I am unsure as to why you wish to point to 'a' and b', surely
passing by value would be in better style; That and I am not sure what
purpose they serve.
{
POINT returnPoint;
// project POINT
return returnPoint;
}
*** I dunno... could you send me the link, perhaps that will clear things
up.
Josiah
________________________________________________________________________
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
|
|