*/
Want to see what people are talking about? See the latest forum posts.
*/

View \MODULE1.BAS

3D wireframe program made in Visual Basic 3.0. Source code

Submitted By: Unknown
Rating: starstarstarstarstar (Rate It)


DEFINT A-Z

' User defined type defining a line by start point
' (X,Y,Z) and end point (X1,Y1,Z1).
TYPE LineType
    X AS INTEGER
    Y AS INTEGER
    Z AS INTEGER
    X1 AS INTEGER
    Y1 AS INTEGER
    Z1 AS INTEGER
END TYPE

' An array to store lines
Global points(100) AS LineType

Global Xs(100) AS SINGLE, Ys(100) AS SINGLE, Xe(100) AS SINGLE, Ye(100) AS SINGLE, Xn(100) AS SINGLE, Yn(100) AS SINGLE

' Arrays to store screen coordinates of last drawn lines
Global XOldStart(100) AS SINGLE, YOldStart(100) AS SINGLE, XOldEnd(100) AS SINGLE, YOldEnd(100) AS SINGLE

' Arrays to store point coordinates. Index is point number
Global X(100) AS SINGLE, Y(100) AS SINGLE, Z(100) AS SINGLE

' Arrays to store point numbers - Pointers1 for start points, Pointers2 for end points
' Index is line #, value is point #
Global Pointers1(100) AS SINGLE, Pointers2(100) AS SINGLE

' List of points to rotate - value is point number
Global PointsToRotate(100) AS SINGLE

'Sine and cosine lookup tables
Global Cosine&(360), Sine&(360)

Global NumberOfLines
Global NumberOfPoints
Global NumberOfPointsToRotate

' Control variables
Global AtLoc
Global Mxm
Global Mym
Global Mzm
Global Speed

    Global D1
    Global D2
' Constants used in program
Global CONST CDERR_CANCEL = 32755' Common dialog cancel button was clicked

SUB DeterminePointsToRotate ()
'Here comes the hard part... Consider this scenario:

'We have two connected lines, like this:

'   1--------2 and 3
'            |
'            |
'            |
'            |
'            4
'Where 1,2, 3, & 4 are the starting and ending points of each line.
'The first line consists of points 1 & 2  and the second line
'is made of points 3 & 4.
'So, you ask, what's wrong? Nothing, really, but don't you see that
'points 2 and 3 are really at the sample place? Why rotate them twice,
'that would be a total waste of time? The following code eliminates such
'occurrences from the line table. (great explanation, huh?)

'take all of the starting & ending points and put them in one big
'array...
NumberOfPoints = 0
FOR LineNumber = 0 TO NumberOfLines - 1
    X(NumberOfPoints) = points(LineNumber).X
    Y(NumberOfPoints) = points(LineNumber).Y
    Z(NumberOfPoints) = points(LineNumber).Z
    NumberOfPoints = NumberOfPoints + 1
    X(NumberOfPoints) = points(LineNumber).X1
    Y(NumberOfPoints) = points(LineNumber).Y1
    Z(NumberOfPoints) = points(LineNumber).Z1
    NumberOfPoints = NumberOfPoints + 1
NEXT LineNumber

'Now set up two sets of pointers that point to each point that a line
'is made of... (in other words, scan for the first occurrence of each
'starting and ending point in the point array we just built...)
FOR LineToTest = 0 TO NumberOfLines - 1
    XTest = points(LineToTest).X
    YTest = points(LineToTest).Y
    ZTest = points(LineToTest).Z            'get the 3 coordinates of the start point
    FOR PointToTest = 0 TO NumberOfPoints - 1         'scan the point array
        IF X(PointToTest) = XTest AND Y(PointToTest) = YTest AND Z(PointToTest) = ZTest THEN
            Pointers1(LineToTest) = PointToTest    'set the pointer to point to the
            EXIT FOR            'point we have just found
        END IF
    NEXT PointToTest
    XTest = points(LineToTest).X1           'do the same thing that we did above
    YTest = points(LineToTest).Y1           'except scan for the ending point
    ZTest = points(LineToTest).Z1           'of each line
    FOR PointToTest = 0 TO NumberOfPoints - 1
        IF X(PointToTest) = XTest AND Y(PointToTest) = YTest AND Z(PointToTest) = ZTest THEN
            Pointers2(LineToTest) = PointToTest
            EXIT FOR
        END IF
    NEXT PointToTest
NEXT LineToTest
'Okay, were almost done! All we have to do now is to build a table
'that tells us which points to actually rotate...
NumberOfPointsToRotate = 0
FOR LineToTest = 0 TO NumberOfLines - 1
    StartPointNo = Pointers1(LineToTest)
    EndPointNo = Pointers2(LineToTest)
    IF NumberOfPointsToRotate = 0 THEN
        PointsToRotate(NumberOfPointsToRotate) = StartPointNo
        NumberOfPointsToRotate = NumberOfPointsToRotate + 1
    ELSE
        Found = 0
        FOR PointToTest = 0 TO NumberOfPointsToRotate - 1
            IF PointsToRotate(PointToTest) = StartPointNo THEN
                Found = -1
                EXIT FOR'already in list
            END IF
        NEXT PointToTest
        IF NOT Found THEN PointsToRotate(NumberOfPointsToRotate) = StartPointNo
        NumberOfPointsToRotate = NumberOfPointsToRotate + 1
    END IF

    Found = 0
    FOR PointToTest = 0 TO NumberOfPointsToRotate - 1
        IF PointsToRotate(PointToTest) = EndPointNo THEN
            Found = -1
            EXIT FOR
        END IF
    NEXT PointToTest
    IF NOT Found THEN PointsToRotate(NumberOfPointsToRotate) = EndPointNo
    NumberOfPointsToRotate = NumberOfPointsToRotate + 1
NEXT LineToTest
END SUB

SUB MakeSinCosTables ()
'The following for/next loop makes a sine & cosine table.
'Each sine & cosine is multiplied by 1024 and stored as long integers.
'This is done so that we don't have to use any slow floating point
'math at run time.
A% = 0
FOR I! = 0 TO 359 / 57.29577951 STEP 1 / 57.29577951
    Cosine&(A%) = INT(.5 + COS(I!) * 1024)
    Sine&(A%) = INT(.5 + SIN(I!) * 1024): A% = A% + 1
NEXT
END SUB

corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.