QBasic 3-D Graphics

Go to TheBOB's Graphic Forum    Go to the QB Forum Index    

Brief program

by Nacho (no login)

Just for you to see a small 3d program. You can experiment with the "funcion", it gets pretty cool drawings
SCREEN 12:CLS:CLEAR
line (0,240)-(640,240),2
line (320,0)-(320,480),2
line (100,479)-(539,0),2
angulo1 = 45

escalareal=2
escala=320/escalareal
salto = 8
color1 = 15
COMIENZO:
angulo = angulo1*3.141593/180 rem radianes
for z1=320 to -320 step (-salto)
for x1=-320 to 320 step salto
x=x1/escala
z=z1/escala
x2 = (x1+salto)/escala
z2 = (z1+salto)/escala

rem esta debe ser la funcion prncipal, de -1 a 1
y = altura (x,z)
y2 = altura (x,z2)
y3 = altura (x2,z)
y4 = altura (x2,z2)
factorb=1 rem 2/3
a = (x*escala)-(z*escala)*cos(angulo)+320
b = 240-((y*escala)*factorb-(z*escala)*sin(angulo))
a2 = (x*escala)-(z2*escala)*cos(angulo)+320
b2 = 240-((y2*escala)*factorb-(z2*escala)*sin(angulo))
a3 = (x2*escala)-(z*escala)*cos(angulo)+320
b3 = 240-((y3*escala)*factorb-(z*escala)*sin(angulo))
a4 = (x2*escala)-(z2*escala)*cos(angulo)+320
b4 = 240-((y4*escala)*factorb-(z2*escala)*sin(angulo))
line (a,b)-(a3,b3),color1
line (a4,b4)-(a2,b2),color1
line (a3,b3)-(a4,b4),color1
line (a2,b2)-(a,b),color1
rem PAINT (a+1,b+1),3

next
next

delay = .1
t! = TIMER
WHILE TIMER - t! < delay! <br> WEND
angulo1=angulo1-1
CLS
GOTO COMIENZO

END

FUNCTION altura (ox,oz)
c = SQR(ABS(2-ox*ox-oz*oz))
rem c = cos(ox+oz)/4+sin(oz*ox)/2-LOG(ABS(ox))
altura = c
END FUNCTION

FUNCTION puntoa (oa)

END FUNCTION

Posted on Nov 8, 2009, 12:20 PM

Respond to this message   

Return to Index


* What does puntoa do? Punt? Cause it does nothing...

by (Login burger2227)
R

Posted on Nov 20, 2009, 3:51 PM

Respond to this message   

Return to Index


first steps in 3D images (Copied from Main Forum)

by Lizsftr (Login The-Universe)
Admin

http://cjoint.com/data/dox7Jxoq83.htm

code :

FOR l% = (PRINTY + hight%) TO (PRINTY + 0) STEP -1

' this is the trick to get the character along an angle, used later :
persp = (l% - (PRINTY + hight%)) * 1.5

FOR k% = PRINTX TO (PRINTX + array(index%) - 1)

' used here, and also the character must be shrinked therefore (persp / 4)

IF POINT(k%, l%) = 1 THEN PSET (k% - 3 + persp, l% + 3 - (persp / 4)), 1


NEXT k%
NEXT l%

Posted on Mar 12, 2009, 7:39 PM

Respond to this message   

Return to Index


Need help in math/QBasic.

by Ben (Login The-Universe)
Admin

Need help in math/QBasic.
by Ben (no login)

Well, I think that I should be making games in QBasic some time soon. I've been thinking about vector images, which lead me to thinking about bezzer curves (I'll post more about my experiments with bezeir curves later), and sense of space on flat space.

So I wanna make games that give a sense of space to the user. It's the modern playable games, but not that crap nerd type RPG games. Anyways, I'm thinking:

Things will rotate on a oval:

m is the multiplier

coordinates will be:

x = m * radius * cos angle
y = radius * sin angle

And I will have 2 vanishing points of perspective (TheBOB probably knows all about that stuff)

So my first step would be to figure out the space I'm working with.

NOTICE that there are TWO ovals in the program?

Step I:

