flash中三维动画学习(关于类)
这几天认真学习了flash中,action script,虽然他无法与.net相比,不过同样是面对对象的语言,
实在是体会了这个思想的伟大,我是学习了Robert Peners的文章,现在负上一个试验,几个类的源码
,由于是初学,请见谅
在vectors.as中
只是定义几个关于坐标转换的function,但是实际的效果太出乎意料了,虽然我血flash才短短的11天
但是我已经被深深吸引了,有在c#的基础,action script实在太简单,学起来相当容易,毕竟他现在还不
是
真正面对对象的语言,不知道,我都快放弃.net了,要是大家有建议请告诉我,谢谢!!
请问asp.net能不能和flash产生交互,我只知道和php,能进行交互,在asp.net条件下,要是能行的话,就太好了
z这是三维的类
下载vectors.rar
实在是体会了这个思想的伟大,我是学习了Robert Peners的文章,现在负上一个试验,几个类的源码
,由于是初学,请见谅
在vectors.as中
只是定义几个关于坐标转换的function,但是实际的效果太出乎意料了,虽然我血flash才短短的11天
但是我已经被深深吸引了,有在c#的基础,action script实在太简单,学起来相当容易,毕竟他现在还不
是
真正面对对象的语言,不知道,我都快放弃.net了,要是大家有建议请告诉我,谢谢!!
请问asp.net能不能和flash产生交互,我只知道和php,能进行交互,在asp.net条件下,要是能行的话,就太好了
z这是三维的类
1
class vectors {
2
var x;
3
var y;
4
var z;
5
public function vectors(x, y, z) {
6
this.x = x;
7
this.y = y;
8
this.z = z;
9
}
10
//
11
function toString() {
12
var rx = Math.round(x*1000)/1000;
13
var ry = Math.round(y*1000)/1000;
14
var rz = Math.round(z*1000)/1000;
15
return "["+rx+","+ry+","+rz+"]";
16
}
17
//reset vector
18
function reset(x, y, z) {
19
this.x = x;
20
this.y = y;
21
// this.z=z;
22
}
23
/////I can't creat this way to clone
24
//
25
//
26
//
27
//function getClone()
28
//{var a;}
29
// compare two vector
30
function equal(v) {
31
return (this.x == v.x && this.y == y && this.z == z);
32
}
33
// put two vector in sum
34
function plus(v) {
35
this.x += v.x;
36
this.y += v.y;
37
this.z += v.z;
38
}
39
//show the result of the vector temperarily
40
function plusNew(v) {
41
return (this.x+v.x, this.y+y, this.z+z);
42
}
43
//a vector subtract form anothor vector
44
function minus(v) {
45
this.x -= v.x;
46
this.y -= v.y;
47
this.z -= v.z;
48
}
49
//show the result of the temperary vector
50
function minusNew(v) {
51
return (this.x-v.x && this.y-v.y && this.z-v.z);
52
}
53
// negator of the vector
54
function negate() {
55
this.x = -this.x;
56
this.y = -this.y;
57
this.z = -this.z;
58
}
59
//the temperary negator of the vector
60
function negateNew() {
61
with (this) {
62
return (-x, -y, -z);
63
}
64
}
65
//
66
//scale the model to this vector
67
function scale(s) {
68
this.x *= s;
69
this.y *= s;
70
this.z *= s;
71
}
72
function scaleNew(s) {
73
return (this.x*s, this.y*s, this.z*s);
74
}
75
// get length
76
function getLength() {
77
return (Math.sqrt(this.x*this+this.y*this.y+this.z*this.z));
78
}
79
//set length
80
function setlength(len) {
81
var r = this.getLength();
82
with (this) {
83
this.x *= (len/r);
84
this.y *= (len/r);
85
this.z *= (len/r);
86
}
87
}
88
//dot
89
function dot(v) {
90
return (this.x*v.x+this.y*v.x+this.z*v.z);
91
}
92
//cross to two vector
93
function cross(v) {
94
with (this) {
95
var cx = y*v.z-z*v.y;
96
var cy = z*v.x-x*v.z;
97
var cz = x*v.y-y*v.x;
98
}
99
return (new vectors(cx, cy, cz));
100
}
101
//get between angle
102
function angleBetween(v) {
103
var dp = this.dot(v);
104
var cosangle = Math.acos(this.getLength()*v.getlength()/dp);
105
return Math.acos(cosangle);
106
}
107
//get
108
function getPerspective(viewDist) {
109
if (viewDist == undefined) {
110
viewDist = 300;
111
}
112
return viewDist/(this.z+viewDist);
113
}
114
function persProject(p) {
115
if (p == undefined) {
116
p = this.getPerspective();
117
}
118
with (this) {
119
x *= p;
120
y *= p;
121
z = 0;
122
}
123
}
124
function persProjectNew(p) {
125
if (p == undefined) {
126
p = getPerspective();
127
}
128
with (this) {
129
return (new vectors(p*x, p*y, 0));
130
}
131
}
132
//rotate with x
133
function rotateX(angle) {
134
var ca = Math.cos(angle);
135
var sa = Math.sin(angle);
136
with (this) {
137
var temy = y*ca-z*sa;
138
var temz = y*sa+z*ca;
139
}
140
y = temy;
141
z = temz;
142
}
143
function rotateY(angle) {
144
var ca = Math.cos(angle);
145
var sa = Math.sin(angle);
146
with (this) {
147
var temz = z*ca-x*sa;
148
var temx = z*sa+x*ca;
149
}
150
x = temx;
151
z = temz;
152
}
153
function rotateZ(angle) {
154
var ca = Math.cos(angle);
155
var sa = Math.sin(angle);
156
with (this) {
157
var temx = x*ca-y*sa;
158
var temy = x*sa+y*ca;
159
}
160
y = temy;
161
x = temx;
162
}
163
function rotateXY(a, b) {
164
var ca = Math.cos(a);
165
var sa = Math.sin(a);
166
var cb = Math.cos(b);
167
var sb = Math.sin(b);
168
with (this) {
169
//with x rotate
170
y = y*ca-z*sa;
171
var rz = y*sa+z*ca;
172
z = x*(-sb)+rz*cb;
173
x = x*cb+rz*sb;
174
}
175
}
176
function rotateXYZ(a, b, c) {
177
with (Math) {
178
var ca = cos(a), sa = sin(a);
179
var cb = cos(b), sb = sin(b);
180
var cc = cos(c), sc = sin(c);
181
}
182
with (this)
183
{ //rotate with x
184
var ry = y*ca-z*sa;
185
var rz=y*sa+z*ca;
186
//rotate with y
187
z=rz*cb-x*sb;
188
var rx=x*sb+rz*cb;
189
//rotate with z
190
x=rx*cc-ry*sc
191
y=rx*sc+ry*cc;
192
193
}
194
}
195
function rotateXYZNew(a, b, c) {
196
with (Math) {
197
var ca = cos(a), sa = sin(a);
198
var cb = cos(b), sb = sin(b);
199
var cc = cos(c), sc = sin(c);
200
}
201
with (this)
202
{ //rotate with x
203
var ry = y*ca-z*sa;
204
var rz=y*sa+z*ca;
205
//rotate with y
206
z=rz*cb-x*sb;
207
var rx=x*sb+rz*cb;
208
//rotate with z
209
x=rx*cc-ry*sc
210
y=rx*sc+ry*cc;
211
212
}
213
214
}
215
}
216
class vectors {2
var x;3
var y;4
var z;5
public function vectors(x, y, z) {6
this.x = x;7
this.y = y;8
this.z = z;9
}10
//11
function toString() {12
var rx = Math.round(x*1000)/1000;13
var ry = Math.round(y*1000)/1000;14
var rz = Math.round(z*1000)/1000;15
return "["+rx+","+ry+","+rz+"]";16
}17
//reset vector18
function reset(x, y, z) {19
this.x = x;20
this.y = y;21
// this.z=z;22
}23
/////I can't creat this way to clone 24
//25
//26
//27
//function getClone()28
//{var a;}29
// compare two vector 30
function equal(v) {31
return (this.x == v.x && this.y == y && this.z == z);32
}33
// put two vector in sum34
function plus(v) {35
this.x += v.x;36
this.y += v.y;37
this.z += v.z;38
}39
//show the result of the vector temperarily40
function plusNew(v) {41
return (this.x+v.x, this.y+y, this.z+z);42
}43
//a vector subtract form anothor vector 44
function minus(v) {45
this.x -= v.x;46
this.y -= v.y;47
this.z -= v.z;48
}49
//show the result of the temperary vector50
function minusNew(v) {51
return (this.x-v.x && this.y-v.y && this.z-v.z);52
}53
// negator of the vector54
function negate() {55
this.x = -this.x;56
this.y = -this.y;57
this.z = -this.z;58
}59
//the temperary negator of the vector60
function negateNew() {61
with (this) {62
return (-x, -y, -z);63
}64
}65
//66
//scale the model to this vector67
function scale(s) {68
this.x *= s;69
this.y *= s;70
this.z *= s;71
}72
function scaleNew(s) {73
return (this.x*s, this.y*s, this.z*s);74
}75
// get length76
function getLength() {77
return (Math.sqrt(this.x*this+this.y*this.y+this.z*this.z));78
}79
//set length80
function setlength(len) {81
var r = this.getLength();82
with (this) {83
this.x *= (len/r);84
this.y *= (len/r);85
this.z *= (len/r);86
}87
}88
//dot89
function dot(v) {90
return (this.x*v.x+this.y*v.x+this.z*v.z);91
}92
//cross to two vector93
function cross(v) {94
with (this) {95
var cx = y*v.z-z*v.y;96
var cy = z*v.x-x*v.z;97
var cz = x*v.y-y*v.x;98
}99
return (new vectors(cx, cy, cz));100
}101
//get between angle102
function angleBetween(v) {103
var dp = this.dot(v);104
var cosangle = Math.acos(this.getLength()*v.getlength()/dp);105
return Math.acos(cosangle);106
}107
//get108
function getPerspective(viewDist) {109
if (viewDist == undefined) {110
viewDist = 300;111
}112
return viewDist/(this.z+viewDist);113
}114
function persProject(p) {115
if (p == undefined) {116
p = this.getPerspective();117
}118
with (this) {119
x *= p;120
y *= p;121
z = 0;122
}123
}124
function persProjectNew(p) {125
if (p == undefined) {126
p = getPerspective();127
}128
with (this) {129
return (new vectors(p*x, p*y, 0));130
}131
}132
//rotate with x133
function rotateX(angle) {134
var ca = Math.cos(angle);135
var sa = Math.sin(angle);136
with (this) {137
var temy = y*ca-z*sa;138
var temz = y*sa+z*ca;139
}140
y = temy;141
z = temz;142
}143
function rotateY(angle) {144
var ca = Math.cos(angle);145
var sa = Math.sin(angle);146
with (this) {147
var temz = z*ca-x*sa;148
var temx = z*sa+x*ca;149
}150
x = temx;151
z = temz;152
}153
function rotateZ(angle) {154
var ca = Math.cos(angle);155
var sa = Math.sin(angle);156
with (this) {157
var temx = x*ca-y*sa;158
var temy = x*sa+y*ca;159
}160
y = temy;161
x = temx;162
}163
function rotateXY(a, b) {164
var ca = Math.cos(a);165
var sa = Math.sin(a);166
var cb = Math.cos(b);167
var sb = Math.sin(b);168
with (this) {169
//with x rotate170
y = y*ca-z*sa;171
var rz = y*sa+z*ca;172
z = x*(-sb)+rz*cb;173
x = x*cb+rz*sb;174
}175
}176
function rotateXYZ(a, b, c) {177
with (Math) {178
var ca = cos(a), sa = sin(a);179
var cb = cos(b), sb = sin(b);180
var cc = cos(c), sc = sin(c);181
}182
with (this)183
{ //rotate with x184
var ry = y*ca-z*sa;185
var rz=y*sa+z*ca;186
//rotate with y187
z=rz*cb-x*sb;188
var rx=x*sb+rz*cb;189
//rotate with z190
x=rx*cc-ry*sc191
y=rx*sc+ry*cc;192
193
}194
}195
function rotateXYZNew(a, b, c) {196
with (Math) {197
var ca = cos(a), sa = sin(a);198
var cb = cos(b), sb = sin(b);199
var cc = cos(c), sc = sin(c);200
}201
with (this)202
{ //rotate with x203
var ry = y*ca-z*sa;204
var rz=y*sa+z*ca;205
//rotate with y206
z=rz*cb-x*sb;207
var rx=x*sb+rz*cb;208
//rotate with z209
x=rx*cc-ry*sc210
y=rx*sc+ry*cc;211
212
}213
214
}215
}216

下载vectors.rar



浙公网安备 33010602011771号