Mailing List
Home
Forum Home
Softimage
Carrara
trueSpace
Dir3d-l
Maya - a powerful 3D animation and visual effects software
Macromedia Flash Development
Subjects
Subject: Cameras
Subject: scaleDown command
Subject: black out solved
Subject: Aircraft Tutorial
Subject: Mathematical XYZ ?
Subject: Re: Its done This vs That
Subject: Re: Its done first week
recommendations for screen video captures?
Subject: 3DExplorer "Oddity "
Subject: Re: New Director
Subject: ProTeam renewals
Fuel 's new websites (X post)
Blue peter create a make toy
targeting groups question
XPost: Shockwave 3D game ( sort of )
Subject: RES: RES: RES: Fish Modeling
Emitting particles from object intersection
Fuel 's new websites (X post)
Subject: Re: Texturing
Big Break Contest Videos
Subject: New Plugins
Models and Texture on my updated site
Error Installing Patch tS6 6
Subject: Plasma?
Looking for Inspiration
Subject: Weird EMail Q
Subject: Re: It 's done first week ?
Subject: Cherry not cranberry
Subject: Re: New game
Camera Animation Problem
Subject: Particle plugins?
 
Lightwave and Shockwave 3D

Lightwave and Shockwave 3D

2004-02-26       - By Thomas Williams

 Back
Reply:     1     2     3     4     5  

oops...
I left someting out in that script I just sent. (adding it to the actor
list)
this line should be inserted into the constructor
on new me
.... just before return
(the actorList).append(me)
return me
end



for your conveniece I put the entire corrected script below

=======================================================================

-- CameraRotateZoom
-- OOP Camera Controller.

-- Input: the camera to be controlled

-- Usage:
-- this scsript rotates the camera around the center of the world.
-- Also features ease in motion. This will be implemented by using a buffer
variable that will
-- store incremented mouse change. This in turn will be used to rotate a
controller dummy model.
-- The camera is parented to a dummy group.
-- Rotation will be triggered by the user holding down the <control> key.
-- Zoom will be triggered by the user holding down the <shift>   key.
-- Elevation mode is triggered by holding down both the <control> and the
<shift> key

-- Implementation:
-- In the init script, add these lines.
-- Name this script "CameraControl"
-- Make sure it is a Parent script.
--  -- Create a camera control object.
--  gCameraControl = script("CameraControl").new(scene.camera[1])
--  (the actorList).append(gCameraControl)

global scene
global gCameraControl -- reference the instance of this class.
-- Use this as a global variable in the initialize movie script to reference
an instance of this class..
global gNavMode -- string: indicates the current navigation mode. Options
are Rotate,Zoom,Elevate.


property pRotateBufferX -- the amount of rotation that remains to be done.
Mouse action adds to this, rotation subtracts.
property pRotateBufferY -- the amount of rotation that remains to be done.
Mouse action adds to this
property pZoomBuffer  -- the amount of zooming that remains to be done.
property pElevBuffer  -- the amount of elevating that remains to be done.
property pCamera
property pMouseOld -- a reference to the last mouse loc
property pMouseIsDown -- boolean used to determine if this is the mouse has
just benn clicked.
property pInterpPercent --  a factor that determines how much of the
pRotateBuffer the camera will rotate.
property pCameraMagnitude -- the distance from the camera to the dummy.
property pZoomLimit -- the range in vector magniture the the camera may zoom
in and out.
property pFriction -- a list of min and max values that limit the amount of
spin after user lets go. 0 means spin forever. 1 is normal
property pZoomLag -- the interpolation factor for zooming. 0 is infinite
lag, 1 is no lag.
property pDummyCamInitialTransform --  the transform of the camera
controller dummy at world start.
property pCamInitialTransform --  the transform of the camera controller
dummy at world start.
property pDummy_cam_Rot_old -- float: the recorded trandoform.rotation.x of
model("dummy_camera_Plane")
property pWM -- the model that will be the world Master. All models will be
parented to it.
property pInitialWMTransform -- the initial transform of the world master,
after it is adjusted to face camera.

on new me,mCamera
 pCamera = mCamera -- the camera
 -- Dummy_camera: Interpolates to Dummy_mouse. the camera is parented to
this.
 if voidP(scene.group("Cam_Master")) then
   pWM = scene.newGroup("Cam_Master")
 else
   pWM = scene.Group("Cam_Master")
 end if

 -- Set initial rotation of the Dummy camera to be the same as the camera,
then reset the position to the origin..
 pWM.transform = pCamera.transform
 pWM.transform.position = vector(0,0,0)
 pWM.translate(0,30,0)
 pInitialWMTransform =  pWM.transform.duplicate()

 -- Parent the camera to the "Dummy_camera"
 pWM.addChild(pCamera,#preserveWorld)
 pRotateBufferX = 0
 pRotateBufferY = 0
 pZoomBuffer = 0
 pMouseIsDown = 0
 pCameraMagnitude = (pCamera.worldPosition- pWM.worldPosition).magnitude
 pZoomLimit = [pCameraMagnitude*.3,pCameraMagnitude*2]
 pInterpPercent  = .2
 pFriction = .5
 -- point the camera at the dummy
 pCamera.pointat( pWM.worldposition)
 -- Record the initial transforms of the camera and its dummys to be used
later in camera reset.
 pCamInitialTransform = pCamera.transform.duplicate()
 pDummyCamInitialTransform =  pWM.transform.duplicate()
 pZoomLag = .2
 pDummy_cam_Rot_old = pDummyCamInitialTransform.rotation.x
 pInit = 1
(the actorList).append(me)

 -- This line makes the mouse rotate the world. This shows off the
reflection maps as the glide over the models.
 -- create a World Master model that will be the parent of all the objects
in the scene.
 --pWM = createPlane("World Master".100,100,rgb(150,255,0))

 -- parent all the models you want to spin to the world master
 --  repeat with m = 1 to scene.model.count
 --    if scene.model[m].name contains "Dummy" then
 --      nothing
 --    else
 --      pWM.addchild(scene.model(m),#preserveWorld)
 --    end if
 --  end repeat

 return me

end

---*************************************************************************
*****

on stepFrame me

 mouseDif = the mouseloc - me.pMouseOld

 -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----
 -- Set the Navigation mode by trapping key Press events.
 -- <Shift> induces rotate mode,
 -- <control> induces zoom mode,
 -- <Shift> and <Zoom> induce elevate mode.
 if the shiftDown = true then
   gNavMode = "Rotate"
 end if
 if the controlDown = true then
   gNavMode = "Zoom"
 end if
 if the controlDown = true and the shiftDown = true then
   gNavMode = "Elevate"
 end if

 -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----
 --ROTATE only when mouse and control are down
 if gNavMode = "Rotate" and the mouseDown = 1 then

   -- set the mouseOld to the mouse if the mouse was just clicked.
   if  me.pMouseIsDown = 0 then  me.pMouseOld = the mouseloc

   AmpAdjust = .33
   RotX = mouseDif[1]*AmpAdjust
   RotY = mouseDif[2]*AmpAdjust

   me.pRotateBufferX = me.pRotateBufferX + RotX
   me.pRotateBufferY = me.pRotateBufferY + RotY

   -- Set the MouseIsDown flag to on
   me.pMouseIsDown = 1
   pInterpPercent = .2
   RotAngleX = me.pRotateBufferX*pInterpPercent
   RotAngleY = me.pRotateBufferY*pInterpPercent

   -- Interpolate the DummyCamera to the DummyMouse
   rotateCamera(me,RotAngleX,RotAngleY)

   -- reduce the rotation buffer by the amount rotated
   me.pRotateBufferX = me.pRotateBufferX - RotAngleX
   me.pRotateBufferY = me.pRotateBufferY - RotAngleY

 else

   RotAngleX = me.pRotateBufferX*pInterpPercent
   RotAngleY = me.pRotateBufferY*pInterpPercent
   -- Interpolate the DummyCamera to the DummyMouse
   rotateCamera(me,RotAngleX,RotAngleY)

   me.pMouseIsDown = 0

   -- reduce the rotation buffer by the amount rotated
   me.pRotateBufferX = me.pRotateBufferX - RotAngleX*me.pFriction
   me.pRotateBufferY = me.pRotateBufferY - RotAngleY*me.pFriction
 end if

 --  -- ---- ---- ---- ---- ---- ------
 -- Zoom
 -- get the distance of the camera to the dummy
 me.pCameraMagnitude = (pCamera.worldPosition- pWM.worldPosition).magnitude

 if gNavMode = "Zoom" and the mouseDown = 1  then

   AmpAdjust = 1
   ZoomRaw = mouseDif[2]*AmpAdjust
   me.pZoomBuffer = me.pZoomBuffer + ZoomRaw

   -- Set the MouseIsDown flag to on
   me.pMouseIsDown = 1

   -- Zoom the camera
   Zoom = me.pZoomBuffer * me.pZoomLag
   --    if checkLimits(Zoom) then
   me.pCamera.translate(0,0,-Zoom)
   --    else
   --      limitRange()
   --    end if

 else
   -- Zoom the camera
   Zoom = me.pZoomBuffer * me.pZoomLag
   -- if checkLimits(Zoom) then
   me.pCamera.translate(0,0,-Zoom)
   --    else
   --      limitRange()
   --    end if

   me.pMouseIsDown = 0
 end if

 -- reduce the rotation buffer by the amount rotated
 me.pZoomBuffer = me.pZoomBuffer - Zoom

 -- ---- ---- ---- ---- ---- ------
 -- Elevate
 if gNavMode = "Elevate" and the mouseDown = 1 then

   AmpAdjust = .5
   ElevRaw = mouseDif[2]*AmpAdjust
   me.pElevBuffer = me.pElevBuffer + ElevRaw

   -- Set the MouseIsDown flag to on
   me.pMouseIsDown = 1

   -- Zoom the camera
   Elev = me.pElevBuffer * me.pZoomLag
   -- if checkLimits(Elev) then
   me. pWM.translate(0,Elev,0,#world)
   -- else
   -- limitRange()
   -- end if

 else
   -- Zoom the camera
   Elev = me.pElevBuffer * me.pZoomLag
   --    if checkLimits(Elev) then
   me. pWM.translate(0,Elev,0,#world)
   --    else
   --      limitRange()
   --    end if

   me.pMouseIsDown = 0
 end if
 -- reduce the elevation buffer by the amount rotated
 me.pElevBuffer = me.pElevBuffer - Elev
 --if me.pElevBuffer < 0 then me.pElevBuffer = 0

 -- ---- ---- ---- ---- ---- ------
 --set the MouseOld
 me.pMouseOld = the mouseloc

end

--***********************************************************
-- Rotate the camera to catch up with the dummy
on rotateCamera me, RotAngleX, RotAngleY
 --put "RotAngleY",RotAngleY
 pWM.rotate(-RotAngleY,0,0,#world)
 pWM.rotate(0,-RotAngleX,0,#world)
end

--***********************************************************

on limitRange me

 cam = me.pCamera
 --place the camera within its limits
 -- ------
 --Far
 if me.pCameraMagnitude < me.pZoomLimit[1]  then
   -- reset the zoomBuffer
   me.pZoomBuffer = 0
   CamMagnitudefactor = me.pZoomLimit[1].float/me.pCameraMagnitude+.001
   cam.transform.position = CamMagnitudefactor*cam.transform.position
 end if

 -- ------
 --Near
 if me.pCameraMagnitude > me.pZoomLimit[2] then
   -- reset the zoomBuffer
   me.pZoomBuffer = 0
   CamMagnitudefactor = me.pZoomLimit[2].float/me.pCameraMagnitude-.001
   cam.transform.position = CamMagnitudefactor*cam.transform.position

 end if
end

--***********************************************************

on checkLimits ( me,zoom)
 mResult = 0
 -- get the new position that the camera will be in on the next step
 newCamPos = me.pCamera.transform.position + vector(0,0,-zoom)
 --and test to see if it is within the limits
 if newCamPos.magnitude > me.pZoomLimit[1] and \
newCamPos.magnitude < me.pZoomLimit[2] then
   mResult = 1
 end if
 return mResult
end

--***********************************************************

on checkForBreakthrough ( me,zoom,percent)
 mResult = 1
 if me.pPositionHistory.count > 1 then
   -- get the new position that the camera will be in on the next step
   newCamPos = me.pCamera.transform.position + vector(0,0,-zoom)
   --and test to see if it is within the limits
   -- Near the min
   --    if newCamPos.magnitude < me.pZoomLimit[1]+ pRangeMag*.01*percent
then
   mResult = 0
 end if
 -- near the max
 if newCamPos.magnitude > me.pZoomLimit[2]- me.pRangeMag*.01*percent then
   mResult = 0
 end if

 --  return mResult
end


--***********************************************************
on resetView me
 -- resets the camera and dummy to their initial settings
 global gInterpolateNode -- List that conatins child objects that control
the interpolation animation for various nodes

 -- Animate the camera to move to the origin.

 transformList =
[scene.model("Dummy_camera_Plane").transform,pInitialWMTransform]
 --put transformList[1].position
 -- transformList[2].position
 speed = 10
 AnimIndex =  gInterpolateNode.count + 1
 node = scene.model("Dummy_camera_Plane")
 -- move the camera back to its start position.
 --on new                                                (me, node,
transformList,speed,indx,restriction)
 --gInterpolateNode[AnimIndex] = new (script "InterpolateNode",
node,transformList,speed,AnimIndex,0)
 -- Move the World Master back to it's original orientation.
 node = pWM
 transformList = [pWM.transform,pInitialWMTransform]
 AnimIndex =  gInterpolateNode.count + 1
 gInterpolateNode[AnimIndex] = new (script "InterpolateNode",
node,transformList,speed,AnimIndex,0)

 -- move the camera to its initial position
 AnimIndex =  gInterpolateNode.count + 1
 node = pCamera
 transformList = [pCamera.transform,pCamInitialTransform]
 gInterpolateNode[AnimIndex] = new (script "InterpolateNode",
node,transformList,speed,AnimIndex,0)

end









__ ____ ____ ____ ____ ____ ____ ____ ____ ____
Dir3d-l mailing list
Dir3d-l@(protected)
http://nuttybar.drama.uga.edu/mailman/listinfo/dir3d-l