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?

Sponsor Sponsor

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 :arraycharofboolean
ballx :=maxxdiv2
bally :=maxydiv2
ballz :=50 loop Input.KeyDown(chars) cls

% Checking if the ball hit the ground ifnot ballmass =0then % 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 <= 20then
ballmass := ballmass div4*3
direction *= -1 elsif ballz >= ballmass then
direction *= -1 endif endif 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 endif % Draw the ball drawfilloval(ballx, bally, ballz, ballz, black) drawfilloval(ballx, bally, ballz - 2, ballz - 2, 42) drawarc(ballx + ballz - (ballz div4), bally, ballz - (ballz div3), ballz - (ballz div3),90, 270, black) drawarc(ballx - ballz + (ballz div4), bally, ballz - (ballz div3), ballz - (ballz div3),270, 90, black) drawline(ballx - ballz, bally, ballx + ballz, bally, black) put"Press space to drop the ball again." View.Update delay(5) endloop

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.

Sponsor Sponsor

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