-- WALKABOUT CAMERA BEHAVIOR -- -- -- © September 2001, James Newton -- -- This behavior allows the user to move the camera by dragging the -- mouse. -- -- Dragging horizontally rotates the camera around its y-axis. -- Dragging from one side of the sprite to the other will make a -- complete 360° turn. -- -- Dragging the mouse up or down dollies the camera forwards or -- backwards along its z-axis. A minimum movement of 10 pixels is -- required to start this dolly movement. -- PROPERTY DECLARATIONS -- property solidModels -- names of models that should appear solid property cubeSize -- size of box model around the camera -- property pCamera -- Camera used by this sprite property pfPixelAngle -- Angle rotated when mouse is moved 1 pixel property piLastH -- Horizontal loc of mouse on last exitFrame property piClickV -- Vertical loc where user clicked on the sprite -- SPRITE EVENT -- on beginSprite(me) me.mInitialize() end beginSprite -- EVENT HANDLERS -- on mouseDown(me) ----------------------------------------------------- -- Allows the user to manipulate the camera with the arrow and other -- keys -------------------------------------------------------------------- piLastH = the mouseH piClickV = the mouseV end mouseDown on exitFrame(me) ----------------------------------------------------- -- Allows the user to manipulate the camera with the arrow and other -- keys -------------------------------------------------------------------- if piClickV then if the mouseDown then me.mMoveCamera() else -- the user has just released the mouse piLastH = VOID piClickV = VOID end if end if end exitFrame -- PRIVATE METHODS -- on mInitialize(me) --------------------------------------------------- -- Called by beginSprite() -- -- ACTION: -- * Creates a box model of the chosen size and makes the current -- sprite a camera its child -- * Adds the collision modifier in mesh mode to the box model plus -- any models which have been chosen in the Behavior Parameters -- dialog. -------------------------------------------------------------------- tSprite = sprite(me.spriteNum) tMember = tSprite.member -- Create a box model with a unique name of the appropriate size tName = string(me) tName = " is a pointer to the sprite to which this behavior is -- attached -- -- RETURNS: a string containing the names of all the models which -- should have the collision modifier attached to them, delimited -- by the character "," -------------------------------------------------------------------- tModelNames = "" tMember = aSprite.member i = tMember.model.count repeat while i put ","&tMember.model(i).name before tModelNames i = i - 1 end repeat delete tModelNames.char[1] return tModelNames end mGetModelNames on mGetModelList(me, aMember) --------------------------------------- -- Called by mInitialize() -- -- INPUT: -- is the member this behavior is attached to -- -- RETURNS: a list of models whose names were selected in the -- Behavior Parameters dialog -------------------------------------------------------------------- tModelList = [] tDelimiter = the itemDelimiter the itemDelimiter = "," i = solidModels.item.count repeat while i tName = solidModels.item[i] tModel = aMember.model(tName) if ilk(tModel) <> #model then -- The user may have added one or more spaces after the comma repeat while tName starts " " delete tName.char[1] end repeat tModel = aMember.model(tName) end if if ilk(tModel, #model) then tModelList.append(tModel) end if i = i - 1 end repeat the itemDelimiter = tDelimiter return tModelList end mGetModelList -- BEHAVIOR PARAMETERS AND DESCRIPTION -- on isOKToAttach(me, aSpriteType, aSpriteNumber) if aSpriteType = #graphic then return sprite(aSpriteNumber).member.type = #shockwave3D end if return FALSE end isOKToAttach on getPropertyDescriptionList(me) tPropertyList = [:] if not the currentSpriteNum then exit end if tModelNames = me.mGetModelNames(sprite(the currentSpriteNum)) -- Create a random symbol so that a full list of all model names -- is displayed each time in the lower field, regardless of how the -- user last edited them tRandomSymbol = symbol("_"&the ticks) tPropertyList[ \ #solidModels] = [ \ #comment: "Attach Collision Modifier to models (full list below)", \ #format: #string, \ #default: tModelNames \ ] tPropertyList[ \ tRandomSymbol] = [ \ #comment: "", \ #format: #string, \ #default: tModelNames \ ] tPropertyList[ \ #cubeSize] = [ \ #comment: "Size of cube around camera", \ #format: #integer, \ #range: [#min: 1, #max: 100], \ #default: 4 \ ] return tPropertyList end getPropertyDescriptionList on getBehaviorTooltip(me) return \ "Use with Shockwave 3D sprites only."&RETURN&RETURN&\ "Allows the user to walk through a world using"&RETURN&\ "the mouse without walking through solid objects." end getBehaviorTooltip on getBehaviorDescription(me) return \ "WALKTHROUGH CAMERA BEHAVIOR"&RETURN&RETURN&\ "Use with Shockwave 3D sprites to allow the user to walk through a world using the mouse without walking through solid objects."&RETURN&RETURN&\ "Clicking on the sprite and dragging upwards moves the camera forwards, dragging downwards moves the camera back. Dragging to one side rotates the camera."&RETURN&RETURN&\ "PARAMETERS:"&RETURN&\ " * Names of models that the camera cannot move through"&RETURN&\ " * Size of box around the camera."&RETURN&RETURN&\ "If you find that collisions are not correctly detected, try increasing the size of the cube around the camera" end getBehaviorDescription