******* start of program *******
SCREEN 9
FOR i = 0 TO 75
x = COS(i * .1) * 200 + 250
y = SIN(i * .1) * 50 + 100
PSET (x, y)
NEXT
LINE (50, 100)-(320, 350)
LINE (450, 100)-(320, 350)
FOR i = 0 TO 75
x = COS(i * .1) * 100 + 285
y = SIN(i * .1) * 25 + 224
PSET (x, y)
NEXT
PRINT "this is my 3d perspective lol"
SLEEP
******* end of program *******

Step II:

This is it.

Now I'm going to implement a loop and a few lines that will be related to this perspective.

******* Start of program *******
SCREEN 9, , 1, 0

DO
i = i + 1

a = i
x0 = COS(a * .1) * 80 + 250
y0 = SIN(a * .1) * 20 + 100
x = COS(a * .1) * 200 + 250
y = SIN(a * .1) * 50 + 100
x01 = COS(a * .1) * 100 + 285
y01 = SIN(a * .1) * 25 + 224
x03 = 80 / 200 * (COS(a * .1) * 100) + 285
y03 = 80 / 200 * (SIN(a * .1) * 25) + 224
a = i + 10
x1 = COS(a * .1) * 200 + 250
y1 = SIN(a * .1) * 50 + 100
x2 = COS(a * .1) * 80 + 250
y2 = SIN(a * .1) * 20 + 100
x02 = (COS(a * .1) * 100) + 285
y02 = (SIN(a * .1) * 25) + 224
x04 = 80 / 200 * (COS(a * .1) * 100) + 285
y04 = 80 / 200 * (SIN(a * .1) * 25) + 224

LINE (0, 0)-(640, 350), 0, BF

LINE (x0, y0)-(x2, y2)
LINE (x, y)-(x1, y1)
LINE (x, y)-(x0, y0)
LINE (x1, y1)-(x2, y2)
LINE (x01, y01)-(x02, y02)
LINE (x03, y03)-(x04, y04)
LINE (x01, y01)-(x03, y03)
LINE (x02, y02)-(x04, y04)
LINE (x, y)-(x01, y01)
LINE (x1, y1)-(x02, y02)
LINE (x2, y2)-(x04, y04)
LINE (x0, y0)-(x03, y03)

'LINE (x, y)-(320, 350), 8
'LINE (x1, y1)-(320, 350), 8
'LINE (x0, y0)-(320, 350), 8
'LINE (x2, y2)-(320, 350), 8

PCOPY 1, 0
WAIT &H3DA, 8, 8
WAIT &H3DA, 8
LOOP UNTIL INP(&H60) = 1

******* End of program *******

Now this looks like crap and I'm not sure how to get the math right. 3D tutorials are BS because they use really complex math and I can't understand it. Wikipedia uses really complex formulas and equations for really simple things. I asked my dad, he said 3D means 3rd integrals. I don't understand that. So I'm stuck here and I need some guidance.

Some of my ideas:

Remember when I said there are TWO ovals?

Well, I only need one oval in the whole program, and the lines will relate to the oval and the 2 vanishing points of perspective. But what happens is this:

the perspective will make a line. I need to find the other 2 sets of coordinates.

the greek formula says:

a^2+b^2=c^2
but only c is known, a and b are not known. I cannot use SIN and COS because I don't know the angle. One thing I could do is find the rational angle:

(350-y)/(320-x)

then make linear equations:

y = rational equation * x

then have a few of them and solve for intersection by making two sets of equations and solving them. But I can't seem to understand it

I will have to plan this on paper a little bit.

Anyways, I hope you will help me, and if you do: Thank you.

Ben

Posted on Mar 12, 2009, 7:09 PM

Respond to this message   

Return to Index


If I have time I'll look into this

by lkt153 (no login)

For now I can say, if you're serious about 3D, you'll need to learn a lot of Analytic Geometry. As for what your dad said, no, 3D does not mean 3rd integrals, 3D means 3 dimensions, period (no offense meant by this). You need analytic geometry to learn how to project 3d stuff on a 2d screen, how to decide whether things intersect, and how to draw them. Integrals could be used for some stuff I guess, but in games are mostly used for physics, and not much else.

"3D tutorials are BS because they use really complex math and I can't understand it. Wikipedia uses really complex formulas and equations for really simple things."

Representing a 3d world is not a very simple thing, as things can be rotated, scaled, translated, amongst other things. That "really complex math" you mention, isn't in fact all that complex, but as I've said before, you need to know AG. I suggest you grab a book on the subject, or on Computer Graphics to learn specially about how to define a coordinate space, and how to operate on it. It's not very complex once you get used to it, it simply comes down to multiplying matrices, if you do it right.

Interesting topics:
AG:
- Vectors and operations (normalizing, dot- and cross- product)
- How to convert from a space to another
CG:
- Homogeneous coordinate (z for 2d, w for 3d)
- Perspective

It's really late and I'm brain dead, if I have time (which I probably won't), I'll look into this on the weekend.

hth
lkt153

Posted on Mar 13, 2009, 12:42 AM

Respond to this message   

Return to Index


Forget vanishing points

by (Login Mikrondel)
R

Vanishing-point geometry is difficult and not very useful.

The usual approach is to define an "eye" and a "screen" a short distance in front of it, and trace lines from the eye to each point of interest, and find where each line crosses the screen.

So, you start with a set of (x,y,z) co-ordinates for a visible point, and have to determine (p, q) co-ordinates, where (p, q) are relative to the screen.

In some cases (e.g. games where you can turn around) the screen is at a funny angle compared to the "3D space". This makes the calculations difficult without matrix maths.


A good exercise is to clone the "starfield" screen saver. In this case you can line the screen up with the space (i.e. (x,y) and (p,q) co-ordinates are basically the same, and z goes "into" the screen) which makes the calculations quite easy.

I suggest you take the eye to be at (0, 0, 0) and the centre of the screen to be (0, 0). Draw a picture of this looking from above, and looking from the side, identify where x, y, z, p and q are on the diagrams, and try to find p and q in terms of x, y and z (this requires similar triangles).

Let me know if you need help.

Aleks

Posted on Mar 13, 2009, 3:20 PM

Respond to this message   

Return to Index


RE

by Ben (no login)

I think it would look much better with vanishing points. I'm not sure what you mean by x,y,z,p,q. But when you are doing 2 D you got two numbers that show direction.

Like:

line (0,0)-(x,y)

But in 3 D you would need another one which I assume you mean Z which should look like digging in to the monitor. It would be:

line (0,0,0)-(x,y,z)

But that can't be done so it is used something like maybe if you have a triangle X,Y,V: You would then draw the same triangle only exact opposite to the triangle of XYV, and the 3rd line Z would be going into the opposite corner of the triangle to show perspective. But then the length of Z going into the opposite angle would have to be divided by something to show how far away the eye is.


" I suggest you take the eye to be at (0, 0, 0) and the centre of the screen to be (0, 0). Draw a picture of this looking from above, and looking from the side, identify where x, y, z, p and q are on the diagrams, and try to find p and q in terms of x, y and z (this requires similar triangles). "

Well, I didn't understand any of that, but I tried this:

SCREEN 9, , 1, 0

a1 = 320
a2 = 50

b1 = 280
b2 = 100

c1 = 360
c2 = 100

d1 = 320
d2 = 150

z = 0

DO
LINE (0, 0)-(640, 350), 0, BF

LINE (a1, a2)-(b1, b2)
LINE (a1, a2)-(c1, c2)
LINE (c1, c2)-(d1, d2)
LINE (b1, b2)-(d1, d2)

LINE (a1, a2 + z)-(b1, b2 + z)
LINE (a1, a2 + z)-(c1, c2 + z)
LINE (c1, c2 + z)-(d1, d2 + z)
LINE (b1, b2 + z)-(d1, d2 + z)

LINE (a1, a2)-(a1, a2 + z)
LINE (b1, b2)-(b1, b2 + z)
LINE (d1, d2)-(d1, d2 + z)
LINE (c1, c2)-(c1, c2 + z)

a2 = a2 + 1
d2 = d2 - 1

i = i + 1
z = z + 1
'I tried something like this to have it rotate:
'z = SIN(i / 10) * 10 'But that didn't work sadly
'why? I don't know. It should be adding negative numbers
'when the sine is reaching the bottom.

IF i = 52 THEN EXIT DO

SLEEP 1
PCOPY 1, 0
WAIT &H3DA, 8, 8
WAIT &H3DA, 8
LOOP







Anyways, must I learn the analytic geometry if I just want to make simple programs that resemble something of 3d, but maybe not 100% accurate?

They don't teach any useful math at school and they aren't any time soon so I don't know where to start learning the things I would need to understand geometry. I tried learning the trigonmentry, I understand the functions and stuff, but I can't solve the tringomentric equations. And I don't what this type of stuff means:

sin^2 (x) <<????

Ben


P.S. I've been reading about the PHP and I think I understand the basic structure (I know for/while loops, if/else arrays variables etc) but I don't know any of the built in fucntions that do stuff. I also don;t understand things like:

$variable = new variabletype();

I say they are the same as types, but Galleon says they aren't the same as types so I'm confused. I also don;t know what this operator does: =>.

Anyways, where can I find the source code so I can learn this by example?

Posted on Mar 13, 2009, 5:58 PM

Respond to this message   

Return to Index


Briefly

by (Login Mikrondel)
R

because I need to go in a moment...

>>I think it would look much better with vanishing points.

The vanishing points would still be there. But they would be a result, rather than a method.

>>I'm not sure what you mean by x,y,z,p,q.

OK, let's say you have a point A in 3D space. Its co-ordinates in 3D space are (x, y, z). You want to find its "shadow" on the screen, whose co-ordinates on the screen are (p, q).

I suggest you make the bottom-left corner of the screen (-1, -1) and the top-right corner (1, 1). In 3D space, they are equivalent to (-1, -1, 1) and (1, 1, 1). The centre of the screen is (0, 0, 1).

>>Anyways, where can I find the source code so I can learn this by example?

I might post some later.



    
This message has been edited by Mikrondel on Mar 14, 2009 1:08 AM

Posted on Mar 13, 2009, 6:20 PM

Respond to this message   

Return to Index


In answer to your other questions

by (Login Mikrondel)
R

>>Anyways, must I learn the analytic geometry if I just want to make simple programs that resemble something of 3d, but maybe not 100% accurate?

No, you can write very simple programs without understanding the maths. But that's all you'll be able to do. If you learn a little more, you'll be able to go much further. And you'll be able to make more sense of the maths on Wikipedia.

>>They don't teach any useful math at school and they aren't any time soon so I don't know where to start learning

Don't forget that it's more important to a teacher that the dull students aren't left behind, than the bright students get ahead. Maybe you can find a teacher who is willing to explain something to you outside of class. Or maybe a parent or relative of yours could help.

At my school there was a maths society where we explored topics outside of the curriculum...

Having a good teacher is probably the best way to learn this sort of stuff, but failing that a good book might be helpful. Check your library for something that's at the right level for you.

>>And I don't what this type of stuff means:

>>sin^2 (x) <<????

Basically, computer programmers need to make sure the computer understands them. Mathematicians need to make sure that other mathematicians understand them. So while programming languages tend to be fairly simple and consistent, mathematical notation is much less so.

Also remember that mathematics until recently was nearly always written by hand, and even today much is written by hand. A notation that's easier to read in slightly messy writing is a winner.

There are many areas of mathematics where there are a few different notations in popular usage. Often say Europe will use one notation and the US will use another.

Anyway, this is one case where "everybody knows" that sin^2(x) means sin(x)*sin(x). Just learn it.

>>$variable = new variabletype();

This is to do with object oriented programming, a big topic that I don't think you should worry about just yet. PHP does not require you to use it.

Posted on Mar 14, 2009, 3:05 AM

Respond to this message   

Return to Index


Help!

by Ben (no login)

Well I decided to try a starfield. Wasn't exactly as easy as I expected.

(0,0) , since qbasic on 4th quadrant:

a=160
b=100

path of stars:

do
i = i +1
x = 160 cos i
y = 100 sin i

line (a,b) - (a-x, b+y)

loop

Now what? I'm stuck. I could find slope of each line and have the stars move through this but thats not a good way.

What I have so far:


SCREEN 7, , 1, 0

FOR i = 1 TO 15
j = j + 7
OUT &H3C8, i
OUT &H3C9, j
OUT &H3C9, j
OUT &H3C9, j
NEXT

' (a, b) = (0, 0) : Correct?
a = 160
b = 100

'x - cos and y + sin
DO
i = i + 1
IF i > 100 THEN i = 0
LINE (0, 0)-(320, 200), 0, BF


'x = COS(i) * 160
'y = SIN(i) * 100

c = i / 15

LINE (a - i, b - i)-(a - (i + (i / 18)), b - (i + (i / 18))), c
LINE (a + i, b - i)-(a + (i + (i / 18)), b - (i + (i / 18))), c
LINE (a - i, b + i)-(a - (i + (i / 18)), b + (i + (i / 18))), c
LINE (a + i, b + i)-(a + (i + (i / 18)), b + (i + (i / 18))), c
LINE (a + i, b)-(a + (i + (i / 18)), b), c
LINE (a - i, b)-(a - (i + (i / 18)), b), c
LINE (a, b + i)-(a, b + (i + (i / 18))), c
LINE (a, b - i)-(a, b - (i + (i / 18))), c
PCOPY 1, 0
WAIT &H3DA, 8, 8
WAIT &H3DA, 8
LOOP UNTIL INP(&H60) = 1

Posted on Mar 15, 2009, 6:36 PM

Respond to this message   

Return to Index


That's not what I suggested...

by (Login Mikrondel)
R

Forget paths, forget vanishing points. The solution to this problem does NOT require sin/cos.


This is the main task:
Given the location of a star (as x, y, and z co-ordinates), find where it should appear on the screen (as p, q co-ordinates). Don't worry about the movement of the stars (yet). Just make sure that wherever the star is at one moment, its location on the screen is correct.

There is a bit of difficult 3D visualisation involved. This program may help you:

SCREEN 12
LOCATE 14, 3: PRINT "Eye";
LOCATE 12, 9: PRINT "Screen";
LOCATE 10, 49: PRINT "Star";
LINE (30, 240)-STEP(400, 0), 4
CIRCLE (30, 240), 3
LINE (90, 200)-STEP(0, 80)

LINE (90, 229)-(400, 170), 2
LINE (400, 240)-(400, 170), 2

LINE (30, 240)-(90, 229), 9
LINE (90, 240)-(90, 229), 9


PSET (400, 169)
PSET (401, 170)
PSET (399, 170)
PSET (400, 171)

END

Think of it as a side-view of the situation (with no perspective). This means that the Y axis points upwards and the Z axis points to the right. The X axis points towards you.

You should be able to find lines in the diagram that have the lengths p, x, and z. You also know the distance from the eye to the screen, so you should be able to calculate p based on x and z, using similar triangles.

Repeat the process except treat the diagram as a top view this time.

See how you go.

Posted on Mar 15, 2009, 7:08 PM

Respond to this message   

Return to Index


Can't say that I understand what you mean:

by Ben (no login)



(x, y, z)

p/640 = x / ???

q/480 = y / ???

What you are trying to say? The star is in the "projection" but on screen is represented by similar traingle. How is Z related? Z is the multiplier that increases size of x,y from screen to projection?

Posted on Mar 15, 2009, 8:27 PM

Respond to this message   

Return to Index


Do you understand what the diagram is showing?

by (Login Mikrondel)
R

Add this to the program:

CIRCLE (90, 229), 3, 5

This is the point where the line between the eye and the star crosses the screen. Basically you need to find the co-ordinates of this point, after being told the co-ordinates of the star.

The diagram is a side-view of the situation. The red line is the Z axis. The Y axis points upwards from the Eye. The X axis cannot be seen, and any points that share the same X co-ordinate are "flattened" into one. For instance, the screen itself has been squashed; you can tell how high the purple point is on the screen, but not whether it is on the left or right side of the screen.

If the centre of the screen is (0, 0, 1) then the length of the vertical blue line is q! The distance along the red line from the eye to where the red line meets the green line is z. The length of the vertical green line is y.

See if that gets you anywhere.

Posted on Mar 15, 2009, 9:48 PM

Respond to this message   

Return to Index


RE

by Ben (no login)

I see the coordinates. x is left/right y is up down and z is forward backward. Now I see that if I have a square at (50,50,0) and another square at (50,50,20) they would should be exactly on the same spot on screen. But then they can't be on the same spot because this is 3d, so (p, q) (of z=20) will not be 50,50, but something else based on similar triangles and on Z.

Well, that is the way I see it, but I guess im wrong and can't understand it. Thanks for the help, but I'm going to try finding these laws of 3D myself, and hopefully I'll make it to what you were trying to tell me.

SCREEN 12
PRINT "this is where I'm going to start with"
PRINT "rotation"
LOCATE 20
PRINT "Red means on the projection and will be smaller on screen"
PRINT "white means is on the screen and will be bigger"
z = .3
FOR i = 0 TO 50
x1 = COS(i) * 50 * z
y1 = SIN(i) * 50

x2 = COS(i) * 50
y2 = SIN(i) * 50 * z

IF x1 > 0 THEN c1 = 12 ELSE c1 = 15
IF y1 < 0 THEN c2 = 12 ELSE c2 = 15

PSET (x1 + 100, y1 + 100), c1
PSET (x2 + 100, y2 + 100), c2
NEXT

COLOR 10

LOCATE 9, 15: PRINT " this is line z"
LINE (120, 80)-(80, 120), 10

Posted on Mar 16, 2009, 11:34 AM

Respond to this message   

Return to Index


Actually...

by (Login Mikrondel)
R

>>Thanks for the help, but I'm going to try finding these laws of 3D myself

Actually, I was trying to get you to find them yourself. I can give a much more detailed explanation, if you like, but I think it's better just to give it some time and let you find things for yourself.

>>Now I see that if I have a square at (50,50,0) and another square at (50,50,20) they should be exactly on the same spot on screen.

The diagram program I gave you DOES show things in a "flattened" view. This makes it easy to find the relations you need.

But the final starfield program should NOT be "flattened"; it should show things in perspective view.

Note that two stars that differ only in their Z co-ordinates WILL appear at different locations on the screen (at the two purple circles):

SCREEN 12
LOCATE 14, 3: PRINT "Eye";
LOCATE 12, 9: PRINT "Screen";
LOCATE 10, 24: PRINT "Star 1";
LOCATE 10, 49: PRINT "Star 2";
LINE (120, 170)-(430, 170), 8
LINE (30, 240)-STEP(400, 0), 4
CIRCLE (30, 240), 3
LINE (90, 200)-STEP(0, 80)
LINE (90, 229)-(400, 170), 2
LINE (400, 240)-(400, 170), 2
LINE (30, 240)-(90, 229), 9
LINE (90, 240)-(90, 229), 9
PSET (400, 169)
PSET (401, 170)
PSET (399, 170)
PSET (400, 171)
LINE (90, 215)-(200, 170), 2
LINE (200, 240)-(200, 170), 2
LINE (30, 240)-(90, 215), 9
LINE (90, 240)-(90, 215), 9
PSET (200, 169)
PSET (201, 170)
PSET (199, 170)
PSET (200, 171)
CIRCLE (90, 229), 3, 5
CIRCLE (90, 215), 3, 5

Posted on Mar 16, 2009, 3:46 PM

Respond to this message   

Return to Index


Correct?

by Ben (no login)

I get an error for some reason if remove the ON ERROR...

SCREEN 9, , 1, 0

x = 50
y = 50
'z = 100
'distance to monitor = 10
FOR z = 100 TO z = 1 STEP -1
ON ERROR GOTO bye
p = 10 * y / z
q = 10 * x / z
LINE (0, 0)-(640, 350), 0, BF
CIRCLE (p, q), 10, 10
PCOPY 1, 0
NEXT
bye:
END
RESUME

Posted on Mar 23, 2009, 1:19 PM

Respond to this message   

Return to Index


* RESUME WHAT? You already tried to END it.

by (Login burger2227)
R



    
This message has been edited by burger2227 on Mar 23, 2009 2:35 PM

Posted on Mar 23, 2009, 2:30 PM

Respond to this message   

Return to Index


Wait... sorry..

by Ben (no login)

I was a little tired when I wrote that, but I think I got it now,

SCREEN 9, , 1, 0


FOR i = 1 TO 50
x1 = 450
y1 = 450
z1 = i
x2 = 700
y2 = 450
z2 = i
x3 = 450
y3 = 450
z3 = i + 20
x4 = 700
y4 = 450
z4 = i + 20

p1 = 15 * x1 / z1
q1 = 15 * y1 / z1
p2 = 15 * x2 / z2
q2 = 15 * y2 / z2
p3 = 15 * x3 / z3
q3 = 15 * y3 / z3
p4 = 15 * x4 / z4
q4 = 15 * y4 / z4

LINE (0, 0)-(640, 350), 0, BF
LINE (p1, q1)-(p2, q2)
LINE (p3, q3)-(p4, q4)
LINE (p1, q1)-(p3, q3)
LINE (p4, q4)-(p2, q2)

PCOPY 1, 0
WAIT &H3DA, 8, 8
WAIT &H3DA, 8

t = TIMER
DO
LOOP UNTIL TIMER - t > .1
NEXT

Posted on Mar 23, 2009, 3:45 PM

Respond to this message   

Return to Index


*Good job!

by (Login Mikrondel)
R

Posted on Mar 23, 2009, 3:56 PM

Respond to this message   

Return to Index


* How far is the eye from the monitor?

by Ben (no login)

Posted on Mar 25, 2009, 1:33 PM

Respond to this message   

Return to Index


Just pick something that looks realistic

by (Login Mikrondel)
R

Remember that the width and height of the screen are important. Together they determine when something is out of view.

Posted on Mar 25, 2009, 2:46 PM

Respond to this message   

Return to Index


Getting a lot better!

by (Login Mikrondel)
R

The error is due to "z = 1" rather than "1" here:
FOR z = 100 TO z = 1 STEP -1

the "z = 1" is evaluated before the loop starts, at which time z is zero. So "z = 1" is false, and therefore zero.

Ok, now... the main problem with your program is that the Z axis passes through the top-left corner of the screen. If you want to achieve the Starfield effect, it needs to go right through the centre of the screen. But this is easy to do. Just shift p and q from the corner to the centre of the screen.

Eventually you'll want the stars to grow larger as they get closer, but for now I'd just use a white PSET for each star. Create a small array of random star co-ordinates (allow X and Y to be negative or positive; but make sure Z is positive) and draw them all at once. Then decrease their Z co-ordinates and draw them again.

Rather than LINE (0, 0)-(640, 350), 0, BF, I would suggest just painting each star black. But that's mainly a speed/consistency issue.

Hopefully that's all pretty easy. See how you go.

Posted on Mar 23, 2009, 3:51 PM

Respond to this message   

Return to Index


* How can you have 3D on a 2D monitor?

by (Login burger2227)
R

Posted on Mar 4, 2009, 11:55 AM

Respond to this message   

Return to Index


That's what this forum is for!

by (Login Mikrondel)
R

3D graphics is usually concerned with projecting a 3D scene onto a 2D screen.

The idea is much like taking a photograph: light from a 3D scene is funnelled onto a 2D surface. 3D programming essentially tries to do the same thing, mathematically. Usually thirty times a second for a changing scene!

There are many different techniques; some are fast but inaccurate, some are fast but limiting, some are fast but use lots of memory, some are slow but easy to code, some are slow but powerful... you can usually combine different techniques depending on what you need.

Posted on Mar 7, 2009, 4:37 PM

Respond to this message   

Return to Index


dot products. calc 101 bub!

by vector calculus (no login)

Posted on Mar 8, 2009, 10:14 AM

Respond to this message   

Return to Index


New 3-D Qbasic Forum opened.

by (Login The-Universe)
Admin

This forum was created to post code, post questions, and to provide solutions for 3-D graphics programming in QBasic, QUickBasic, and QB64.

Pete

Posted on Mar 1, 2009, 4:09 PM

Respond to this message   

Return to Index


*Thanks for opening this forum, I'll be posting here very soon!

by (no login)

Posted on Mar 2, 2009, 11:32 AM

Respond to this message   

Return to Index


* Great idea Pete! Hope it catches on.........

by (Login burger2227)
R

Posted on Mar 2, 2009, 12:41 PM

Respond to this message   

Return to Index