I've been rewriting my object manager framework lately and decided to post it up for use. Use it however you want to.
The functions started as a way to reference and manipulate objects by name rather than ID numbers. In the rewrite, I've added velocity, rotation rate, and YPR rates which automatically apply themselves when an object is updated with the Object_Update() function. The functions aren't commented, but you can probably figure out what they do by the function names and a little code browsing. Beware that the functions rely on an error handler (Error_Write()) to spit out error messages to the console log.
Here are the functions:
rem ------------------------------------------------------------------------------------------------------------------------------------------------------------------
type Float_3
X as float
Y as float
Z as float
endtype
`Object data type definitions
type Appearance_Data
Wireframe as byte
Transparent as byte
Cull as byte
Filter as byte
Light as byte
Fog as byte
Ambient as byte
endtype
type Texture_Data
Image as word
WrapMode as byte
MipMode as byte
MipEnable as byte
endtype
type Object_Entry
SourceFile as string `The object's source file
Name as string `The object's handle, or name
Number as word `The object's DirectX ID number
Size as Float_3 `The object's size along each axis
Scale as Float_3 `The object's scaling factor along each axis
CollisionRadius as float `The object's colllision radius
Position as Float_3 `The object's position in the world
Velocity as Float_3 `The velocity along each of the object's axis
Angle as Float_3 `The current angle along each of the object's axis
Rotation as Float_3 `The rate of rotation along each of the object's axis
ForwardVel as float
VerticalVel as float
LateralVel as float
PitchRate as float
YawRate as float
RollRate as float
PitchAngle as float
YawAngle as float
RollAngle as float
Texture as Texture_Data
Appearance as Appearance_Data
endtype
dim Object() as Object_Entry
empty array Object()
global Object
rem ----------------------------
rem | Object Manager Functions |
rem ----------------------------
function Object_Decrease_Velocity_Absolute(Name$, X#, Y#, Z#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Decrease_Velocity_Absolute-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).Velocity.X = Object(Obj).Velocity.X - X#
Object(Obj).Velocity.Y = Object(Obj).Velocity.Y - Y#
Object(Obj).Velocity.Z = Object(Obj).Velocity.Z - Z#
endfunction 0
function Object_Decrease_Velocity_Relative(Name$, X#, Y#, Z#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Decrease_Velocity_Relative-->Error=Object not found " + Name$)
exitfunction -1
endif
X# = X# / 100.0
Y# = Y# / 100.0
Z# = Z# / 100.0
Object(Obj).Velocity.X = Object(Obj).Velocity.X - Object(Obj).Velocity.X * X#
Object(Obj).Velocity.Y = Object(Obj).Velocity.Y - Object(Obj).Velocity.Y * Y#
Object(Obj).Velocity.Z = Object(Obj).Velocity.Z - Object(Obj).Velocity.Z * Z#
endfunction 0
function Object_Delete(Name$)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Delete-->Error=Object " + Name$ + " not found")
exitfunction -1
endif
delete object Object(Obj).Number
array delete element Object(), Obj
endfunction 1
function Object_Flush(File$)
array index to top Object()
while array index valid(Object())
if Object().SourceFile = File$
delete object Object().Number
array delete element Object()
else
next array index Object()
endif
endwhile
endfunction 1
function Object_Get_Angle_X(Name$)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Get_Angle_X-->Error=Object not found " + Name$)
exitfunction -1.0
endif
p# = Object(Obj).Angle.X
endfunction p#
function Object_Get_Angle_Y(Name$)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Get_Angle_Y-->Error=Object not found " + Name$)
exitfunction -1.0
endif
p# = Object(Obj).Angle.Y
endfunction p#
function Object_Get_Angle_Z(Name$)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Get_Angle_Z-->Error=Object not found " + Name$)
exitfunction -1.0
endif
p# = Object(Obj).Angle.Z
endfunction p#
function Object_Get_Free_ID()
a = 1
while a < 65535
if not object exist(a)
exitfunction a
endif
inc a
endwhile
endfunction -1
function Object_Get_Pitch_Rate(Name$, R#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Get_Pitch_Rate-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).PitchRate = R#
endfunction 1
function Object_Get_Position_X(Name$)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Get_Position_X-->Error=Object not found " + Name$)
exitfunction -1.0
endif
p# = Object(Obj).Position.X
endfunction p#
function Object_Get_Position_Y(Name$)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Get_Position_Y-->Error=Object not found " + Name$)
exitfunction -1.0
endif
p# = Object(Obj).Position.Y
endfunction p#
function Object_Get_Position_Z(Name$)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Get_Position_Z-->Error=Object not found " + Name$)
exitfunction -1.0
endif
p# = Object(Obj).Position.Z
endfunction p#
function Object_Get_Roll_Rate(Name$, R#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Get_Roll_Rate-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).RollRate = R#
endfunction 1
function Object_Get_Rotation_X(Name$)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Get_Rotation_X-->Error=Object not found " + Name$)
exitfunction -1.0
endif
p# = Object(Obj).Rotation.X
endfunction p#
function Object_Get_Rotation_Y(Name$)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Get_Rotation_Y-->Error=Object not found " + Name$)
exitfunction -1.0
endif
p# = Object(Obj).Rotation.Y
endfunction p#
function Object_Get_Rotation_Z(Name$)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Get_Rotation_Z-->Error=Object not found " + Name$)
exitfunction -1.0
endif
p# = Object(Obj).Rotation.Z
endfunction p#
function Object_Get_Velocity_X(Name$)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Get_Velocity_X-->Error=Object not found " + Name$)
exitfunction -1.0
endif
p# = Object(Obj).Velocity.X
endfunction p#
function Object_Get_Velocity_Y(Name$)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Get_Velocity_Y-->Error=Object not found " + Name$)
exitfunction -1.0
endif
p# = Object(Obj).Velocity.Y
endfunction p#
function Object_Get_Velocity_Z(Name$)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Get_Velocity_Z-->Error=Object not found " + Name$)
exitfunction -1.0
endif
p# = Object(Obj).Velocity.Z
endfunction p#
function Object_Get_Yaw_Rate(Name$, R#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Get_Yaw_Rate-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).YawRate = R#
endfunction 1
function Object_Hide(Name$)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Hide-->Error=Object not found " + Name$)
exitfunction -1.0
endif
hide object Object(Obj).Number
endfunction 0.0
function Object_Increase_Velocity_Absolute(Name$, X#, Y#, Z#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Increase_Velocity_Absolute-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).Velocity.X = Object(Obj).Velocity.X + X#
Object(Obj).Velocity.Y = Object(Obj).Velocity.Y + Y#
Object(Obj).Velocity.Z = Object(Obj).Velocity.Z + Z#
endfunction 0
function Object_Increase_Velocity_Relative(Name$, X#, Y#, Z#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Increase_Velocity_Relative-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).Velocity.X = Object(Obj).Velocity.X + Object(Obj).Velocity.X * X#
Object(Obj).Velocity.Y = Object(Obj).Velocity.Y + Object(Obj).Velocity.Y * Y#
Object(Obj).Velocity.Z = Object(Obj).Velocity.Z + Object(Obj).Velocity.Z * Z#
endfunction 0
function Object_Index_From_Name(Name$)
i = 0
array index to top Object()
while array index valid(Object())
if Object().Name = Name$
exitfunction i
endif
next array index Object()
inc i
endwhile
endfunction -1
function Object_Invert_Rotation(Name$, X#, Y#, Z#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Invert_Rotation-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).Rotation.X = 0.0 - Object(Obj).Rotation.X
Object(Obj).Rotation.Y = 0.0 - Object(Obj).Rotation.Y
Object(Obj).Rotation.Z = 0.0 - Object(Obj).Rotation.Z
endfunction 0
function Object_Invert_Velocity(Name$, X#, Y#, Z#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Invert_Velocity-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).Velocity.X = 0.0 - Object(Obj).Velocity.X
Object(Obj).Velocity.Y = 0.0 - Object(Obj).Velocity.Y
Object(Obj).Velocity.Z = 0.0 - Object(Obj).Velocity.Z
endfunction 0
function Object_Load(File$, Name$)
SourceObject = Object_Number_From_File(File$)
if SourceObject < 0
SourceObject = Object_Get_Free_ID()
if SourceObject < 0
Error_Write("Object Manager-->Object_Load-->Error=No Free Source Object ID:Could not load 3D object " + File$ + "as " + Name$)
exitfunction -1
endif
if not file exist(File$)
Error_Write("Object Manager-->Object_Load-->Error=File does not exist:Could not load 3D object " + File$ + "as " + Name$)
exitfunction -2
endif
load object File$, SourceObject
hide object SourceObject
array insert at bottom Object()
array index to bottom Object()
SourceIndex = array count(Object())
Object().SourceFile = File$
Object().Name = "Source_" + Name$
Object().Number = SourceObject
Object().Size.X = object size x(SourceObject)
Object().Size.Y = object size y(SourceObject)
Object().Size.Z = object size z(SourceObject)
if Object().Size.X =< Object().Size.Y
if Object().Size.Y =< Object().Size.Z
Object().CollisionRadius = Object().Size.Z / 2
else
Object().CollisionRadius = Object().Size.Y / 2
endif
else
if Object().Size.X =< Object().Size.Z
Object().CollisionRadius = Object().Size.Z / 2
else
Object().CollisionRadius = Object().Size.X / 2
endif
endif
Object().Scale.X = 1.0
Object().Scale.Y = 1.0
Object().Scale.Z = 1.0
Object().Position.X = 0.0
Object().Position.Y = 0.0
Object().Position.Z = 0.0
Object().Velocity.X = 0.0
Object().Velocity.Y = 0.0
Object().Velocity.Z = 0.0
Object().Angle.X = 0.0
Object().Angle.Y = 0.0
Object().Angle.Z = 0.0
Object().Rotation.X = 0.0
Object().Rotation.Y = 0.0
Object().Rotation.Z = 0.0
Object().ForwardVel = 0.0
Object().VerticalVel = 0.0
Object().LateralVel = 0.0
Object().PitchRate = 0.0
Object().YawRate = 0.0
Object().RollRate = 0.0
Object().PitchAngle = 0.0
Object().YawAngle = 0.0
Object().RollAngle = 0.0
endif
DestinationObject = Object_Get_Free_ID()
if DestinationObject < 0
Error_Write("Object Manager-->Object_Load-->Error=No Free Destination Object ID:Could not load 3D object " + File$ + "as " + Name$)
exitfunction -3
endif
array insert at bottom Object()
array index to bottom Object()
clone object DestinationObject, SourceObject
Object().SourceFile = "Clone_" + File$
Object().Name = Name$
Object().Number = DestinationObject
Object().Size.X = Object(SourceIndex).Size.X
Object().Size.Y = Object(SourceIndex).Size.Y
Object().Size.Z = Object(SourceIndex).Size.Z
Object().CollisionRadius = Object(SourceIndex).CollisionRadius
Object().Scale.X = 1.0
Object().Scale.Y = 1.0
Object().Scale.Z = 1.0
Object().Position.X = 0.0
Object().Position.Y = 0.0
Object().Position.Z = 0.0
Object().Velocity.X = 0.0
Object().Velocity.Y = 0.0
Object().Velocity.Z = 0.0
Object().Angle.X = 0.0
Object().Angle.Y = 0.0
Object().Angle.Z = 0.0
Object().Rotation.X = 0.0
Object().Rotation.Y = 0.0
Object().Rotation.Z = 0.0
Object().ForwardVel = 0.0
Object().VerticalVel = 0.0
Object().LateralVel = 0.0
Object().PitchRate = 0.0
Object().YawRate = 0.0
Object().RollRate = 0.0
Object().PitchAngle = 0.0
Object().YawAngle = 0.0
Object().RollAngle = 0.0
Error_Write("Object Manager-->Object_Load-->Error=Object " + File$ + "cloned as " + Name$)
endfunction 0
function Object_Loaded(Name$)
array index to top Object()
while array index valid(Object())
if Object().Name = Name$
exitfunction 1
endif
endwhile
endfunction 0
function Object_Move_Down(Name$, Dist#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Move_Down-->Error=Object not found " + Name$)
exitfunction -1
endif
move object down Object(Obj).Number, Dist#
Object(Obj).Position.X = object position x(Object(Obj).Number)
Object(Obj).Position.Y = object position y(Object(Obj).Number)
Object(Obj).Position.Z = object position z(Object(Obj).Number)
endfunction 0
function Object_Move_Forward(Name$, Dist#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Move_Forward-->Error=Object not found " + Name$)
exitfunction -1
endif
move object Object(Obj).Number, Dist#
Object(Obj).Position.X = object position x(Object(Obj).Number)
Object(Obj).Position.Y = object position y(Object(Obj).Number)
Object(Obj).Position.Z = object position z(Object(Obj).Number)
endfunction 0
function Object_Move_Left(Name$, Dist#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Move_Left-->Error=Object not found " + Name$)
exitfunction -1
endif
move object left Object(Obj).Number, Dist#
Object(Obj).Position.X = object position x(Object(Obj).Number)
Object(Obj).Position.Y = object position y(Object(Obj).Number)
Object(Obj).Position.Z = object position z(Object(Obj).Number)
endfunction 0
function Object_Move_Reverse(Name$, Dist#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Move_Reverse-->Error=Object not found " + Name$)
exitfunction -1
endif
move object Object(Obj).Number, -Dist#
Object(Obj).Position.X = object position x(Object(Obj).Number)
Object(Obj).Position.Y = object position y(Object(Obj).Number)
Object(Obj).Position.Z = object position z(Object(Obj).Number)
endfunction 0
function Object_Move_Right(Name$, Dist#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Move_Right-->Error=Object not found " + Name$)
exitfunction -1
endif
move object right Object(Obj).Number, Dist#
Object(Obj).Position.X = object position x(Object(Obj).Number)
Object(Obj).Position.Y = object position y(Object(Obj).Number)
Object(Obj).Position.Z = object position z(Object(Obj).Number)
endfunction 0
function Object_Move_Up(Name$, Dist#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Move_Up-->Error=Object not found " + Name$)
exitfunction -1
endif
move object up Object(Obj).Number, Dist#
Object(Obj).Position.X = object position x(Object(Obj).Number)
Object(Obj).Position.Y = object position y(Object(Obj).Number)
Object(Obj).Position.Z = object position z(Object(Obj).Number)
endfunction 0
function Object_Number_From_File(File$)
array index to top Object()
while array index valid(Object())
if Object().SourceFile = File$
n = Object().Number
exitfunction n
endif
next array index Object()
endwhile
endfunction -1
function Object_Number_From_Name(Name$)
array index to top Object()
while array index valid(Object())
if Object().Name = Name$
n = Object().Number
exitfunction n
endif
next array index Object()
endwhile
endfunction -1
function Object_Pitch_Down(Name$, A#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Pitch_Down-->Error=Object not found " + Name$)
exitfunction -1
endif
pitch object down Object(Obj).Number, A#
Object(Obj).Angle.X = object angle x(Object(Obj).Number)
Object(Obj).Angle.Y = object angle y(Object(Obj).Number)
Object(Obj).Angle.Z = object angle z(Object(Obj).Number)
endfunction 0
function Object_Pitch_Up(Name$, A#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Pitch_Up-->Error=Object not found " + Name$)
exitfunction -1
endif
pitch object up Object(Obj).Number, A#
Object(Obj).Angle.X = object angle x(Object(Obj).Number)
Object(Obj).Angle.Y = object angle y(Object(Obj).Number)
Object(Obj).Angle.Z = object angle z(Object(Obj).Number)
endfunction 0
function Object_Preload(File$)
SourceObject = Object_Number_From_File(File$)
if SourceObject < 0
SourceObject = Object_Get_Free_ID()
if SourceObject < 0
Error_Write("Object Manager-->Object_Load-->Error=No Free Source Object ID:Could not load 3D object " + File$ + "as " + Name$)
exitfunction -1
endif
if not file exist(File$)
Error_Write("Object Manager-->Object_Load-->Error=File does not exist:Could not load 3D object " + File$ + "as " + Name$)
exitfunction -2
endif
load object File$, SourceObject
hide object SourceObject
array insert at bottom Object()
array index to bottom Object()
Object().SourceFile = File$
Object().Name = "Source_" + Name$
Object().Number = SourceObject
Object().Size.X = object size x(SourceObject)
Object().Size.Y = object size y(SourceObject)
Object().Size.Z = object size z(SourceObject)
if Object().Size.X =< Object().Size.Y
if Object().Size.Y =< Object().Size.Z
Object().CollisionRadius = Object().Size.Z / 2
else
Object().CollisionRadius = Object().Size.Y / 2
endif
else
if Object().Size.X =< Object().Size.Z
Object().CollisionRadius = Object().Size.Z / 2
else
Object().CollisionRadius = Object().Size.X / 2
endif
endif
Object().Scale.X = 1.0
Object().Scale.Y = 1.0
Object().Scale.Z = 1.0
Object().Position.X = 0.0
Object().Position.Y = 0.0
Object().Position.Z = 0.0
Object().Velocity.X = 0.0
Object().Velocity.Y = 0.0
Object().Velocity.Z = 0.0
Object().Angle.X = 0.0
Object().Angle.Y = 0.0
Object().Angle.Z = 0.0
Object().Rotation.X = 0.0
Object().Rotation.Y = 0.0
Object().Rotation.Z = 0.0
Object().ForwardVel = 0.0
Object().VerticalVel = 0.0
Object().LateralVel = 0.0
Object().PitchRate = 0.0
Object().YawRate = 0.0
Object().RollRate = 0.0
Object().PitchAngle = 0.0
Object().YawAngle = 0.0
Object().RollAngle = 0.0
endif
endfunction 1
function Object_Preloaded(File$)
array index to top Object()
while array index valid(Object())
if Object().SourceFile = "Source_" + File$
exitfunction 1
endif
endwhile
endfunction 0
function Object_Reset_Angle(Name$)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Reset_Angle-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).Angle.X = 0.0
Object(Obj).Angle.Y = 0.0
Object(Obj).Angle.Z = 0.0
endfunction 0
function Object_Reset_Rotation(Name$)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Reset_Rotation-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).Rotation.X = 0.0
Object(Obj).Rotation.Y = 0.0
Object(Obj).Rotation.Z = 0.0
endfunction 0
function Object_Reset_Velocity(Name$)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Reset_Velocity-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).Velocity.X = 0.0
Object(Obj).Velocity.Y = 0.0
Object(Obj).Velocity.Z = 0.0
endfunction 0
function Object_Roll_Left(Name$, A#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Roll_Left-->Error=Object not found " + Name$)
exitfunction -1
endif
roll object left Object(Obj).Number, A#
Object(Obj).Angle.X = object angle x(Object(Obj).Number)
Object(Obj).Angle.Y = object angle y(Object(Obj).Number)
Object(Obj).Angle.Z = object angle z(Object(Obj).Number)
endfunction 0
function Object_Roll_Right(Name$, A#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Roll_Right-->Error=Object not found " + Name$)
exitfunction -1
endif
roll object right Object(Obj).Number, A#
Object(Obj).Angle.X = object angle x(Object(Obj).Number)
Object(Obj).Angle.Y = object angle y(Object(Obj).Number)
Object(Obj).Angle.Z = object angle z(Object(Obj).Number)
endfunction 0
function Object_Rotate(Name$, X#, Y#, Z#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Rotate-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).Angle.X = Object(Obj).Angle.X + X#
Object(Obj).Angle.Y = Object(Obj).Angle.Y + Y#
Object(Obj).Angle.Z = Object(Obj).Angle.Z + Z#
rotate object Object(Obj).Number, Object(Obj).Angle.X, Object(Obj).Angle.Y, Object(Obj).Angle.Z
endfunction 0
function Object_Scale_Absolute_Down(Name$, S#)
rem Scales an object down by S percent
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Scale_Absolute_Down-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).Scale.X = Object(Obj).Scale.X - S#
if Object(Obj).Scale.X < 0
Object(Obj).Scale.X = 0
endif
Object(Obj).Scale.Y = Object(Obj).Scale.Y - S#
if Object(Obj).Scale.Y < 0
Object(Obj).Scale.Y = 0
endif
Object(Obj).Scale.Z = Object(Obj).Scale.Z - S#
if Object(Obj).Scale.Z < 0
Object(Obj).Scale.Z = 0
endif
scale object Object(Obj).Number, Object(Obj).Scale.X * 100, Object(Obj).Scale.Y * 100, Object(Obj).Scale.Z * 100
Object(Obj).Size.X = object size x(Object(Obj).Number)
Object(Obj).Size.Y = object size y(Object(Obj).Number)
Object(Obj).Size.Z = object size z(Object(Obj).Number)
endfunction 0
function Object_Scale_Absolute_Up(Name$, S#)
rem Scales an object up by S#
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Scale_Absolute_Up-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).Scale.X = Object(Obj).Scale.X + S#
if Object(Obj).Scale.X < 0
Object(Obj).Scale.X = 0
endif
Object(Obj).Scale.Y = Object(Obj).Scale.Y + S#
if Object(Obj).Scale.Y < 0
Object(Obj).Scale.Y = 0
endif
Object(Obj).Scale.Z = Object(Obj).Scale.Z + S#
if Object(Obj).Scale.Z < 0
Object(Obj).Scale.Z = 0
endif
scale object Object(Obj).Number, Object(Obj).Scale.X * 100, Object(Obj).Scale.Y * 100, Object(Obj).Scale.Z * 100
Object(Obj).Size.X = object size x(Object(Obj).Number)
Object(Obj).Size.Y = object size y(Object(Obj).Number)
Object(Obj).Size.Z = object size z(Object(Obj).Number)
endfunction 0
function Object_Scale_Relative_Down(Name$, S#)
rem Scales an object down by S percent of its current scaling values
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Scale_Relative_Down-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).Scale.X = Object(Obj).Scale.X - Object(Obj).Scale.X * S#
if Object(Obj).Scale.X < 0
Object(Obj).Scale.X = 0
endif
Object(Obj).Scale.Y = Object(Obj).Scale.Y - Object(Obj).Scale.Y * S#
if Object(Obj).Scale.Y < 0
Object(Obj).Scale.Y = 0
endif
Object(Obj).Scale.Z = Object(Obj).Scale.Z - Object(Obj).Scale.Z * S#
if Object(Obj).Scale.Z < 0
Object(Obj).Scale.Z = 0
endif
scale object Object(Obj).Number, Object(Obj).Scale.X * 100, Object(Obj).Scale.Y * 100, Object(Obj).Scale.Z * 100
Object(Obj).Size.X = object size x(Object(Obj).Number)
Object(Obj).Size.Y = object size y(Object(Obj).Number)
Object(Obj).Size.Z = object size z(Object(Obj).Number)
endfunction 0
function Object_Scale_Relative_Up(Name$, S#)
rem Scales an object up by S percent of its current scaling values
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Scale_Relative_Up-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).Scale.X = Object(Obj).Scale.X + Object(Obj).Scale.X * S#
if Object(Obj).Scale.X < 0
Object(Obj).Scale.X = 0
endif
Object(Obj).Scale.Y = Object(Obj).Scale.Y + Object(Obj).Scale.Y * S#
if Object(Obj).Scale.Y < 0
Object(Obj).Scale.Y = 0
endif
Object(Obj).Scale.Z = Object(Obj).Scale.Z + Object(Obj).Scale.Z * S#
if Object(Obj).Scale.Z < 0
Object(Obj).Scale.Z = 0
endif
scale object Object(Obj).Number, Object(Obj).Scale.X * 100, Object(Obj).Scale.Y * 100, Object(Obj).Scale.Z * 100
Object(Obj).Size.X = object size x(Object(Obj).Number)
Object(Obj).Size.Y = object size y(Object(Obj).Number)
Object(Obj).Size.Z = object size z(Object(Obj).Number)
endfunction 0
function Object_Set_Angle(Name$, X#, Y#, Z#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Set_Angle-->Error=Object not found " + Name$)
exitfunction -1
endif
rotate object Object(Obj).Number, X#, Y#, Z#
fix object pivot Object(Obj).Number
Object(Obj).Angle.X = object angle x(Object(Obj).Number)
Object(Obj).Angle.Y = object angle y(Object(Obj).Number)
Object(Obj).Angle.Z = object angle z(Object(Obj).Number)
endfunction 0
function Object_Set_Appearance(Name$, Wireframe, Transparent, Cull, Filter, Light, Fog, Ambient)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Set_Appearance-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).Appearance.Wireframe = Wireframe
Object(Obj).Appearance.Transparent = Transparent
Object(Obj).Appearance.Cull = Cull
Object(Obj).Appearance.Filter = Filter
Object(Obj).Appearance.Light = Light
Object(Obj).Appearance.Fog = Fog
Object(Obj).Appearance.Ambient = Ambient
if Object(Obj).Appearance.Wireframe > 0
W = 1
else
W = 0
endif
if Object(Obj).Appearance.Transparent > 0
T = 1
else
T = 0
endif
if Object(Obj).Appearance.Cull > 0
C = 1
else
C = 0
endif
if Object(Obj).Appearance.Filter > 0
Fl = 1
else
Fl = 0
endif
if Object(Obj).Appearance.Light > 0
L = 1
else
L = 0
endif
if Object(Obj).Appearance.Fog > 0
Fo = 1
else
Fo = 0
endif
if Object(Obj).Appearance.Ambient > 0
A = 1
else
A = 0
endif
set object Object(Obj).Number, W, T, C, Fl, L, Fo, A
endfunction 1
function Object_Set_Forward_Velocity(Name$, R#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Set_Forward_Velocity-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).ForwardVel = R#
endfunction 1
function Object_Set_Pitch_Rate(Name$, R#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Set_Pitch_Rate-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).PitchRate = R#
endfunction 1
function Object_Set_Position(Name$, X#, Y#, Z#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Set_Position-->Error=Object not found " + Name$)
exitfunction -1
endif
position object Object(Obj).Number, X#, Y#, Z#
Object(Obj).Position.X = X#
Object(Obj).Position.Y = Y#
Object(Obj).Position.Z = Z#
endfunction 0
function Object_Set_Roll_Rate(Name$, R#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Set_Roll_Rate-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).RollRate = R#
endfunction 1
function Object_Set_Rotation(Name$, X#, Y#, Z#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Set_Rotation-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).Rotation.X = X#
Object(Obj).Rotation.Y = Y#
Object(Obj).Rotation.Z = Z#
endfunction 0
function Object_Set_Scale(Name$, X#, Y#, Z#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Set_Scale-->Error=Object not found " + Name$)
exitfunction -1
endif
scale object Object(Obj).Number, X# * 100, Y# * 100, Z# * 100
Object(Obj).Scale.X = X#
Object(Obj).Scale.Y = Y#
Object(Obj).Scale.Z = Z#
Object(Obj).Size.X = object size x(Object(Obj).Number)
Object(Obj).Size.Y = object size y(Object(Obj).Number)
Object(Obj).Size.Z = object size z(Object(Obj).Number)
if Object().Size.X =< Object().Size.Y
if Object().Size.Y =< Object().Size.Z
Object().CollisionRadius = Object().Size.Z / 2
else
Object().CollisionRadius = Object().Size.Y / 2
endif
else
if Object().Size.X =< Object().Size.Z
Object().CollisionRadius = Object().Size.Z / 2
else
Object().CollisionRadius = Object().Size.X / 2
endif
endif
endfunction 0
function Object_Set_Specular_Color(Name$, Color)
Obj = Object_Number_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Set_Specular_Color-->Error=Object not found " + Name$)
exitfunction -1
endif
set object specular Obj, Color
endfunction 1
function Object_Set_Texture(Name$, Image)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Set_Texture-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).Texture.Image = Image
texture object Object(Obj).Number, Image
endfunction 0
function Object_Set_Texture_Mode(Name$, Wrap, Mode, Mip)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Set_Texture_Mode-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).Texture.WrapMode = Wrap
Object(Obj).Texture.MipMode = Mip
Object(Obj).Texture.MipEnable = Mip
if Object(Obj).Texture.MipEnable > 0
M = 1
else
M = 0
endif
set object texture Object(Obj).Number, Wrap, Mode, M
endfunction 1
function Object_Set_Velocity(Name$, X#, Y#, Z#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Set_Velocity-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).Velocity.X = X#
Object(Obj).Velocity.Y = Y#
Object(Obj).Velocity.Z = Z#
endfunction 0
function Object_Set_Yaw_Rate(Name$, R#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Set_Yaw_Rate-->Error=Object not found " + Name$)
exitfunction -1
endif
Object(Obj).YawRate = R#
endfunction 1
function Object_Show(Name$)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Show-->Error=Object not found " + Name$)
exitfunction -1.0
endif
show object Object(Obj).Number
endfunction 0.0
function Object_Update(Name$)
`Updates object movement and rotation based on its velocity and rotation values
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Update-->Error=Object not found " + Name$)
exitfunction -1.0
endif
move object Object(Obj).Number, Object(Obj).ForwardVel
move object up Object(Obj).Number, Object(Obj).VerticalVel
move object left Object(Obj).Number, Object(Obj).LateralVel
Object(Obj).Position.X = object position x(Object(Obj).Number) + Object(Obj).Velocity.X
Object(Obj).Position.Y = object position y(Object(Obj).Number) + Object(Obj).Velocity.Y
Object(Obj).Position.Z = object position z(Object(Obj).Number) + Object(Obj).Velocity.Z
X# = Object(Obj).Angle.X + Object(Obj).Rotation.X
Y# = Object(Obj).Angle.Y + Object(Obj).Rotation.Y
Z# = Object(Obj).Angle.Z + Object(Obj).Rotation.Z
position object Object(Obj).Number, Object(Obj).Position.X, Object(Obj).Position.Y, Object(Obj).Position.Z
rotate object Object(Obj).Number, X#, Y#, Z#
pitch object up Object(Obj).Number, Object(Obj).PitchRate
turn object left Object(Obj).Number, Object(Obj).YawRate
roll object left Object(Obj).Number, Object(Obj).RollRate
Object(Obj).Angle.X = object angle x(Object(Obj).Number)
Object(Obj).Angle.Y = object angle y(Object(Obj).Number)
Object(Obj).Angle.Z = object angle z(Object(Obj).Number)
endfunction 0.0
function Object_Yaw_Left(Name$, A#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Yaw_Left-->Error=Object not found " + Name$)
exitfunction -1
endif
turn object left Object(Obj).Number, A#
Object(Obj).Angle.X = object angle x(Object(Obj).Number)
Object(Obj).Angle.Y = object angle y(Object(Obj).Number)
Object(Obj).Angle.Z = object angle z(Object(Obj).Number)
endfunction 0
function Object_Yaw_Right(Name$, A#)
Obj = Object_Index_From_Name(Name$)
if Obj < 0
Error_Write("Object Manager-->Object_Yaw_Right-->Error=Object not found " + Name$)
exitfunction -1
endif
turn object right Object(Obj).Number, A#
Object(Obj).Angle.X = object angle x(Object(Obj).Number)
Object(Obj).Angle.Y = object angle y(Object(Obj).Number)
Object(Obj).Angle.Z = object angle z(Object(Obj).Number)
endfunction 0
And here is an example of how to use a few functions:
sync on
Object_Load("<insert .x object filename here>", "<insert name here>")
Object_Set_Rotation("<insert name here>", 0.0, 1.0, 0.0)
do
Object_Update("<insert name here>")
sync
loop
Comments and suggestions are welcome. I'll be posting a file with updates/additions as I make them at:
http://ixeelectronics.com/Development/Object_Manager_Functions.txt
There are a few fixes I need to make such as coding the rotation/velocity/ypr rates to be time-based rather than call-based.
Keep your Hope & Change to yourself, I choose Liberty! Stop by for a chat! [IXE]Nateholio on irc.maxgaming.net:6667 #GarageGames