3D mouse follow script details

Source: Internet
Author: User
Tags scalar

Let's take a look at the animation demonstration on the right. This animation is made by jimbob. You can download the original file of this animation here. See his detailed explanation below:

If Frame Is Loaded ("end ")
Go to and Play ("start ")
End Frame Loaded

Initalise:
Comment:
Comment: Initialize global variables
Set Variable: "pi" = 1415.
Set Variable: "worldRotX" =. 496 // initialize the Rotation
Set Variable: "worldRotY" = 267.
Set Variable: "centerx" = 160 // location of X and Y in the 3D Center
Set Variable: "centery" = 180
// Set the 3D coordinate value of a vertex. Separate xyz r to separate each vertex.
Set Variable: "ptsetstringA" = "40, 40,-40R-40, 40,-40R-40,-40,-40R40,-40,-40R40, 40, 40R-40, 40, 40R-40, -40, 40R40,-40, 40R"
Set Variable: "numberofpts" = 8 // points
Start Drag ("/drag", lockcenter)
Comment:
Comment: Set the vertex location
Set Variable: "inptsetstring" = ptsetstringA
Set Variable: "inshapename" = "cube"
Set Variable: "innumberofpts" = numberofpts
Call ("make matrix") // returns the 3D coordinates of each point, for example, cobe_01_x = 50.
// Cobe_01_y = 50
// Cobe_01_z =-50
Comment:
Comment: Generate other light balls
Set Variable: "counter" = 1
Loop While (counter <> numberofpts)
Set Variable: "counter" = counter + 1
Duplicate Movie Clip ("light1", "light" & counter, counter + 10)
End Loop

Display stars:
Comment:
Comment: Get the current mouse position
Set Variable: "Xm" = GetProperty ("/drag", _ x)
Set Variable: "Ym" = GetProperty ("/drag", _ y)
Comment: Get the current tracking location
Set Variable: "Xf" = centerx
Set Variable: "Yf" = centery
Comment: calculates the interval and calculates the current position based on the acceleration.
Set Variable: "Sx" = Xm-Xf
Set Variable: "Sy" = Ym-Yf
Set Variable: "Xnew" = Xf + (Sx/50)
Set Variable: "Ynew" = Yf + (Sy/50)
Comment:
Comment: sets the degree of rotation.
Comment:
Set Variable: "worldRotX" = worldRotX + (Ym-Yf)/300) * 0. 5)
// Change the Rotation Degree Based on the mouse shift
If (worldRotX> (2 * pi ))
Set Variable: "worldRotX" = worldRotX-(2 * pi)
End If
If (worldRotX <0)
Set Variable: "worldRotX" = worldRotX + (2 * pi)
End If
Set Variable: "worldRotY" = worldRotY-(Xm-Xf)/400) * 0. 5)
// Change the Rotation Degree Based on the mouse shift
If (worldRotY> (2 * pi ))
Set Variable: "worldRotY" = worldRotY-(2 * pi)
End If
If (worldRotY <0)
Set Variable: "worldRotY" = worldRotY + (2 * pi)
End If
Call ("spinXY") // obtain the 3D coordinates of the new point after conversion.
//? For example, cube_01_tx; cube_01_ty; cube_01_tz
Comment:
Comment: Draw a light ball
Comment:
Set Variable: "counter" = 0
Loop While (counter <> numberofpts)
Set Variable: "counter" = counter + 1
Set Variable: "lightnum" = "0" & counter
Set Variable: "WhichLight" = "light" & counter
Call ("display light") // draw a light ball
End Loop
Set Variable: "centerx" = Xnew
Set Variable: "centery" = Ynew

Loop back:
Go to and Play ("display stars ")

SpinXY:
If (worldRotX> 0)
Set Variable: "tmpX" = worldRotX
Set Variable: "tmpX" = Substring (tmpX, 1, 1) & Substring (tmpX, 3, 2)
Set Variable: "sinX" = eval ("/sin: sin" & tmpX)
Else
Set Variable: "tmpX" = worldRotX
Set Variable: "tmpX" = Substring (tmpX, 2, 1) & Substring (tmpX, 4, 2)
Set Variable: "sinX" = 0-eval ("/sin: sin" & tmpX)
End If
If (worldRotY> 0)
Set Variable: "tmpY" = (worldRotY + 10. 0001)
Set Variable: "tmpY" = Substring (tmpY, 2, 1) & Substring (tmpY, 4, 2)
Set Variable: "sinY" = eval ("/sin: sin" & tmpY)
Else
Set Variable: "tmpY" = (worldRotY-10. 0001)
Set Variable: "tmpY" = Substring (tmpY, 3, 1) & Substring (tmpY, 5, 2)
Set Variable: "sinY" = 0-eval ("/sin: sin" & tmpY)
End If
Set Variable: "cosX" = eval ("/cos: cos" & tmpX)
Set Variable: "cosY" = eval ("/cos: cos" & tmpY)
Set Variable: "counter" = 0
Loop While (counter <> numberofpts)
Set Variable: "counter" = counter + 1
Set Variable: "in" = counter
If (length (in) = 1)
Set Variable: "in" = "0" & in
End If
// Calculate the new 3D coordinates based on the Rotation Angle
Set Variable: "tmp_zpos" = eval ("cube _" & in & "_ z") * cosY-eval ("cube _" & in & "_ x") * sinY
Set Variable: "cube _" & in & "_ tx" = eval ("cube _" & in & "_ z ") * sinY + eval ("cube _" & in & "_ x") * cosY
Set Variable: "cube _" & in & "_ tz" = eval ("cube _" & in & "_ y") * sinX + tmp_zpos * cosX
Set Variable: "cube _" & in & "_ ty" = eval ("cube _" & in & "_ y") * cosX-tmp_zpos * sinX
End Loop

Display line:
Call ("make 2d pointset") // calculate the position of x and y in 2D based on 3D coordinates.
Set Variable: "tmpAlpha" = eval ("cube _" & eval ("lightnum") & "_ fa") // obtain the vertex transparency
If (tmpAlpha> 12)
Set Property (WhichLight, Alpha) = tmpAlpha
Set Property (WhichLight, X Scale) = tmpAlpha // magnification of the optical sphere = transparency
Set Property (WhichLight, Y Scale) = tmpAlpha
Set Property (WhichLight, X Position) = eval ("cube _" & eval ("lightnum") & "_ fx ")
Set Property (WhichLight, Y Position) = eval ("cube _" & eval ("lightnum") & "_ fy ")
Set Property (WhichLight, Visibility) = 1
Else
Set Property (WhichLight, Visibility) = 0
End If

Make 2d pointset:
Set Variable: "scalar" = (1/(eval ("cube _" & lightnum & "_ tz")/300 + 1 ))
// Zcoordinate influence line depth
Set Variable: "xp" = scalar * eval ("cube _" & lightnum & "_ tx ")
Set Variable: "yp" = scalar * eval ("cube _" & lightnum & "_ ty ")
Set Variable: "cube _" & lightnum & "_ fx" = xp + Xnew
Set Variable: "cube _" & lightnum & "_ fy" = yp + Ynew
Set Variable: "cube _" & lightnum & "_ fa" = (scalar-. 7) * 133) + 20
// Transparency is achieved by Depth

Make matrix:
Comment:
Comment: Set the 3D coordinates of a vertex.
Comment: use, to split xyz r to separate points
Set Variable: "whichOne" = 1
Set Variable: "whichchar" = 0
Set Variable: "tmpstring" = ""
Loop While (whichOne <> (innumberofpts + 1 ))
Set Variable: "letter" = whichOne
If (Length (letter) = 1)
Set Variable: "letter" = "0" & letter
End If
Set Variable: "whichXYZ" = "x"
Set Variable: "loopy" = "0"
Loop While (loopy <> 1)
Set Variable: "whichchar" = whichchar + 1
If (Ord (substring (inptsetstring, whichchar, 1) = 82)
Set Variable: "loopy" = 1
Set Variable: "whichOne" = whichOne + 1
Else If (Ord (substring (inptsetstring, whichchar, 1) = 44)
Set Variable: "tmpstring" = ""
If (whichXYZ eq "x ")
Set Variable: "whichXYZ" = "y"
Else If (whichXYZ eq "y ")
Set Variable: "whichXYZ" = "z"
End If
Else
Set Variable: "tmpstring" & whichXYZ = eval ("tmpstring" & whichXYZ) & substring (inptsetstring, whichchar, 1)
End If
End Loop
Set Variable: inshapename & "_" & letter & "_ x" = tmpstringx
Set Variable: inshapename & "_" & letter & "_ y" = tmpstringy
Set Variable: inshapename & "_" & letter & "_ z" = tmpstringz
Set Variable: "tmpstringx" = ""
Set Variable: "tmpstringy" = ""
Set Variable: "tmpstringz" = ""
End Loop

MC sin: // retrieves the sin value from the string
Set Variable: "thetext" = "0. 0000. 0100... (the intermediate data is omitted)... 01-0. 00"
Set Variable: "counter" =-1
Loop While (counter< 629)
Set Variable: "counter" = counter + 1
If (length (counter) = 1)
Set Variable: "tmpName" = "sin" & "00" & counter
Else If (length (counter) = 2)
Set Variable: "tmpName" = "sin" & "0" & counter
Else If (length (counter) = 3)
Set Variable: "tmpName" = "sin" & counter
End If
Set Variable: tmpName = substring (thetext, (counter * 5) + 1, 5)
End Loop

MC cos: // extract the cos value from the string
Set Variable: "thetext" = "1. 0001. 0000... (the intermediate data is omitted)... 9991. 000"
Set Variable: "counter" =-1
Loop While (counter< 629)
Set Variable: "counter" = counter + 1
If (length (counter) = 1)
Set Variable: "tmpName" = "cos" & "00" & counter
Else If (length (counter) = 2)
Set Variable: "tmpName" = "cos" & "0" & counter
Else If (length (counter) = 3)
Set Variable: "tmpName" = "cos" & counter
End If
Set Variable: tmpName = substring (thetext, (counter * 5) + 1, 5)
End Loop

If you have any questions, please contact us.

Download original code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.