
-----------------------------------
richcash
Fri Jul 21, 2006 4:26 pm

3-dimensional plotting : x, y, z axes
-----------------------------------
Can someone tell me how to plot 3d points on a 2d screen if I have (x, y, z)? 
Also, I need to know how to make the screen turn. So, if the screen has turned 360 degrees, then it's back in the same spot. 
If I simply use sin and cos for a circle won't it make the objects on the screen look like they're travelling on a curve?
My best attempt is to take x / z and y / z and plot those, and as I said use sin and cos to turn the screen, but this is not correct!

Any info or ideas? Thanks in advance.

-----------------------------------
[Gandalf]
Fri Jul 21, 2006 4:33 pm


-----------------------------------
[url=http://freespace.virgin.net/hugo.elias/]The good-looking textured light-sourced bouncy fun smart and stretchy page is a good source for such things.  The exact link which I think you would find useful is: [url=http://freespace.virgin.net/hugo.elias/routines/3d_to_2d.htm]plotting 3D points onto a 2D screen. :)

-----------------------------------
Delos
Fri Jul 21, 2006 4:35 pm


-----------------------------------
I'm going to assume that you know your way around Turing and more importantly, around trig.  If you have a background in 3D maths as well (3D physics is just as good), then you're set to go.

Bah!  

-----------------------------------
richcash
Fri Jul 21, 2006 4:56 pm


-----------------------------------
Thanks! That's exactly what I needed. I have the first few parts working.
The website is quite detailed except for panx, pany, and panz. What are these and what sort of values should they be?

-----------------------------------
richcash
Fri Jul 21, 2006 5:14 pm


-----------------------------------
The first part works great!

var centrex := maxx div 2
var centrey := maxy div 2
var zoom := 20
var x, y, z : array 1 .. 8 of real
var screenx, screeny : array 1 .. 8 of int

proc assign (var i1, i2, i3, i4 : real, val : int)
    i1 := val
    i2 := val
    i3 := val
    i4 := val
end assign
%SIMPLE CUBE COORDINATES
assign (x (1), x (3), x (5), x (7), 10)
assign (x (2), x (4), x (6), x (8), 20)
assign (y (1), y (2), y (5), y (6), 10)
assign (y (3), y (4), y (7), y (8), 20)
assign (z (1), z (2), z (3), z (4), 10)
assign (z (5), z (6), z (7), z (8), 15)
proc _3d
    for n : 1 .. 8
        %GIVEN CODE
        if z (n) > 0 then

            screenx (n) := round (x (n) / z (n) * zoom) + centrex

            screeny (n) := round (y (n) / z (n) * zoom) + centrey

        end if
        %END GIVEN CODE
    end for
end _3d

_3d

for n : 1 .. 8
    drawdot (screenx (n), screeny (n), 7)
end for

But I don't think this is correct?

var centrex := maxx div 2
var centrey := maxy div 2
var zoom := 100
var x, y, z, newx, newy, newz : array 1 .. 8 of real
var screenx, screeny : array 1 .. 8 of int
var panx, pany, panz := 20
var posx, posy, posz : int := 100

posz := 1
proc assign (var i1, i2, i3, i4 : real, val : int)
    i1 := val
    i2 := val
    i3 := val
    i4 := val
end assign
%SIMPLE CUBE COORDINATES?
assign (x (1), x (3), x (5), x (7), 10)
assign (x (2), x (4), x (6), x (8), 20)
assign (y (1), y (2), y (5), y (6), 10)
assign (y (3), y (4), y (7), y (8), 20)
assign (z (1), z (2), z (3), z (4), 10)
assign (z (5), z (6), z (7), z (8), 20)

proc _3d
    for n : 1 .. 8
        %GIVEN CODE
        x (n) := x (n) + posx

        y (n) := y (n) + posy

        z (n) := z (n) + posz



        newx (n) := x (n) * cosd (panx) - z (n) * sind (panx)

        newz (n) := x (n) * sind (panx) + z (n) * cosd (panx)

        newy (n) := y (n) * cosd (pany) - newz (n) * sind (pany)

        z (n) := newy (n) * cosd (pany) - newz (n) * sind (pany)

        x (n) := newx (n) * cosd (panz) - newy (n) * sind (panz)

        y (n) := newx (n) * sind (panz) + newy (n) * cosd (panz)

        if z (n) > 0 then

            screenx (n) := round (x (n) / z (n) * zoom) + centrex

            screeny (n) := round (y (n) / z (n) * zoom) + centrey - 200

        end if
        %END GIVEN CODE
    end for
end _3d

_3d
for n : 1 .. 8
    drawdot (screenx (n), screeny (n), 7)
end for

This is just a quick test, I will use classes later on.
