void line3D(short x1, short y1, short z1, short x2, short y2, short z2)
{
short x,y;//final vars...
x = abs(640 * x1 / z1);//this is a formula i dug up to use
y = abs(640 * y1 / z1);//i added the abs...
_moveto(x,y); //sets the start point
x = 640 * x2 / z2;//end point
y = 640 * y2 / z2;//end point
_lineto(x,y); //draws the line/
}
I came, I saw, I got programmers block.
~V''lion
🔒 Locked
3d lines...
Advertisement
Original Post
Or taking a virtual 3d line, and rastreizing it to the screen...
This particualr function is giving me errors....
could ya''ll take a gander ?
FYI, i`m using QC to do work out this algorithim.
Dont mean to rain on your parade or anything, but heres the program. I dont have a camera, 3d vector or anything.
I simply have straight non-page-flipping code, horribly simple....
Heres my program in the entirty, with the unused function edited out.
I came, I saw, I got programmers block.
~V''lion
I simply have straight non-page-flipping code, horribly simple....
Heres my program in the entirty, with the unused function edited out.
#include
#include
void setup(){_setvideomode(_MAXRESMODE);}
void line3D(short x1, short y1, short z1, short x2, short y2, short z2)
{
short x,y;
//x = abs(640 * x1 / z1);
//y = abs(480 * y1 / z1);
x = ( x1 / z1 * 320 ) + 480/2;
y = ( y1 / z1 * 320) + 640/2;
_moveto(x,y);
x = 640 * x2 / z2;
y = 640 * y2 / z2;
_lineto(x,y);
}
void RETURN()
{
getch();
_setvideomode(_DEFAULTMODE);
}
void main()
{
int i;
setup();
for(i=1;i<=360;i++)
{
line3D(100,200,i,100,100,i);
}
RETURN();
}
I came, I saw, I got programmers block.
~V''lion
OK. I''ll explain what you should be doing.
To get perspective, multiply both x and y by d/z, where d is the distance of your eye (or camera) from the monitor. In your original code, this was 640, which was great, but it needed conversion to screen space. Looking at the new code, you''re using different algorithms for each end of the line! Point 1 is ok (with d=320), but point 2 is using the old code. Try writing a generic ''3D-point to 2D screen pixel'' function and calling it for both ends of the line; you can use:
(which I stole from your code above ;-) )
You''re almost there!
To get perspective, multiply both x and y by d/z, where d is the distance of your eye (or camera) from the monitor. In your original code, this was 640, which was great, but it needed conversion to screen space. Looking at the new code, you''re using different algorithms for each end of the line! Point 1 is ok (with d=320), but point 2 is using the old code. Try writing a generic ''3D-point to 2D screen pixel'' function and calling it for both ends of the line; you can use:
x = ( x1 / z1 * 320 ) + 480/2;
y = ( y1 / z1 * 320) + 640/2;
(which I stole from your code above ;-) )
You''re almost there!
Like this ?
I
Can you give me ideas ?
Also...
line3d(0,0,100,50,0,100);
That just gives me a pixel.
line3d(0,0,100,50,50,100);
This too simply outputs a pixel...
Why ?
void line3D(short x1, short y1, short z1, short x2, short y2, short z2)
{
short x,y;
x=(x1 / z1 * 640) + 640/2;
y=(y1 / z1 * 640) + 480/2;
_moveto(x,y);
x=(x2 / z2 * 640) + 640/2;
y=(y2 / z2 * 640) + 480/2;
_lineto(x,y);
}
I came, I saw, I got programmers block.
~V''lion
I
ve tried it and it works a TON better than my previous algorithims did, but Im not sure what are acceptable co-ords for the camera space.Can you give me ideas ?
Also...
line3d(0,0,100,50,0,100);
That just gives me a pixel.
line3d(0,0,100,50,50,100);
This too simply outputs a pixel...
Why ?
void line3D(short x1, short y1, short z1, short x2, short y2, short z2)
{
short x,y;
x=(x1 / z1 * 640) + 640/2;
y=(y1 / z1 * 640) + 480/2;
_moveto(x,y);
x=(x2 / z2 * 640) + 640/2;
y=(y2 / z2 * 640) + 480/2;
_lineto(x,y);
}
I came, I saw, I got programmers block.
~V''lion
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement