Public Group

#### Archived

This topic is now archived and is closed to further replies.

# Camera in First 3D Engine

This topic is 5816 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Witht the help of some good tutorials and information, I have created my first 3D Engine (in QBasic) driven completely by the software (okay, it's only wireframe right now and it's obviously a long way from being finished). While it's rendering things fine I just can't seem to make an effective camera (by saying I can't make an "effective" camera I mean when I try it totally screws things up). The engine basically works like this. There are three sets of coordinate variables created for each object: x, y, and Z; x2, y2, and Z2; and x3 and y3. x2, y2, and Z2 are used in equations to convert the 3D x, y, and Z coordinates into 2D coordinates which are stored in x3 and y3. Lines are drawn between the x3 and y3 coordinates to display the figure (all the x, y, and Z coordinates are arrays with an index equal to the number of points in the figure being draw... but that's not important, is it?). I could probably post some code later, but most of you probably dont' know or care about QBasic... oh well, I'll do it anyway! (I don't want to post it RIGHT NOW because I still haven't broken down all the code into good functions and subs) Any ideas? Thanks! [edited by - Jackysan on August 15, 2002 9:48:21 PM]

##### Share on other sites
Whoa... a 3D engine in QBasic... why would you torture yourself so?

But anyway, I assume that you just have a fixed camera location. If you want to move the camera, can''t you just translate the whole world in the opposite direction?

##### Share on other sites
My first 3D wireframe engine was in QBASIC so i''ll help you. First there are two ways of doing 3D. The first is X=X/Z,Y=Y/Z. The problem with this A)objects look wierd B)division by zero errors. The second method is the one I used it goes X=X+Z,Y=Y+Z and usually dosn''t cause errors.

I don''t know how to do rotation but I do know translation(moving the camera).

''TZ is for z translation(X and Y could be applied the same way)
X=X+Z
X=X/TZ
X2=X2+Z2
X2=X2/TZ
Y=Y+Z
Y=Y/TZ
Y2=Y2+Z2
Y2=Y2/TZ

Check out DirectQB or the Future Library if you want to draw filled or textured triangles!

Also for a school project i did a web site about qbasic. It can be found at www.geocities.com/qbking13. Chapter 14 covers 3D programming.

##### Share on other sites
Your thought on X = (X / Z) vs X = (X + Z) is interesting, however, using some advanced equations and sin/cos tables (of which I take NO credit for) I am able to create 3D rotations in my engine.

I''m not at home right now, but I can post an early version to show you the working of the engine (The one I''m working on now is more compact, is broken into functions and subs, and can handle multiple objects defined by the TYPE statement). This little demo will draw a rotating cube and give you a few options. I take very little credit for this stage in my engine, it''s mostly a cut and paste job. The engine I''m working on is another story though :-)!

Just as a note, the FPS meter takes forever to count up so it is only approx. Also, enter a frame delay of 10000 at first, THEN experiment.

  DIM c!(360), s!(360)DIM x(8), y(8), Z(8), x2(8), y2(8), Z2(8), x3(8), y3(8)FOR i = 1 TO 360c!(i) = COS(i * 3.14 / 180): s!(i) = SIN(i * 3.14 / 180)NEXTFOR i = 1 TO 8: READ x(i): READ y(i): READ Z(i): NEXTphi = 1: theta = 1xcenter = 150: ycenter = 100: zcenter = 256frmcount = 0fps = 100SCREEN 7PRINT "QD, 3D ENGINE - CUBE DEMO"PRINTINPUT "Enter Frame Interval: ", delayINPUT "Enter Initial Speed: ", speedSCREEN 7, 0, 1, 0TIME$= "00:00:00"DOpress$ = INKEY$IF speed < 1 THEN speed = 1frmcount = frmcount + 1Time = TIMERCLSFOR i = 1 TO 8x2(i) = -x(i) * s!(theta) + y(i) * c!(theta)y2(i) = -x(i) * c!(theta) * s!(phi) - y(i) * s!(theta) * s!(phi) - Z(i) * c!(phi) + pZ2(i) = -x(i) * c!(theta) * c!(phi) - y(i) * s!(theta) * c!(phi) + Z(i) * s!(phi)x3(i) = 256 * (x2(i) / (Z2(i) + zcenter)) + xcentery3(i) = 256 * (y2(i) / (Z2(i) + zcenter)) + ycenterPSET (x3(i), y3(i)), 15NEXTLINE (x3(1), y3(1))-(x3(3), y3(3)), 15LINE (x3(1), y3(1))-(x3(4), y3(4)), 15LINE (x3(1), y3(1))-(x3(5), y3(5)), 15LINE (x3(2), y3(2))-(x3(3), y3(3)), 15LINE (x3(2), y3(2))-(x3(4), y3(4)), 15LINE (x3(2), y3(2))-(x3(6), y3(6)), 15LINE (x3(7), y3(7))-(x3(6), y3(6)), 15LINE (x3(7), y3(7))-(x3(3), y3(3)), 15LINE (x3(7), y3(7))-(x3(5), y3(5)), 15LINE (x3(8), y3(8))-(x3(5), y3(5)), 15LINE (x3(8), y3(8))-(x3(4), y3(4)), 15LINE (x3(8), y3(8))-(x3(6), y3(6)), 15LINE (2, 2)-(318, 11), 10, BLINE (4, 4)-((speed * 6) + 5, 9), 12, BFPRINTPRINTPRINT " F = faster, S = slower, Esc = exit"FOR s = 1 TO 20PRINTNEXTPRINT "Frame Count:"; frmcount; " FPS:"; fps;PCOPY 1, 0phi = phi + speed: theta = theta + speedIF phi > 360 THEN phi = phi - 360IF theta > 360 THEN theta = theta - 360fps = (frmcount / (Time + 1))FOR i = 1 TO delay: NEXTIF INKEY$ = "f" THEN speed = speed + .1FOR i = 1 TO delay: NEXTIF INKEY$= "s" THEN speed = speed - 1FOR i = 1 TO delay: NEXTIF INKEY$ = "p" THEN speed = 1FOR i = 1 TO delay: NEXTLOOP UNTIL press$= CHR$(27)DATA 30,30,-30DATA -30,-30,-30DATA -30,30,-30DATA 30,-30,-30DATA 30,30,30DATA -30,-30,30DATA -30,30,30DATA 30,-30,30

P.S. I already tried changing the x, y and zcenter variables, but it creates a loss of perspective. I''m only going to use it as a last resort

##### Share on other sites
I got rotation in a few programs too, but it was just cut and paste and I did not understand it so I took it out.

Did you check out the Future Library.

1. Go to www.qb45.com
2. Find the QB section
3. go to libraries
4. find fl35.zip(the file size is messed up)

Drawing textured triangles is much better then wireframe!

I don''t use QB anymore and Im not a newbie. I now c++ and opengl and I would recommend that you give it a try. glRotatef() is much easier then all that sin/cos crap. QBASIC is old and ugly and no one should bother useing it any more. Go see Cone3D''s and NeHe''s site(Dev-C++ is the best).

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 23
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631766
• Total Posts
3002235
×