 Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki Blog Search Turing Chat Room Members
[Tutorial] 3D graphics        Author Message
BenLi  Posted: Thu Jan 25, 2007 12:43 pm   Post subject: RE:[Tutorial] 3D graphics

can somone expand upon this tutorial? I understand the ball thingie, but applying it into any sort of real situation would be harder. Zylum, why don't you explain your entry for the "20 lines" contest?    CodeMonkey2000 Posted: Wed Jul 18, 2007 6:01 pm   Post subject: RE:[Tutorial] 3D graphics

I don't get it. Why does the x and y values change as you move along the z axis? Why does the z value affect the position of the ball? It should only affect the size (in my mind anyway).
 code: Mouse.ButtonChoose ("multibutton") const BALL_SIZE := 20 var x, y : int := 100 var z : real := 10 var temp_zvel : real := 0 % velocity of the ball function size2D (size, z : real) : int     if z <= 0 then         result round (size)     end if     result round (size / z) end size2D proc drawBall (x : real, y : real, z : real)     var size : int := size2D (BALL_SIZE, z)     Draw.FillOval (round (x), round (y), size, size, black) end drawBall var button : int := 0 loop     Mouse.Where (x, y, button)     if button = 1 then         temp_zvel += 0.03     elsif button = 100 then         temp_zvel += -0.03     else         temp_zvel := 0     end if     z += temp_zvel     drawBall (x, y, z)     delay (50)     cls end loop

Is this considered 3D? HellblazerX  Posted: Thu Jul 19, 2007 10:35 am   Post subject: RE:[Tutorial] 3D graphics

CodeMonkey, you're right in that the z-value doesn't affect the position of the ball. What it does affect is the size of the ball, as well as the size of the space between the z-axis and the ball. As the ball gets smaller, so does that space, and the ball appears to be moving closer to the z-axis, when in reality it isn't. CodeMonkey2000 Posted: Thu Jul 19, 2007 2:47 pm   Post subject: RE:[Tutorial] 3D graphics

Why does the space between the z-axis and the ball also appear to be getting bigger/smaller? zylum  Posted: Thu Jul 19, 2007 3:06 pm   Post subject: RE:[Tutorial] 3D graphics

perspective Gooie Posted: Thu Jan 03, 2008 1:02 am   Post subject: Re: [Tutorial] 3D graphics

Ok, so far this tutorial hasn't helped at all, actually it's really confusing. I think It needs a serious revamp. I'll try to write some of it, but anyone feel free to toss in any knowledge.

I am just starting with 3D. So I only know a few of the subjects listed below. I've seen some 3D engines on CompSci, and I think that It would be great if some of those people could give up there secrets.

So here are some areas needed to be covered. All of them together give the illusion of depth.
-relative size. Objects further away appear smaller.
-relative speed. Objects further away appear to move slower.
-z-axis blocking. Objects nearer appear in front of objects further away.
-haze. Objects further away are obscured by particles in the air.
-perspective. The apparent dimensions of an object taper as they get further away. Relative size and speed are also a result of perspective.
-light reflection/shading. The way light reflects from an object indicates its three-dimensional shape, and its position in relation to the light source.

I got this list from a website that explains 3D in great detail, for Shockwave. Translations could really help. http://www.jmckell.com/ andrew. Posted: Thu Jun 26, 2008 6:13 pm   Post subject: RE:[Tutorial] 3D graphics

Don't know if I can do this, but I have created my own "3D thingy". It's basically a basketball and it drops to the ground. I read this, but it wasn't much help, so I just kind of made it up. Also, it may be my computer, but the end product of Windsurfer's tutorial doesn't do much. I think mine is much better, if I don't say so myself.

 Turing: setscreen ("graphics:800,600,nobuttonbar,offscreenonly") const gravity := 3 var ballmass : int := 150 var ballx, bally, ballz : int var direction : int := 1 var chars : array char of boolean ballx := maxx div 2 bally := maxy div 2 ballz := 50 loop     Input.KeyDown (chars)     cls     % Checking if the ball hit the ground     if not ballmass = 0 then         % If the ball didn't hit the ground, then make it drop         ballz := ballz - (gravity * direction)         % If the ball is at the ground then reverse the direction. Same for the other one.         if ballz <= 20 then             ballmass := ballmass div 4 * 3             direction *= -1         elsif ballz >= ballmass then             direction *= -1         end if     end if     if chars (KEY_UP_ARROW) then         bally += 3     elsif chars (KEY_DOWN_ARROW) then         bally -= 3     elsif chars (KEY_LEFT_ARROW) then         ballx -= 3     elsif chars (KEY_RIGHT_ARROW) then         ballx += 3     elsif chars (' ') then         ballz := 150         ballmass := 150     end if     % Draw the ball     drawfilloval (ballx, bally, ballz, ballz, black)     drawfilloval (ballx, bally, ballz - 2, ballz - 2, 42)     drawarc (ballx + ballz - (ballz div 4), bally, ballz - (ballz div 3), ballz - (ballz div 3), 90, 270, black)     drawarc (ballx - ballz + (ballz div 4), bally, ballz - (ballz div 3), ballz - (ballz div 3), 270, 90, black)     drawline (ballx - ballz, bally, ballx + ballz, bally, black)     put "Press space to drop the ball again."     View.Update     delay (5) end loop

P.S. Some of my variable names don't make sense, but I couldn't think of anything better at the time.

EDIT: Forgot to comment it. apomb  Posted: Fri Jun 27, 2008 8:25 am   Post subject: RE:[Tutorial] 3D graphics

