delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/26/10:47:50

From: "Tom Cook" <tcook AT nexus DOT edu DOT au>
Newsgroups: comp.os.msdos.djgpp
Subject: 3D Stuff in Allegro
Date: Fri, 26 Dec 1997 16:27:40 +0930
Organization: Nexus Information Service
Lines: 54
Message-ID: <67vlel$lk0@nexus.nexus.edu.au>
NNTP-Posting-Host: nexus.nexus.edu.au
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hey, if anybody could help me with this it would be much appreciated!

I'm using persp_project( fixed, fixed, fixed, fixed* fixed* ) from the
Allegro library to project 3D points onto the screen. This works fine, until
I try to project points which are behind the camera. Say if I use the
following code:

#include "allegro.h"
#include "iostream.h"

int main()
{
    allegro_init();
    set_gfx_mode( GFX_AUTODETECT, 800, 600, 800, 600 );

    fix x, y, z;    // A 3D point.
    fix sx, sy;    // The screen co-ordinates of that 3D point.

    x=2;
    y=3;    // Purely arbitary;
    z=-10;    // Behind the origin.

    persp_project( x, y, z, &sx, &sy );

    cout << "\nScreen x: " << sx << "\nScreen y: " << sy << "\n";

    exit( 0 );

}

I get the point  (128, 70 ) as the projection, which is wrong, as the point
is behind the camera and therefore not on the screen at all. The only
solution I can think of is to check the Z co-ordinate to see if the point is
behind the camera and not draw it if it is behind. This has its own
problems, though.

For instance, what if I had a line which ran between two points. To draw
this line, I get the projection of each point using persp_project(), and
then call line() to draw the line between these two projected points. this
causes problems, though, when one of the points is behind the camera and the
other is not. Now either I don't calculate one of the points and therefore
don't draw the line, or I calculate the other point to the wrong place using
persp_project(), and the line gets drawn wrong. Neither of these is really
satisfactory.

If anyone either knows a way to get around the problem of points behind the
camera, or knows/knows of a 3D line routine, it would be much appreciated if
you could let me know.

Thanks for reading

Tom Cook


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019