Jump to content
  • Advertisement


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.

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
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 this post

Link to post
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)

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 this post

Link to post
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 360
c!(i) = COS(i * 3.14 / 180): s!(i) = SIN(i * 3.14 / 180)
FOR i = 1 TO 8: READ x(i): READ y(i): READ Z(i): NEXT

phi = 1: theta = 1
xcenter = 150: ycenter = 100: zcenter = 256

frmcount = 0
fps = 100

INPUT "Enter Frame Interval: ", delay
INPUT "Enter Initial Speed: ", speed

SCREEN 7, 0, 1, 0
TIME$ = "00:00:00"

press$ = INKEY$
IF speed < 1 THEN speed = 1
frmcount = frmcount + 1
Time = TIMER

FOR i = 1 TO 8

x2(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) + p
Z2(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)) + xcenter
y3(i) = 256 * (y2(i) / (Z2(i) + zcenter)) + ycenter

PSET (x3(i), y3(i)), 15

LINE (x3(1), y3(1))-(x3(3), y3(3)), 15
LINE (x3(1), y3(1))-(x3(4), y3(4)), 15
LINE (x3(1), y3(1))-(x3(5), y3(5)), 15

LINE (x3(2), y3(2))-(x3(3), y3(3)), 15
LINE (x3(2), y3(2))-(x3(4), y3(4)), 15
LINE (x3(2), y3(2))-(x3(6), y3(6)), 15

LINE (x3(7), y3(7))-(x3(6), y3(6)), 15
LINE (x3(7), y3(7))-(x3(3), y3(3)), 15
LINE (x3(7), y3(7))-(x3(5), y3(5)), 15

LINE (x3(8), y3(8))-(x3(5), y3(5)), 15
LINE (x3(8), y3(8))-(x3(4), y3(4)), 15
LINE (x3(8), y3(8))-(x3(6), y3(6)), 15

LINE (2, 2)-(318, 11), 10, B
LINE (4, 4)-((speed * 6) + 5, 9), 12, BF
PRINT " F = faster, S = slower, Esc = exit"
FOR s = 1 TO 20
PRINT "Frame Count:"; frmcount; " FPS:"; fps;

PCOPY 1, 0

phi = phi + speed: theta = theta + speed
IF phi > 360 THEN phi = phi - 360
IF theta > 360 THEN theta = theta - 360

fps = (frmcount / (Time + 1))

FOR i = 1 TO delay: NEXT
IF INKEY$ = "f" THEN speed = speed + .1
FOR i = 1 TO delay: NEXT
IF INKEY$ = "s" THEN speed = speed - 1
FOR i = 1 TO delay: NEXT
IF INKEY$ = "p" THEN speed = 1
FOR i = 1 TO delay: NEXT
LOOP UNTIL press$ = CHR$(27)

DATA 30,30,-30
DATA -30,-30,-30
DATA -30,30,-30
DATA 30,-30,-30

DATA 30,30,30
DATA -30,-30,30
DATA -30,30,30
DATA 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 this post

Link to post
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).

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!