请大家先看右边的动画演示。这个动画就是由 jimbob 制作的,您可以到这里来下载这个动画的原始文件。下面请看他的详细解释:

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

initalise:
Comment:
Comment: 初始化全局变量
Set Variable: "pi" = 3 .1415
Set Variable: "worldRotX" = .496 //初始化旋转度
Set Variable: "worldRotY" = 5 .267
Set Variable: "centerx" = 160 //3D中心的X,Y位置
Set Variable: "centery" = 180
// 设置点的3D坐标值 用 ,分割XYZ R分割各个点
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 //点数
Start Drag ("/drag", lockcenter)
Comment:
Comment: 设置点位置
Set Variable: "inptsetstring" = ptsetstringA
Set Variable: "inshapename" = "cube"
Set Variable: "innumberofpts" = numberofpts
Call ("make matrix") //返回各个点的3D坐标如 cobe_01_x=50
// cobe_01_y=50
// cobe_01_z=-50
Comment:
Comment: 生成其余的光球
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: 获取当前鼠标位置
Set Variable: "Xm" = GetProperty ("/drag",_x)
Set Variable: "Ym" = GetProperty ("/drag",_y)
Comment: 获取当前跟踪位置
Set Variable: "Xf" = centerx
Set Variable: "Yf" = centery
Comment: 计算间隔并由加速度计算当前位置
Set Variable: "Sx" = Xm-Xf
Set Variable: "Sy" = Ym-Yf
Set Variable: "Xnew" = Xf+(Sx/50)
Set Variable: "Ynew" = Yf+(Sy/50)
Comment:
Comment: 设置旋转度
Comment:
Set Variable: "worldRotX" = worldRotX + (((Ym - Yf) /300)*0 .5)
// 根据鼠标位移来改变旋转度
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)
// 根据鼠标位移来改变旋转度
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") //获取转换后新点的3D坐标
// ? 如 cube_01_tx; cube_01_ty; cube_01_tz
Comment:
Comment: 画光球
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") //画出光球
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
// 根据旋转角度算出新的3D坐标
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") //根据3D坐标算出2D的x,y位置
Set Variable: "tmpAlpha" = eval("cube_"&eval("lightnum")&"_fa") //获得点的透明度
If (tmpAlpha > 12)
Set Property (WhichLight, Alpha) = tmpAlpha
Set Property (WhichLight, X Scale) = tmpAlpha //光球的放大倍数=透明度
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))
// z坐标影响线的深度
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
// 由深度取得透明度

make matrix:
Comment:
Comment: 设置点的3D坐标
Comment: 用 ,分割XYZ R分割各个点
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: //从字符串中取出sin值
Set Variable: "thetext" = "0 .0000 .0100 ... (中间数据略) ....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: //从字符串中取出cos值
Set Variable: "thetext" = "1 .0001 .0000 ... (中间数据略) ... .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

  有什么问题,请联系我们。

下载原始代码

转载于:https://www.cnblogs.com/savageworld/archive/2006/07/29/462702.html