Thats not exactly 3D, Andrew. there's no perspective, the ball is simply a 2D object. where is this third dimension? Moving a circle seemingly into the screen is hardly 3D visuals. Oh, and P.S. this is a TUTORIAL, not a submissions thread. just to point that out.    SNIPERDUDE  Posted: Sat Jun 28, 2008 1:29 pm   Post subject: RE:[Tutorial] 3D graphics

Ok, I've MASTERED 2D graphics, and might as well start tampering around with 3D.

I've noticed that in your tutorial WindSurfer that the Z coordinate always moves towards (0, 0). What if I wanted it (my (0, 0) coordinate) to move towards the center instead of lower left? So no matter where the X or Y coordinates are on the screen changing the Z will make it move closer to the middle...

I'll experiment a bit and see if I can come up with anything. andrew. Posted: Sun Jun 29, 2008 9:38 pm   Post subject: RE:[Tutorial] 3D graphics

Oh well, I tried. SNIPERDUDE  Posted: Mon Jun 30, 2008 5:40 pm   Post subject: RE:[Tutorial] 3D graphics

I've almost got it...
still working on it though Lucas  Posted: Thu Mar 24, 2011 8:14 pm   Post subject: RE:[Tutorial] 3D graphics

setscreen ("graphics: 1200; 800")
setscreen ("offscreenonly")
var Cubes : int := 50
var x, y, z : array 1 .. Cubes of array 0 .. 8 of real
var dx, dy : array 1 .. Cubes * 8 of int
var clr : array 1 .. Cubes of int
var Vx := 600
var Vy := -200
var Vz := 400
var l : int := 80
var dump : string (1)
var mx, my, dump2 : int
var dix, diz : int

loop
for a : 1 .. Cubes
x (a) (0) := Rand.Int (-350, 3750)
y (a) (0) := Rand.Int (100, 1800)
z (a) (0) := Rand.Int (-3550, 3350)
clr (a) := Rand.Int (1, 13)
for b : 1 .. 8
if b = 1 or b = 2 or b = 5 or b = 6 then
x (a) (b) := x (a) (0) + l
else
x (a) (b) := x (a) (0) - l
end if
if b = 1 or b = 4 or b = 5 or b = 8 then
y (a) (b) := y (a) (0) + l
else
y (a) (b) := y (a) (0) - l
end if
if b < 5 then
z (a) (b) := z (a) (0) - l
else
z (a) (b) := z (a) (0) + l
end if
end for
end for

loop
exit when hasch
mousewhere (mx, my, dump2)
dix := (600 - mx) div 50
diz := (400 - my) div 50
for a : 1 .. Cubes
for b : 1 .. 8
x (a) (b) := x (a) (b) - dix
z (a) (b) := z (a) (b) - diz
dx (((a - 1) * 8) + b) := (((200 / (y (a) (b) + 200)) * (x (a) (b) - Vx)) + Vx) div 1
dy (((a - 1) * 8) + b) := (((200 / (y (a) (b) + 200)) * (z (a) (b) - Vz)) + Vz) div 1
end for
drawline (dx (((a - 1) * 8) + 1), dy (((a - 1) * 8) + 1), dx (((a - 1) * 8) + 2), dy (((a - 1) * 8) + 2), clr (a))
drawline (dx (((a - 1) * 8) + 2), dy (((a - 1) * 8) + 2), dx (((a - 1) * 8) + 3), dy (((a - 1) * 8) + 3), clr (a))
drawline (dx (((a - 1) * 8) + 3), dy (((a - 1) * 8) + 3), dx (((a - 1) * 8) + 4), dy (((a - 1) * 8) + 4), clr (a))
drawline (dx (((a - 1) * 8) + 4), dy (((a - 1) * 8) + 4), dx (((a - 1) * 8) + 1), dy (((a - 1) * 8) + 1), clr (a))
drawline (dx (((a - 1) * 8) + 5), dy (((a - 1) * 8) + 5), dx (((a - 1) * 8) + 6), dy (((a - 1) * 8) + 6), clr (a))
drawline (dx (((a - 1) * 8) + 6), dy (((a - 1) * 8) + 6), dx (((a - 1) * 8) + 7), dy (((a - 1) * 8) + 7), clr (a))
drawline (dx (((a - 1) * 8) + 7), dy (((a - 1) * 8) + 7), dx (((a - 1) * 8) + 8), dy (((a - 1) * 8) + 8), clr (a))
drawline (dx (((a - 1) * 8) + 8), dy (((a - 1) * 8) + 8), dx (((a - 1) * 8) + 5), dy (((a - 1) * 8) + 5), clr (a))
drawline (dx (((a - 1) * 8) + 1), dy (((a - 1) * 8) + 1), dx (((a - 1) * 8) + 5), dy (((a - 1) * 8) + 5), clr (a))
drawline (dx (((a - 1) * 8) + 2), dy (((a - 1) * 8) + 2), dx (((a - 1) * 8) + 6), dy (((a - 1) * 8) + 6), clr (a))
drawline (dx (((a - 1) * 8) + 3), dy (((a - 1) * 8) + 3), dx (((a - 1) * 8) + 7), dy (((a - 1) * 8) + 7), clr (a))
drawline (dx (((a - 1) * 8) + 4), dy (((a - 1) * 8) + 4), dx (((a - 1) * 8) + 8), dy (((a - 1) * 8) + 8), clr (a))
end for
View.Update
delay (0)
cls
end loop
getch (dump)
end loop

I think that that is a good example that combines depth/perspective SNIPERDUDE  Posted: Thu Mar 24, 2011 8:30 pm   Post subject: Re: [Tutorial] 3D graphics

code tags in the future please, it makes it easier to read. Especially language-specific.
 code: [syntax="turing"]code here[/syntax] Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First         Page 2 of 2  [ 28 Posts ]
Goto page Previous  1, 2
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: