TGC Codebase Backup



Advanced 3D Trails by Mobiius

31st Jan 2005 13:41
Summary

Code to create a 3D trail effect (useful for space ship engines, 3D Bang Bang! games, weapon shots, screen-savers and heaps more!) For free, From Me, For You!



Description

Comments: This Program Details The Useage Of My Cool Looking Advanced Trails.
It Uses Two Commands Which Are Located In The Trail.Dba File.
Those two Commands Are:

PrepareTrail(TrailNumber, FlareTexturePath$)
Trail(TrailNumber, XPos, YPos, ZPos, XAng, YAng, ZAng, XOffset, YOffset, ZOffset)

Here Is The Syntax Of The Commands.

PrepareTrail.
Each trail uses 10 plain objects, ghosted, and textured with
FlareTexturePath$.
TrailNumber is a number you use to identify the trail

You can call the PrepareTrail function many times as it automatically picks empty
objects for the trails

Trail.
TrailNumber is the number you chose to identify the trail
XPos is the X Position of the base object
YPos is the Y Position of the base object
ZPos is the Z Position of the base object
XAng is the X Angle of the base object
YAng is the Y Angle of the base object
ZAng is the Z Angle of the base object
XOffset is the X Offset of the base object
YOffset is the Y Offset of the base object
ZOffset is the Z Offset of the base object



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    RemStart
   -------------------------------------------------------------------
   Program Name: MouseTrails
   -------------------------------------------------------------------
   Written By:   Mobiius
   Date:         12-09-04
   -------------------------------------------------------------------
   Comments:     This Program Details The Useage Of My Cool Looking Advanced Trails.
                 It Uses Two Commands Which Are Located In The Trail.Dba File.
                 Those two Commands Are:

                 PrepareTrail(TrailNumber, FlareTexturePath$)
                 Trail(TrailNumber, XPos, YPos, ZPos, XAng, YAng, ZAng, XOffset, YOffset, ZOffset)

                 Here Is The Syntax Of The Commands.

                 PrepareTrail.
                 Each trail uses 10 plain objects, ghosted, and textured with
                 FlareTexturePath$.
                 TrailNumber is a number you use to identify the trail

                 You can call the PrepareTrail function many times as it automatically picks empty
                 objects for the trails

                 Trail.
                 TrailNumber is the number you chose to identify the trail
                 XPos is the X Position of the base object
                 YPos is the Y Position of the base object
                 ZPos is the Z Position of the base object
                 XAng is the X Angle of the base object
                 YAng is the Y Angle of the base object
                 ZAng is the Z Angle of the base object
                 XOffset is the X Offset of the base object
                 YOffset is the Y Offset of the base object
                 ZOffset is the Z Offset of the base object
   -------------------------------------------------------------------
RemEnd

AutoCam Off
Sync On
Sync Rate 60

Backdrop On
Color Backdrop 0

Hide Mouse
Set Camera Range 1, 10000


Set Text Size 30
Set Text Font "Times New Roman"



Dim TrailNumber(10, 10)

PrepareTrail(1, "Lens-11.Bmp")
PrepareTrail(2, "Lens-13.Bmp")
PrepareTrail(3, "Lens-12.Bmp")
PrepareTrail(4, "Lens-11.Bmp")
PrepareTrail(5, "Lens-13.Bmp")
PrepareTrail(6, "Lens-12.Bmp")


Make Object Cube 1, 50
Position Object 1, 0, 0, 0
Hide Object 1
Make Object Cube 2, 50
Position Object 2, 0, 0, 0
Hide Object 2

Position Camera 0, 0, -150
Point Camera 0, 0, 0

Do
   XRotate Object 1, WrapValue(Object Angle X(1) + 1)
   YRotate Object 1, WrapValue(Object Angle Y(1) + 3)
   ZRotate Object 1, WrapValue(Object Angle Z(1) + 2)

   XRotate Object 2, WrapValue(Object Angle X(2) + 2)
   YRotate Object 2, WrapValue(Object Angle Y(2) + 1)
   ZRotate Object 2, WrapValue(Object Angle Z(2) + 3)

   ZRotate Camera WrapValue(Camera Angle Z() + .1)

   Trail(1, 0, 0, 0, Object Angle X(1), Object Angle Y(1), Object Angle Z(1), 0, 40, 0)
   Trail(2, Object Position X(TrailNumber(1, 0)), Object Position Y(TrailNumber(1, 0)), Object Position Z(TrailNumber(1, 0)), Object Angle X(1), WrapValue(Object Angle Z(1) + Object Angle X(1)), Object Angle Y(1), 50, 0, -20)
   Trail(3, Object Position X(TrailNumber(2, 0)), Object Position Y(TrailNumber(2, 0)), Object Position Z(TrailNumber(2, 0)), WrapValue(Object Angle X(1) + Object Angle Y(TrailNumber(2, 0))), WrapValue(Object Angle Z(1) + Object Angle X(1)), Object Angle Z(TrailNumber(2, 0)), 20, 0, -20)

   Trail(4, 0, 0, 0, Object Angle X(2), Object Angle Y(2), Object Angle Z(2), 0, 50, 0)
   Trail(5, Object Position X(TrailNumber(4, 0)), Object Position Y(TrailNumber(4, 0)), Object Position Z(TrailNumber(4, 0)), Object Angle X(2), WrapValue(Object Angle Z(2) + Object Angle X(1)), Object Angle Y(2), 0, 0, -20)
   Trail(6, Object Position X(TrailNumber(5, 0)), Object Position Y(TrailNumber(5, 0)), Object Position Z(TrailNumber(5, 0)), WrapValue(Object Angle X(2) + Object Angle Y(TrailNumber(4, 0))), WrapValue(Object Angle Z(2) + Object Angle X(1)), Object Angle Z(TrailNumber(2, 0)), 40, 0, -20)
   Sync
Loop
End

`Function *****Trail.Dba

`============================================================================================================================

Function Trail(No, Xp#, Yp#, Zp#, Xa#, Ya#, Za#, Xo#, Yo#, Zo#)

   Position Object TrailNumber(No, 0), X#, Y#, Z#
   Rotate Object TrailNumber(No, 0), Xa#, Ya#, Za#

`  Set The Object Z Offset (Forward And Backward)
   Move Object TrailNumber(No, 0), Zo#
`  Set The Object Y Offset (Up And Down)
   XRotate Object TrailNumber(No, 0), WrapValue(Object Angle X(TrailNumber(No, 0)) - 90)
   Move Object TrailNumber(No, 0), Yo#
   XRotate Object TrailNumber(No, 0), WrapValue(Object Angle X(TrailNumber(No, 0)) + 90)
`  Set The Object X Offset (Left And Right)
   YRotate Object TrailNumber(No, 0), WrapValue(Object Angle Y(TrailNumber(No, 0)) + 90)
   Move Object TrailNumber(No, 0), Xo#
   YRotate Object TrailNumber(No, 0), WrapValue(Object Angle Y(TrailNumber(No, 0)) - 90)


   For Obj = 9 To 0 Step -1
      Position Object TrailNumber(No, Obj + 1), Object Position X(TrailNumber(No, Obj)), Object Position Y(TrailNumber(No, Obj)), Object Position Z(TrailNumber(No, Obj))
   Next A

   For A = 1 To 10
      Point Object TrailNumber(No, A), Camera Position X(), Camera Position Y(), Camera Position Z()
   Next A
EndFunction

`============================================================================================================================

Function PrepareTrail(TrailNumber, Path$)
   ImgNo = GetBlankImgNo()
   Load Image Path$, ImgNo


   TrailNumber(TrailNumber, 0) = GetBlankObjNo()
   Make Object Sphere TrailNumber(TrailNumber, 0), 15
   Texture Object TrailNumber(TrailNumber, 0), ImgNo
   Ghost Object On TrailNumber(TrailNumber, 0)
   Set Object Light TrailNumber(TrailNumber, 0), 0
   Set Object Cull TrailNumber(TrailNumber, 0), 0

   Size = 25
   For Obj = 1 To 10
      TrailNumber(TrailNumber, Obj) = GetBlankObjNo()
      Make Object Plain TrailNumber(TrailNumber, Obj), Size, Size
      Texture Object TrailNumber(TrailNumber, Obj), ImgNo
      Ghost Object On TrailNumber(TrailNumber, Obj)
      Set Object Light TrailNumber(TrailNumber, Obj), 0
      Size = Size - 1
   Next Obj
EndFunction

`============================================================================================================================

Function GetBlankImgNo()
   For ImgNo = 65000 To 1 Step -1
      If Image Exist(ImgNo) = 0
         ExitFunction ImgNo
      EndIf
   Next ImgNo
EndFunction 0

`============================================================================================================================

Function GetBlankObjNo()
   For ObjNo = 65000 To 1 Step -1
      If Object Exist(ObjNo) = 0
         ExitFunction ObjNo
      EndIf
   Next ObjNo
EndFunction 0