Computer Science Canada

Array field of Type

Author:  Saad [ Tue May 15, 2007 9:45 pm ]
Post subject:  Array field of Type

I've been working on a 3D engine and i have all the base procesdures. I have to problems

1. in
code:
type Polygon :
    record
        Vertex : array 1 .. 4 of Point_3D
        Midpoint : Point_3D
    end record

Is there a way to change between 3/4 so i can use triangles or quads

2. In a raw file are the vertices based on 4 point polygon or 3 point polygon?

Edit:
Also to prove im not asking for help on my hw i have attached a simple cube render, use the w a s d keys to rotate

Thnx a100

Author:  DIIST [ Wed May 16, 2007 7:44 pm ]
Post subject:  Re: Array field of Type

thats why use classes, but if you dont want to go the easy way use unions. There the same things as structs & records but at runtime you can select the feilds. Ie three points or four! Wink

Author:  Cervantes [ Wed May 16, 2007 8:46 pm ]
Post subject:  RE:Array field of Type

If you want to work with triangles or quadrilaterals, then the easiest solution would probably be to simply use an array from 1 to 4 like you have, and just ignore the last data point if you want to use triangles. You could include a boolean to determine whether to use a triangle or not. Or better yet, just include an integer variable into your Polygon type that represents the number of vertices. This is a bit wasteful of resources, yes, but if you're only using 3 or 4 sided polygons, it's probably not too terrible. But if you want to squeeze resource management, you should just make two different types.

However, thuvs suggestions are great--better. Classes would definitely be good: you could probably make triangle and quadrilateral classes inherit from a generic polygon class. Or, unions sound like they would do very well. I've never seen union used before! It'd be cool if it got put to use.


: