Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 More on .RAW
Index -> Programming, Turing -> Turing Submissions
Goto page Previous  1, 2, 3  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TheZsterBunny




PostPosted: Fri Aug 20, 2004 4:15 pm   Post subject: (No subject)

I give up. I've tried all day, but I cannot figure out what i'm doing wrong.

I would very much like to learn how that program was done

-Z
Sponsor
Sponsor
Sponsor
sponsor
RaPsCaLLioN




PostPosted: Fri Aug 20, 2004 6:07 pm   Post subject: (No subject)

Do you know the equation for rotation? Just make an array that stores 3 coordinates for each point (X, Y, Z) - rotate each accordingly - same equation for any axis. And just draw the 'screen' x/y coordinates.

I don't make any sense...
I'll post the code but it doesn't make much more sense than I do. Let me play around w/ it a bit more first.
Mazer




PostPosted: Fri Aug 20, 2004 6:11 pm   Post subject: (No subject)

I'm a bit curious, how is the Z sorting done? Just taking the average Z coord for each face and sorting them based on that?
RaPsCaLLioN




PostPosted: Sat Aug 21, 2004 7:44 am   Post subject: (No subject)

Yep. So there are some cases where the display would be wrong because the avg of a polygon that should be located further away may be closer than the avg of an up front polygon.
code:
                  __        __
                _I__I______I  I___
               I__________ I  I___I
                 I  I      I  I
                 I  I      I  I
                 I  I      I  I
                 I  I      I  I
                 I  I      I  I
                _I  I______I__I__
               I_I  I____________I
                 I__I      I__I 
                                                 

This is another example of polygons that wouldn't be displayed right.
TheZsterBunny




PostPosted: Sat Aug 21, 2004 7:45 am   Post subject: (No subject)

WHat is the rotation code?

I have a nifty way of keeping the shape stored, but rotation is giving me difficulties.

code:

type poly :
    record
        x : array 1 .. 3 of real
        y : array 1 .. 3 of real
        z : array 1 .. 3 of real
    end record
var shape : flexible array 1 .. 1 of poly
var input : int
var filename : string
put "Enter File Name followed by .raw: " ..
get filename
assert length (filename) > 4 and filename (* -3 .. *) = ".raw" and File.Exists (filename)
% filename := "spacestation2.raw"
open : input, filename, get
var count : int := 1
put "Reading File..."
loop
    for i : 1 .. 3
        get : input, shape (count).x (i)
        get : input, shape (count).y (i)
        get : input, shape (count).z (i)
    end for
    count += 1
    exit when eof (input)
    new shape, count
end loop
close : input
put upper (shape), " Polygons Read."



The answer is probably something very simple, and I'm missing it completely. I dug up some formulas for rotation, but I didn't understand them. Its from some computer science university class. Open with PPT.

I have to go,

-Z



lecture08.ppt
 Description:
Matricies!

Download
 Filename:  lecture08.ppt
 Filesize:  672.5 KB
 Downloaded:  236 Time(s)

RaPsCaLLioN




PostPosted: Sat Aug 21, 2004 7:58 am   Post subject: (No subject)

This is the procedure for rotation. iTheta is the angle whether +/-. The big problem I encountered initially was during display. It took me forever to realize to use a temp variable to store the rounded value to display. I first rounded each stored point which caused distortion in shape.

code:
procedure Rotate (iAxisA, iAxisB, iTheta : int)

    var iU, iV : real

    for i : 1 .. iNumPolys
        for j : 1 .. 3
            iU := arPolygons (i, j, iAxisA)
            iV := arPolygons (i, j, iAxisB)
            arPolygons (i, j, iAxisA) := (iU * cosd (iTheta) + iV * sind (iTheta))
            arPolygons (i, j, iAxisB) := (-iU * sind (iTheta) + iV * cosd (iTheta))
        end for
    end for


end Rotate
TheZsterBunny




PostPosted: Sat Aug 21, 2004 8:42 am   Post subject: (No subject)

Crap. I've seen that thing before too.

This
code:

var tempx, tempy, tempz : array 1 .. 3 of int
for i : 1 .. upper (shape)
    for j : 1 .. 3
        tempx (j) := round (shape (i).x (j)) + xoffset
        tempy (j) := round (shape (i).y (j)) + yoffset
        tempz (j) := round (shape (i).z (j)) % + ???????
    end for
    drawpolygon (tempx, tempy, 3, black)
end for

is what I've used to draw my shapes.

Can you please explain to me what the iAxis variables are?

Thanks

-Z

--edit--

and what arPolygons are

--edit--

I get it. Thanks.

-Z

-Z
TheZsterBunny




PostPosted: Sat Aug 21, 2004 11:32 am   Post subject: (No subject)

Ok, got it.


'cept I'm having trouble with the z-sort.


...and shapes with over 10 000 polygons.


meh.

-Z

code:

var dispx, dispy : array 1 .. 3 of int
type poly :
    record
        xyz : array 1 .. 3, 1 .. 3 of real
    end record
var shape : flexible array 1 .. 1 of poly
var xoffset : int := maxx div 2
var yoffset : int := maxy div 2
var input : int
var filename : string
put "Enter File Name followed by .raw: " ..
get filename
assert length (filename) > 4 and filename (* -3 .. *) = ".raw" and File.Exists (filename)
open : input, filename, get
var count : int := 1
put "Reading File..."
loop
    for i : 1 .. 3
        get : input, shape (count).xyz (1, i)
        get : input, shape (count).xyz (2, i)
        get : input, shape (count).xyz (3, i)
    end for
    count += 1
    exit when eof (input)
    new shape, count
end loop
close : input
var unsort : array 1 .. upper (shape) of real
var sort : array 1 .. upper (shape), 1 .. 2 of real
var mx, my, mb : int
var yangle, xangle : int := 0
put upper (shape), " Polygons Read."
setscreen ("offscreenonly")
proc rotate (axis1, axis2, ang : int)
    var iu, iv : real
    for i : 1 .. upper (shape)
        for j : 1 .. 3
            iu := shape (i).xyz (axis1, j)
            iv := shape (i).xyz (axis2, j)
            shape (i).xyz (axis1, j) := (iu * cosd (ang) + iv * sind (ang))
            shape (i).xyz (axis2, j) := (-iu * sind (ang) + iv * cosd (ang))
        end for
    end for
end rotate
proc draw (axis1, axis2 : int)
    cls
    for i : 1 .. upper (shape)
        for j : 1 .. 3
            dispx (j) := round (shape (i).xyz (axis1, j)) + xoffset
            dispy (j) := round (shape (i).xyz (axis2, j)) + yoffset
        end for
        drawpolygon (dispx, dispy, 3, black)
    end for
    drawline (0, maxy div 2, maxx, maxy div 2, blue)
    drawline (maxx div 2, 0, maxx div 2, maxy, red)
    View.Update
end draw
var alicia : array char of boolean
loop
    Input.KeyDown (alicia)
    if alicia (KEY_LEFT_ARROW) and xoffset - 10 > 0 then
        xoffset -= 10
    end if
    if alicia (KEY_RIGHT_ARROW) and xoffset + 10 < maxx then
        xoffset += 10
    end if
    if alicia (KEY_UP_ARROW) and yoffset + 10 < maxy then
        yoffset += 10
    end if
    if alicia (KEY_DOWN_ARROW) and yoffset - 10 > 0 then
        yoffset -= 10
    end if
    mousewhere (mx, my, mb)
    if mb = 1 then
        if my > 0 and my < maxy then
            yangle := round (((my + yoffset) div 2 / maxy) * (10)) - 5
        else
            yangle := 0
        end if
        if yangle not= 0 then
            rotate (2, 3, yangle)
        end if
        if mx > 0 and mx < maxx then
            xangle := round (((mx + xoffset) div 2 / maxx) * (10)) - 5
        else
            xangle := 0
        end if
        if xangle not= 0 then
            rotate (1, 3, xangle)
        end if
    end if
    if xangle not= 0 or yangle not= 0 then
        draw (1, 2)
    end if
end loop
Sponsor
Sponsor
Sponsor
sponsor
RaPsCaLLioN




PostPosted: Sat Aug 21, 2004 7:42 pm   Post subject: (No subject)

When I used ur code I didn't have problems with .raw files larger than 10k.. What's happening?
TheZsterBunny




PostPosted: Sun Aug 22, 2004 9:32 pm   Post subject: (No subject)

No problems with polygon numbers, but it becomes a bit slow.

My Z-Sort is quite slow, and there are occasional problems with overlap.

-Z
TheZsterBunny




PostPosted: Sun Aug 22, 2004 9:58 pm   Post subject: (No subject)

code:

var dispx, dispy : array 1 .. 3 of int
var colorthing : int := 12
type poly :
    record
        xyz : array 1 .. 3, 1 .. 3 of real
    end record
var shape : flexible array 1 .. 1 of poly
var xoffset : int := maxx div 2
var yoffset : int := maxy div 2
var input : int
var filename : string
put "Enter File Name followed by .raw: " ..
get filename
assert length (filename) > 4 and filename (* -3 .. *) = ".raw" and File.Exists (filename)
open : input, filename, get
var count : int := 1
put "Reading File..."
loop
    for i : 1 .. 3
        get : input, shape (count).xyz (1, i)
        get : input, shape (count).xyz (2, i)
        get : input, shape (count).xyz (3, i)
    end for
    count += 1
    exit when eof (input)
    new shape, count
end loop
close : input
var unsort : array 1 .. upper (shape) of real
var sort : array 1 .. upper (shape), 1 .. 2 of real
var mx, my, mb : int
var yangle, xangle : int := 0
put upper (shape), " Polygons Read."
setscreen ("offscreenonly")
proc rotate (axis1, axis2, ang : int)
    var iu, iv : real
    for i : 1 .. upper (shape)
        for j : 1 .. 3
            iu := shape (i).xyz (axis1, j)
            iv := shape (i).xyz (axis2, j)
            shape (i).xyz (axis1, j) := (iu * cosd (ang) + iv * sind (ang))
            shape (i).xyz (axis2, j) := (-iu * sind (ang) + iv * cosd (ang))
        end for
    end for
end rotate
proc draw (axis1, axis2 : int)
    cls
    drawline (0, maxy div 2, maxx, maxy div 2, blue)
    drawline (maxx div 2, 0, maxx div 2, maxy, red)
    for decreasing i : upper (shape) .. 1
        for j : 1 .. 3
            dispx (j) := round (shape (round (sort (i, 1))).xyz (axis1, j)) + xoffset
            dispy (j) := round (shape (round (sort (i, 1))).xyz (axis2, j)) + yoffset
        end for
        colorthing := RGB.AddColor ((1 - (sort (i, 2) / 240)), (1 - (sort (i, 2) / 240)), (1 - (sort (i, 2) / 240)))
        drawfillpolygon (dispx, dispy, 3, colorthing)
        drawpolygon (dispx, dispy, 3, black)
    end for
    View.Update
end draw
proc zsort
    for qiy : 1 .. upper (shape)
        unsort (qiy) := (shape (qiy).xyz (3, 1) + shape (qiy).xyz (3, 2) + shape (qiy).xyz (3, 3)) / 3
        for yiq : 1 .. 2
            sort (qiy, yiq) := -999999
        end for
    end for
    for zing : 1 .. upper (shape)
        var templow : real := 999999
        var whichlow : int
        for zing2 : 1 .. upper (shape)
            if unsort (zing2) < templow then
                templow := unsort (zing2)
                whichlow := zing2
            end if
        end for
        sort (zing, 1) := whichlow
        sort (zing, 2) := templow
        unsort (round (whichlow)) := 99999
    end for
end zsort
var alicia : array char of boolean
loop
    Input.KeyDown (alicia)
    if alicia (KEY_LEFT_ARROW) and xoffset - 10 > 0 then
        xoffset -= 10
    end if
    if alicia (KEY_RIGHT_ARROW) and xoffset + 10 < maxx then
        xoffset += 10
    end if
    if alicia (KEY_UP_ARROW) and yoffset + 10 < maxy then
        yoffset += 10
    end if
    if alicia (KEY_DOWN_ARROW) and yoffset - 10 > 0 then
        yoffset -= 10
    end if
    mousewhere (mx, my, mb)
    if mb = 1 then
        if my > 0 and my < maxy then
            yangle := round ((my / maxy) * (10)) - 5
        else
            yangle := 0
        end if
        if yangle not= 0 then
            rotate (2, 3, yangle)
        end if
        if mx > 0 and mx < maxx then
            xangle := round ((mx / maxx) * (10)) - 5
        else
            xangle := 0
        end if
        if xangle not= 0 then
            rotate (1, 3, xangle)
        end if
    end if
    if xangle not= 0 or yangle not= 0 then
        zsort
        draw (1, 2)
    end if
end loop


Tried my hand at the Z-Sort and distance shading parts of the engine. Still having trouble with both.

Fair warning with this version. THe fewer polygons, the better. I've tested this with plane2.raw and it has been pretty smooth.

Except for the overlapping polygons.

-Z
RaPsCaLLioN




PostPosted: Mon Aug 23, 2004 11:37 am   Post subject: (No subject)

I'll check that code out when I get home and Edit this reply with comments.

EDIT
I see what u mean with the z-sort. Look into a Quick sort method. I can help u there if u need it. Also, try culling your polygons and that should fix some of the display problems. That should also speed up the system quite a bit.

I never liked distance shading. Confused
TheZsterBunny




PostPosted: Tue Aug 24, 2004 5:50 pm   Post subject: (No subject)

Thanks.

I've spent the last 2 days trying to remember what I learned in compsci class. the teacher showed us an incredible sorting procedure which sorted huge arrays almost instantly, but I cannot remember it.

Also, what is the polygon culling?

--edit--

well I found your qsort procedures and am trying to decipher them.

I'm just curious as to one part. The variables 'lo' and 'hi', are they the actual values or the unsorted positions of?

-Z
RaPsCaLLioN




PostPosted: Wed Aug 25, 2004 9:50 am   Post subject: (No subject)

'lo' and 'hi' are the array positions of the section to sort.
Polygon culling is removing background polygons (which aren't seen anyway) from being drawn to speed up the process.
TheZsterBunny




PostPosted: Wed Aug 25, 2004 3:10 pm   Post subject: (No subject)

so to sort the entire array

code:

var unsort : array 1..5 of int

1 would be 'lo' and 5 would be 'hi'?

There is also palce for 2 arrays. A is the output, B is the unsorted data?

-Z
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 3  [ 37 Posts ]
Goto page Previous  1, 2, 3  Next
Jump to:   


Style:  
Search: