You are on page 1of 8

--------------------------------------------------------------------------------Summary----------------------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------Properties----------------------------------------------------------------------------------------------------------------------------------------------------Author Defined Properties


----------------------------------property pAxisRotation -- String. Which axis (X,Y or Z) to rotate about.
property pModel --------- 3D model. Which model of the scene to rotate.
property pSpeed --------- Integer. The rate of rotation.
------------------------------------General Properties
----------------------------------property pMember -- Member. The member of this sprite.
property pModelTransformOriginList -- List. Contains the original starting trans
forms
-for each model.

---------------------------------------------------------------------------------Sprite Handlers---------------------------------------------------------------------------------------------------------------------------------------------on beginSprite(me)


pMember = sprite(me.spriteNum).member
if pMember.type = #text then
if pMember.displayMode = #modeNormal then
me.textTypeAlert()
exit
end if
end if
if voidP(pModel) then pModel = pMember.model[1].name
--pModel would be void if there is only one model in the scene.
if pModel = "Rotate All" then
pModelTransformOriginList = me.saveModelTransform(pMember, #all)
else
pModelTransformOriginList = me.saveModelTransform(pMember, pModel)
end if
end beginSprite
------------------------------------PURPOSE: General clean up.
--ACCEPTS: 'me' as an instance of this script.
--RETURNS: Nothing.
-----------------------------------

on endSprite(me)
me.setModelTransform(pModelTransformOriginList)
end endSprite

---------------------------------------------------------------------------------Event Handlers----------------------------------------------------------------------------------------------------------------------------------------------on enterFrame(me)


if pModel = "Rotate All" then
me.rotateAllModels()
else
me.rotateSingleModel()
end if
end enterFrame

---------------------------------------------------------------------------------Private Custom Handlers-------------------------------------------------------------------------------------------------------------------------------------on textTypeAlert(me)


tString1 = "The behavior indicated below requires that its text member's displ
ay be set to 3D Mode. " & \
"This sprite's member is not set that way. " & \
"Please correct this." & RETURN & RETURN
tString2= "Sprite" & ":" && string(me.spriteNum) & RETURN & RETURN
tString3 = "Behavior" & ":" && QUOTE & me.getScriptName() & QUOTE
alert(me.typeset(tString1 & tString2 & tString3))
end textTypeAlert
----------------------------------PURPOSE: Sets a model's transform to a previously stored value.
--ACCEPTS: 'me' as an instance of this script.
-'aModel' as a string indicating a specific model name. Or it is the
-symbol #all indicating that every model should be set.
--RETURNS: Nothing.
----------------------------------on resetModelTransform(me, aModel)
repeat with j = 1 to pModelTransformOriginList.count
tModel = pModelTransformOriginList.getPropAt(j)
pMember.model(tModel).transform = pModelTransformOriginList.getAt(j)
end repeat
end resetModelTransform

----------------------------------on rotateAllModels(me)
repeat with j = 1 to me.getModels(pMember, []).count
case pAxisRotation of
"X":
me.rotateX(j)
"Y":
me.rotateY(j)
"Z":
me.rotateZ(j)
end case
end repeat
end rotateAllModels
----------------------------------on rotateSingleModel(me)
case pAxisRotation of
"X":
me.rotateX(pModel)
"Y":
me.rotateY(pModel)
"Z":
me.rotateZ(pModel)
end case
end rotateSingleModel
----------------------------------on rotateX(me, aModel)
case pMember.type of
#text:
tCenterPointAndRadius = pMember.model[1].boundingSphere
tCenter = tCenterPointAndRadius[1]
pMember.model[1].rotate(tCenter, vector(1,0,0), pSpeed,#world)
otherwise:
pMember.model(aModel).rotate(pSpeed,0,0)
end case
end rotateX
--------------------------------on rotateY(me, aModel)
case pMember.type of
#text:
tCenterPointAndRadius = pMember.model[1].boundingSphere
tCenter = tCenterPointAndRadius[1]
pMember.model[1].rotate(tCenter, vector(0,1,0), pSpeed,#world)
otherwise:
pMember.model(aModel).rotate(0,pSpeed,0)
end case
end rotateY

--------------------------------on rotateZ(me, aModel)


case pMember.type of
#text:
tCenterPointAndRadius = pMember.model[1].boundingSphere
tCenter = tCenterPointAndRadius[1]
pMember.model[1].rotate(tCenter, vector(0,0,1), pSpeed,#world)
otherwise:
pMember.model(aModel).rotate(0,0,pSpeed)
end case
end rotateZ
----------------------------------PURPOSE: Saves a duplicate of a model's transform.
--ACCEPTS: 'me' as an instance of this script.
-'aModel' as a string indicating a specific model name. Or it is the
-symbol #all indicating that every model's transform should be saved.
--RETURNS: Nothing.
----------------------------------on saveModelTransform(me, aMember, aModel)
tModelTransformOriginList = [:]
tList = me.getModels(aMember, [])
if aModel = #all then
repeat with j in tList
tModelTransformOriginList.addProp(j, duplicate(aMember.model(j).transform)
)
end repeat
else
tModelTransformOriginList.addProp(aModel, duplicate(aMember.model(aModel).tr
ansform))
end if
return(tModelTransformOriginList)
end saveModelTransform
----------------------------------PURPOSE: Sets a model's transform to a previously stored value.
--ACCEPTS: 'me' as an instance of this script.
-'aList' as a property list. An element contains a model name
-and an associated transform.
--RETURNS: Nothing.
----------------------------------on setModelTransform(me, aList)
repeat with j = 1 to aList.count
tModel = aList.getPropAt(j)
pMember.model(tModel).transform = aList.getAt(j)
end repeat
end setModelTransform

---------------------------------------------------------------------------------Predefined Handlers-------------------------------------------------------------------------------------------------------------------------------------------PURPOSE: Determines whether the behavior can be dropped onto a sprite in the s
core.
--ACCEPTS: 'aScript' as a reference to a script member.
-'aSpriteType' as a symbol. It indicates the type of sprite attempting
---

to be dropped on to.
'aSpriteNum' as an integer. Indicates the channel of the sprite being

-dropped on to.
--RETURNS: True if the behavior is allowed to be dropped on the sprite or score,
-false otherwise.
----------------------------------on isOKtoAttach(aScript, aSpriteType, aSpriteNum)
case aSpriteType of
#Graphic:
case sprite(aSpriteNum).member.type of
#shockwave3d:
if aScript.getModels(sprite(aSpriteNum).member, []).count > 0 then
return(TRUE)
else
return(FALSE)
end if
#text:
if sprite(aSpriteNum).member.displayMode = #mode3D then
return(TRUE)
end if
end case
#script:
return(FALSE)
end case
return(FALSE)
end isOKtoAttach
------------------------------------PURPOSE: Allows the user a dialog box access to the behavior's properties.
--ACCEPTS: 'aScript' as a reference to a script member.
--RETURNS: 'TGPDList' as a property list containing author definable behavior pr
operties
----------------------------------on getPropertyDescriptionList(aScript)
if the currentSpriteNum > 0 then
tGPDList = [:]

tGPDList[#pSpeed] = \
[#comment:"Rotation speed",\
#format: #integer,\
#range:[#min:-20, #max:20],\
#default: 5]
tList = ["Rotate All"]
tList = aScript.getModels(sprite(the currentSpriteNum).member, tList)
if tList.count > 2 then
tGPDList[#pModel] = \
[#comment:"Which model?",\
#format: #string,\
#range: tList,\
#default: tList[1]]
else
nothing
--There is only one model in the member. So, don't offer a selection
--as to which model to rotate.
end if
tGPDList[#pAxisRotation] = \
[#comment:"Which axis to rotate about",\
#format: #string,\
#range:["X", \
"Y", \
"Z"],\
#default: "X"]
return(tGPDList)
end if
end getPropertyDescriptionList
------------------------------------PURPOSE: Provides a tooltip in the behavior library palette.
--ACCEPTS: 'aScript' as a reference to a script member.
--RETURNS: 'tString' as a string.
----------------------------------on getBehaviorToolTip(aScript)
tString1 = "Automatically rotates a model" & RETURN & RETURN
tString2 = "-" && "Type" && ":" && "Independent Action" & RETURN
tString3 = "-" && "Dependencies" && ":" && "None"
return(tString1 & tString2 & tString3)
end getBehaviorToolTip
------------------------------------PURPOSE: Provides a behavior description in the behavior inspector.
--ACCEPTS: 'aScript' as a reference to a script member.
--RETURNS: 'tString' as a string.
----------------------------------on getBehaviorDescription(aScript)
tString1 = "AUTOMATIC MODEL ROTATION" & RETURN & RETURN & \

"Automatically rotates a model about an axis. " & \


"For multiple axes, drop multiple instances of the " & QUOTE & "Automatic M
odel Rotation" & QUOTE & " behavior on the sprite and select the desired axes."
& RETURN & RETURN & \
"This independent behavior does not require a trigger." & RETURN & RETURN &
\
"ACTIONS AND THEIR REQUIRED TRIGGERS:" & RETURN & \
"- None " & RETURN & RETURN & \
"PARAMETERS:" & RETURN & \
"- None" & RETURN & RETURN & \
"PERMITTED SPRITE TYPES:" & RETURN & \
"- Shockwave 3D" & RETURN & \
"- 3D Text"
return(tString1)
end getBehaviorDescription

---------------------------------------------------------------------------------Predefined Handler Support------------------------------------------------------------------------------------------------------------------------------------PURPOSE: Gets the names of each model in a member.


--ACCEPTS: 'aScript' as a reference to a script member.
-'aMember' as a member.
-'aList' that will be used to store the names.
--RETURNS: 'aList' containing the model names.
----------------------------------on getModels(aScript, aMember, aList)
repeat with j = 1 to aMember.model.count
if string(aMember.model[j]) contains "model" then
aList.add(aMember.model[j].name)
end if
end repeat
return(aList)
end getModels
------------------------------------PURPOSE: Determine the name of this script.
--ACCEPTS: 'me' as an instance of this script.
--RETURNS: 'tName' as a string.
----------------------------------on getScriptName(me)
tScriptName = string(me.script)
tName = EMPTY
repeat with tWord = 2 to tScriptName.word.count
tName = tName && tScriptName.word[tWord]
end repeat
tName = tName.char[3..(tName.char.count) - 2]
return(tName)
end getScriptName

------------------------------------PURPOSE: Inserts RETURNs into a string so that the string is of a specific


-number of characters wide.
--ACCEPTS: 'aScript' as a reference to a script member.
-'aString' as a string to be formatted.
--RETURNS: 'tNewString' as a formatted string.
----------------------------------on typeSet(aScript, aString)
tCharLimit = 50 --Limit the character width to this value.
tTempChunk = aString.char[1..tCharLimit]
tNewString = EMPTY
repeat while tTempChunk <> EMPTY
tTempChunk = aString.char[1..tCharLimit]
--Grab a substring of length tCharLimit.
tCount = tTempChunk.char.count
if tTempChunk.char[tCharLimit] = " " then
--The substring ends with a space. So, there are no partial words.
tStopWord = tTempChunk.word.count
else if aString.char[tCharLimit + 1] = " " then
--The first character after the substring is a space.
--So, there are no partial words.
tStopWord = tTempChunk.word.count
else if tTempChunk.char.count < tCharLimit then
--The substring is shorted than tCharLimit characters so use
--the whole substring as is.
tStopWord = tTempChunk.word.count
else
--The string goes beyond tCharLimit characters and would break in the
--middle of a word as is. So, do not use the last word.
tStopWord = tTempChunk.word.count - 1
end if
tTempChunk = aString.word[1..tStopWord]
tNewString = tNewString & RETURN & tTempChunk
delete aString.word[1..tStopWord]
end repeat
return(tNewString)
end typeSet
----------------------------------------------------------------------------------------------------------------------------------------------------------------Do not alter or add to the comments and script below this point!
---------------------------------------------------------------------------------beginInterfaceBlock
--endInterfaceBlock

You might also like