3D 鼠标跟随脚本详解相关推荐

  1. 《Unity 3D 游戏开发技术详解与典型案例》——1.1节Unity 3D基础知识概览

    本节书摘来自异步社区<Unity 3D 游戏开发技术详解与典型案例>一书中的第1章,第1.1节Unity 3D基础知识概览,作者 吴亚峰 , 于复兴,更多章节内容可以访问云栖社区" ...

  2. sshd系统自带启动脚本详解

    SSH 为 Secure Shell 的缩写.sshd服务是linux系统中最经常使用的服务之一.由于其规避了明文传送口令.内容本文及中间人***的安全隐患,因此经常作为远程管理系统的首选方案.虽然各 ...

  3. 《Unity 3D 游戏开发技术详解与典型案例》——1.3节第一个Unity 3D程序

    本节书摘来自异步社区<Unity 3D 游戏开发技术详解与典型案例>一书中的第1章,第1.3节第一个Unity 3D程序,作者 吴亚峰 , 于复兴,更多章节内容可以访问云栖社区" ...

  4. shell脚本详解(十二)——Here Document免交互及Expect自动化交互

    shell脚本详解(十二)--Here Document免交互及Expect自动化交互 一.Here Document 免交互 1.格式 2.注意事项 3.免交互方式实现对行数的统计,将要统计的内容置 ...

  5. shell脚本详解(十)——sed编辑器的使用方法

    shell脚本详解(十)--sed编辑器的使用方法 一.sed编辑器 二.sed编辑器工作流程 1.读取: 2.执行: 3.显示: 4.注: 三.命令格式 四.常用选项 五.常用操作 六.使用地址 s ...

  6. shell脚本详解(九)——一键部署DNS正向解析

    shell脚本详解(九)--一键部署DNS正向解析 一.DNS正向解析 二.shell脚本一键部署 一.DNS正向解析 详情请点击:DNS正向解析 二.shell脚本一键部署 #!/bin/bash ...

  7. shell脚本详解(七)——正则表达式、sort、uniq、tr

    shell脚本详解(七)--正则表达式.sort.uniq.tr 一.排序命令--sort 1.格式 2.常用选项 3.示例 二.去除重复行操作命令--uniq 1.格式 2.常用选项 3.示例 三. ...

  8. shell脚本详解(六)——数组简介和排序算法

    shell脚本详解(六)--数组简介和排序算法 一.数组 1.数组的定义方法 ①.方式一: ②.方式二: ③.方式三: ④.方式四: 2.数组包括的数据类型 3.获取数组长度 4.获取数据列表 5.读 ...

  9. shell脚本详解(四)——循环语句之while循环和until循环(附加例题及解析)

    shell脚本详解(四)--循环语句之while循环和until循环 一.until循环 1.循环结构 2.例题 二.while循环 1.循环结构 2.例题(每个人的思路不同,会导致脚本内容不一样,这 ...

最新文章

  1. Linux UserSpace Back-Door、Rootkit SSH/PAM Backdoor Attack And Defensive Tchnology
  2. Nestjs OpenAPI(Swagger)
  3. Spring(2)——Spring IoC 详解
  4. 史上最全python字符串操作指南
  5. 使用gulp和vsc构建高效的typescript开发环境
  6. IOS调用WCF提供的服务方法,但是方法的参数是WCF那边自定义的对象,这样有办法调用么,如果可以IOS应该怎么传参呢?请问有了解的么,...
  7. 接口中私有方法【应用】
  8. 在存储过程中使用系统存储过程sp_Excute的注意事项
  9. python 近期用到的基础知识汇总(八)
  10. 在Javascript中实现类似C#中string.Format的功能
  11. 检验检测机构LIMS系统应用
  12. 如何在Excel里输入能打钩的选择框?
  13. **python入门实战**-华氏度转摄氏度python代码
  14. 上帝的答复(外两篇)
  15. 小学-知识与能力【7】
  16. 计算机专业买笔记本有什么要求,笔记本电脑什么配置好?硬核选购指南来了!...
  17. org.apache.mina.core.RuntimeIoException: Failed to get the session 异常可能出现的原因
  18. 十五、存储过程与函数
  19. Linux中history的巧用
  20. layout_weight 小白的理解之我的地盘听我的!(二)

热门文章

  1. 天池 在线编程 求和查找
  2. LeetCode 833. 字符串中的查找与替换(排序,replace)
  3. LeetCode 505. 迷宫 II(BFS / Dijkstra 最短路径)
  4. LeetCode 921. 使括号有效的最少添加(栈)
  5. LeetCode 1305. 两棵二叉搜索树中的所有元素(二叉树迭代器)
  6. LeetCode 1009. 十进制整数的反码(位运算)
  7. mac node oracle,将Python3.5(Mac OS X El Capitan)连接到Oracle集群(远程)
  8. java怎么递归_Java的递归、如何与流相结合
  9. mysql维护计划任务_浅谈MySQL event 计划任务
  10. Java实验方法参数传递与递归_4.3类的结构之二:方法(return,重载,可变个数形参,值传递,递归)...