Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
ee28e50f
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ee28e50f
编写于
3月 25, 2011
作者:
M
mrkam
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7027692: /applets/WireFrame demo needs to be improved
Reviewed-by: alexp
上级
b2f6b311
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
252 addition
and
195 deletion
+252
-195
src/share/demo/applets/WireFrame/Matrix3D.java
src/share/demo/applets/WireFrame/Matrix3D.java
+19
-9
src/share/demo/applets/WireFrame/ThreeD.java
src/share/demo/applets/WireFrame/ThreeD.java
+229
-182
src/share/demo/applets/WireFrame/example1.html
src/share/demo/applets/WireFrame/example1.html
+1
-1
src/share/demo/applets/WireFrame/example2.html
src/share/demo/applets/WireFrame/example2.html
+1
-1
src/share/demo/applets/WireFrame/example3.html
src/share/demo/applets/WireFrame/example3.html
+1
-1
src/share/demo/applets/WireFrame/example4.html
src/share/demo/applets/WireFrame/example4.html
+1
-1
未找到文件。
src/share/demo/applets/WireFrame/Matrix3D.java
浏览文件 @
ee28e50f
/*
/*
* Copyright (c) 1995, 20
06
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 20
11
, Oracle and/or its affiliates. All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
...
@@ -29,22 +29,23 @@
...
@@ -29,22 +29,23 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
*/
/*
*/
/** A fairly conventional 3D matrix object that can transform sets of
/** A fairly conventional 3D matrix object that can transform sets of
3D points and perform a variety of manipulations on the transform */
3D points and perform a variety of manipulations on the transform */
class
Matrix3D
{
class
Matrix3D
{
float
xx
,
xy
,
xz
,
xo
;
float
xx
,
xy
,
xz
,
xo
;
float
yx
,
yy
,
yz
,
yo
;
float
yx
,
yy
,
yz
,
yo
;
float
zx
,
zy
,
zz
,
zo
;
float
zx
,
zy
,
zz
,
zo
;
static
final
double
pi
=
3.14159265
;
static
final
double
pi
=
3.14159265
;
/** Create a new unit matrix */
/** Create a new unit matrix */
Matrix3D
()
{
Matrix3D
()
{
xx
=
1.0f
;
xx
=
1.0f
;
yy
=
1.0f
;
yy
=
1.0f
;
zz
=
1.0f
;
zz
=
1.0f
;
}
}
/** Scale by f in all dimensions */
/** Scale by f in all dimensions */
void
scale
(
float
f
)
{
void
scale
(
float
f
)
{
xx
*=
f
;
xx
*=
f
;
...
@@ -60,6 +61,7 @@ class Matrix3D {
...
@@ -60,6 +61,7 @@ class Matrix3D {
zz
*=
f
;
zz
*=
f
;
zo
*=
f
;
zo
*=
f
;
}
}
/** Scale along each axis independently */
/** Scale along each axis independently */
void
scale
(
float
xf
,
float
yf
,
float
zf
)
{
void
scale
(
float
xf
,
float
yf
,
float
zf
)
{
xx
*=
xf
;
xx
*=
xf
;
...
@@ -75,12 +77,14 @@ class Matrix3D {
...
@@ -75,12 +77,14 @@ class Matrix3D {
zz
*=
zf
;
zz
*=
zf
;
zo
*=
zf
;
zo
*=
zf
;
}
}
/** Translate the origin */
/** Translate the origin */
void
translate
(
float
x
,
float
y
,
float
z
)
{
void
translate
(
float
x
,
float
y
,
float
z
)
{
xo
+=
x
;
xo
+=
x
;
yo
+=
y
;
yo
+=
y
;
zo
+=
z
;
zo
+=
z
;
}
}
/** rotate theta degrees about the y axis */
/** rotate theta degrees about the y axis */
void
yrot
(
double
theta
)
{
void
yrot
(
double
theta
)
{
theta
*=
(
pi
/
180
);
theta
*=
(
pi
/
180
);
...
@@ -106,6 +110,7 @@ class Matrix3D {
...
@@ -106,6 +110,7 @@ class Matrix3D {
zy
=
Nzy
;
zy
=
Nzy
;
zz
=
Nzz
;
zz
=
Nzz
;
}
}
/** rotate theta degrees about the x axis */
/** rotate theta degrees about the x axis */
void
xrot
(
double
theta
)
{
void
xrot
(
double
theta
)
{
theta
*=
(
pi
/
180
);
theta
*=
(
pi
/
180
);
...
@@ -131,6 +136,7 @@ class Matrix3D {
...
@@ -131,6 +136,7 @@ class Matrix3D {
zy
=
Nzy
;
zy
=
Nzy
;
zz
=
Nzz
;
zz
=
Nzz
;
}
}
/** rotate theta degrees about the z axis */
/** rotate theta degrees about the z axis */
void
zrot
(
double
theta
)
{
void
zrot
(
double
theta
)
{
theta
*=
(
pi
/
180
);
theta
*=
(
pi
/
180
);
...
@@ -156,6 +162,7 @@ class Matrix3D {
...
@@ -156,6 +162,7 @@ class Matrix3D {
xy
=
Nxy
;
xy
=
Nxy
;
xz
=
Nxz
;
xz
=
Nxz
;
}
}
/** Multiply this matrix by a second: M = M*R */
/** Multiply this matrix by a second: M = M*R */
void
mult
(
Matrix3D
rhs
)
{
void
mult
(
Matrix3D
rhs
)
{
float
lxx
=
xx
*
rhs
.
xx
+
yx
*
rhs
.
xy
+
zx
*
rhs
.
xz
;
float
lxx
=
xx
*
rhs
.
xx
+
yx
*
rhs
.
xy
+
zx
*
rhs
.
xz
;
...
@@ -204,6 +211,7 @@ class Matrix3D {
...
@@ -204,6 +211,7 @@ class Matrix3D {
zy
=
0
;
zy
=
0
;
zz
=
1
;
zz
=
1
;
}
}
/** Transform nvert points from v into tv. v contains the input
/** Transform nvert points from v into tv. v contains the input
coordinates in floating point. Three successive entries in
coordinates in floating point. Three successive entries in
the array constitute a point. tv ends up holding the transformed
the array constitute a point. tv ends up holding the transformed
...
@@ -216,11 +224,13 @@ class Matrix3D {
...
@@ -216,11 +224,13 @@ class Matrix3D {
float
x
=
v
[
i
];
float
x
=
v
[
i
];
float
y
=
v
[
i
+
1
];
float
y
=
v
[
i
+
1
];
float
z
=
v
[
i
+
2
];
float
z
=
v
[
i
+
2
];
tv
[
i
]
=
(
int
)
(
x
*
lxx
+
y
*
lxy
+
z
*
lxz
+
lxo
);
tv
[
i
]
=
(
int
)
(
x
*
lxx
+
y
*
lxy
+
z
*
lxz
+
lxo
);
tv
[
i
+
1
]
=
(
int
)
(
x
*
lyx
+
y
*
lyy
+
z
*
lyz
+
lyo
);
tv
[
i
+
1
]
=
(
int
)
(
x
*
lyx
+
y
*
lyy
+
z
*
lyz
+
lyo
);
tv
[
i
+
2
]
=
(
int
)
(
x
*
lzx
+
y
*
lzy
+
z
*
lzz
+
lzo
);
tv
[
i
+
2
]
=
(
int
)
(
x
*
lzx
+
y
*
lzy
+
z
*
lzz
+
lzo
);
}
}
}
}
@Override
public
String
toString
()
{
public
String
toString
()
{
return
(
"["
+
xo
+
","
+
xx
+
","
+
xy
+
","
+
xz
+
";"
return
(
"["
+
xo
+
","
+
xx
+
","
+
xy
+
","
+
xz
+
";"
+
yo
+
","
+
yx
+
","
+
yy
+
","
+
yz
+
";"
+
yo
+
","
+
yx
+
","
+
yy
+
","
+
yz
+
";"
...
...
src/share/demo/applets/WireFrame/ThreeD.java
浏览文件 @
ee28e50f
/*
/*
* Copyright (c) 1995, 20
06
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 20
11
, Oracle and/or its affiliates. All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
...
@@ -29,28 +29,29 @@
...
@@ -29,28 +29,29 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
*/
/*
*/
/* A set of classes to parse, represent and display 3D wireframe models
represented in Wavefront .obj format. */
import
java.applet.Applet
;
import
java.applet.Applet
;
import
java.awt.Graphics
;
import
java.awt.Graphics
;
import
java.awt.Color
;
import
java.awt.Color
;
import
java.awt.Event
;
import
java.awt.event.*
;
import
java.awt.event.*
;
import
java.io.*
;
import
java.io.*
;
import
java.net.URL
;
import
java.net.URL
;
/* A set of classes to parse, represent and display 3D wireframe models
represented in Wavefront .obj format. */
@SuppressWarnings
(
"serial"
)
class
FileFormatException
extends
Exception
{
class
FileFormatException
extends
Exception
{
public
FileFormatException
(
String
s
)
{
public
FileFormatException
(
String
s
)
{
super
(
s
);
super
(
s
);
}
}
}
}
/** The representation of a 3D model */
/** The representation of a 3D model */
class
Model3D
{
final
class
Model3D
{
float
vert
[];
float
vert
[];
int
tvert
[];
int
tvert
[];
int
nvert
,
maxvert
;
int
nvert
,
maxvert
;
...
@@ -58,16 +59,16 @@ class Model3D {
...
@@ -58,16 +59,16 @@ class Model3D {
int
ncon
,
maxcon
;
int
ncon
,
maxcon
;
boolean
transformed
;
boolean
transformed
;
Matrix3D
mat
;
Matrix3D
mat
;
float
xmin
,
xmax
,
ymin
,
ymax
,
zmin
,
zmax
;
float
xmin
,
xmax
,
ymin
,
ymax
,
zmin
,
zmax
;
Model3D
()
{
Model3D
()
{
mat
=
new
Matrix3D
();
mat
=
new
Matrix3D
();
mat
.
xrot
(
20
);
mat
.
xrot
(
20
);
mat
.
yrot
(
30
);
mat
.
yrot
(
30
);
}
}
/** Create a 3D model by parsing an input stream */
/** Create a 3D model by parsing an input stream */
Model3D
(
InputStream
is
)
throws
IOException
,
FileFormatException
{
Model3D
(
InputStream
is
)
throws
IOException
,
FileFormatException
{
this
();
this
();
StreamTokenizer
st
=
new
StreamTokenizer
(
StreamTokenizer
st
=
new
StreamTokenizer
(
new
BufferedReader
(
new
InputStreamReader
(
is
,
"UTF-8"
)));
new
BufferedReader
(
new
InputStreamReader
(
is
,
"UTF-8"
)));
...
@@ -87,49 +88,61 @@ class Model3D {
...
@@ -87,49 +88,61 @@ class Model3D {
x
=
st
.
nval
;
x
=
st
.
nval
;
if
(
st
.
nextToken
()
==
StreamTokenizer
.
TT_NUMBER
)
{
if
(
st
.
nextToken
()
==
StreamTokenizer
.
TT_NUMBER
)
{
y
=
st
.
nval
;
y
=
st
.
nval
;
if
(
st
.
nextToken
()
==
StreamTokenizer
.
TT_NUMBER
)
if
(
st
.
nextToken
()
==
StreamTokenizer
.
TT_NUMBER
)
{
z
=
st
.
nval
;
z
=
st
.
nval
;
}
}
}
}
}
addVert
((
float
)
x
,
(
float
)
y
,
(
float
)
z
);
addVert
((
float
)
x
,
(
float
)
y
,
(
float
)
z
);
while
(
st
.
ttype
!=
StreamTokenizer
.
TT_EOL
&&
while
(
st
.
ttype
!=
StreamTokenizer
.
TT_EOL
&&
st
.
ttype
st
.
ttype
!=
StreamTokenizer
.
TT_EOF
)
!=
StreamTokenizer
.
TT_EOF
)
{
st
.
nextToken
();
st
.
nextToken
();
}
else
if
(
"f"
.
equals
(
st
.
sval
)
||
"fo"
.
equals
(
st
.
sval
)
||
"l"
.
equals
(
st
.
sval
))
{
}
}
else
if
(
"f"
.
equals
(
st
.
sval
)
||
"fo"
.
equals
(
st
.
sval
)
||
"l"
.
equals
(
st
.
sval
))
{
int
start
=
-
1
;
int
start
=
-
1
;
int
prev
=
-
1
;
int
prev
=
-
1
;
int
n
=
-
1
;
int
n
=
-
1
;
while
(
true
)
while
(
true
)
{
if
(
st
.
nextToken
()
==
StreamTokenizer
.
TT_NUMBER
)
{
if
(
st
.
nextToken
()
==
StreamTokenizer
.
TT_NUMBER
)
{
n
=
(
int
)
st
.
nval
;
n
=
(
int
)
st
.
nval
;
if
(
prev
>=
0
)
if
(
prev
>=
0
)
{
add
(
prev
-
1
,
n
-
1
);
add
(
prev
-
1
,
n
-
1
);
if
(
start
<
0
)
}
if
(
start
<
0
)
{
start
=
n
;
start
=
n
;
}
prev
=
n
;
prev
=
n
;
}
else
if
(
st
.
ttype
==
'/'
)
}
else
if
(
st
.
ttype
==
'/'
)
{
st
.
nextToken
();
st
.
nextToken
();
else
}
else
{
break
;
break
;
if
(
start
>=
0
)
}
}
if
(
start
>=
0
)
{
add
(
start
-
1
,
prev
-
1
);
add
(
start
-
1
,
prev
-
1
);
if
(
st
.
ttype
!=
StreamTokenizer
.
TT_EOL
)
}
if
(
st
.
ttype
!=
StreamTokenizer
.
TT_EOL
)
{
break
scan
;
break
scan
;
}
}
else
{
}
else
{
while
(
st
.
nextToken
()
!=
StreamTokenizer
.
TT_EOL
while
(
st
.
nextToken
()
!=
StreamTokenizer
.
TT_EOL
&&
st
.
ttype
!=
StreamTokenizer
.
TT_EOF
);
&&
st
.
ttype
!=
StreamTokenizer
.
TT_EOF
)
{
// no-op
}
}
}
}
}
}
}
is
.
close
();
is
.
close
();
if
(
st
.
ttype
!=
StreamTokenizer
.
TT_EOF
)
if
(
st
.
ttype
!=
StreamTokenizer
.
TT_EOF
)
{
throw
new
FileFormatException
(
st
.
toString
());
throw
new
FileFormatException
(
st
.
toString
());
}
}
}
/** Add a vertex to this model */
/** Add a vertex to this model */
int
addVert
(
float
x
,
float
y
,
float
z
)
{
int
addVert
(
float
x
,
float
y
,
float
z
)
{
int
i
=
nvert
;
int
i
=
nvert
;
if
(
i
>=
maxvert
)
if
(
i
>=
maxvert
)
{
if
(
vert
==
null
)
{
if
(
vert
==
null
)
{
maxvert
=
100
;
maxvert
=
100
;
vert
=
new
float
[
maxvert
*
3
];
vert
=
new
float
[
maxvert
*
3
];
...
@@ -139,18 +152,21 @@ class Model3D {
...
@@ -139,18 +152,21 @@ class Model3D {
System
.
arraycopy
(
vert
,
0
,
nv
,
0
,
vert
.
length
);
System
.
arraycopy
(
vert
,
0
,
nv
,
0
,
vert
.
length
);
vert
=
nv
;
vert
=
nv
;
}
}
}
i
*=
3
;
i
*=
3
;
vert
[
i
]
=
x
;
vert
[
i
]
=
x
;
vert
[
i
+
1
]
=
y
;
vert
[
i
+
1
]
=
y
;
vert
[
i
+
2
]
=
z
;
vert
[
i
+
2
]
=
z
;
return
nvert
++;
return
nvert
++;
}
}
/** Add a line from vertex p1 to vertex p2 */
/** Add a line from vertex p1 to vertex p2 */
void
add
(
int
p1
,
int
p2
)
{
void
add
(
int
p1
,
int
p2
)
{
int
i
=
ncon
;
int
i
=
ncon
;
if
(
p1
>=
nvert
||
p2
>=
nvert
)
if
(
p1
>=
nvert
||
p2
>=
nvert
)
{
return
;
return
;
if
(
i
>=
maxcon
)
}
if
(
i
>=
maxcon
)
{
if
(
con
==
null
)
{
if
(
con
==
null
)
{
maxcon
=
100
;
maxcon
=
100
;
con
=
new
int
[
maxcon
];
con
=
new
int
[
maxcon
];
...
@@ -160,6 +176,7 @@ class Model3D {
...
@@ -160,6 +176,7 @@ class Model3D {
System
.
arraycopy
(
con
,
0
,
nv
,
0
,
con
.
length
);
System
.
arraycopy
(
con
,
0
,
nv
,
0
,
con
.
length
);
con
=
nv
;
con
=
nv
;
}
}
}
if
(
p1
>
p2
)
{
if
(
p1
>
p2
)
{
int
t
=
p1
;
int
t
=
p1
;
p1
=
p2
;
p1
=
p2
;
...
@@ -168,50 +185,50 @@ class Model3D {
...
@@ -168,50 +185,50 @@ class Model3D {
con
[
i
]
=
(
p1
<<
16
)
|
p2
;
con
[
i
]
=
(
p1
<<
16
)
|
p2
;
ncon
=
i
+
1
;
ncon
=
i
+
1
;
}
}
/** Transform all the points in this model */
/** Transform all the points in this model */
void
transform
()
{
void
transform
()
{
if
(
transformed
||
nvert
<=
0
)
if
(
transformed
||
nvert
<=
0
)
{
return
;
return
;
if
(
tvert
==
null
||
tvert
.
length
<
nvert
*
3
)
}
tvert
=
new
int
[
nvert
*
3
];
if
(
tvert
==
null
||
tvert
.
length
<
nvert
*
3
)
{
tvert
=
new
int
[
nvert
*
3
];
}
mat
.
transform
(
vert
,
tvert
,
nvert
);
mat
.
transform
(
vert
,
tvert
,
nvert
);
transformed
=
true
;
transformed
=
true
;
}
}
/* Quick Sort implementation
/* Quick Sort implementation
*/
*/
private
void
quickSort
(
int
a
[],
int
left
,
int
right
)
private
void
quickSort
(
int
a
[],
int
left
,
int
right
)
{
{
int
leftIndex
=
left
;
int
leftIndex
=
left
;
int
rightIndex
=
right
;
int
rightIndex
=
right
;
int
partionElement
;
int
partionElement
;
if
(
right
>
left
)
if
(
right
>
left
)
{
{
/* Arbitrarily establishing partition element as the midpoint of
/* Arbitrarily establishing partition element as the midpoint of
* the array.
* the array.
*/
*/
partionElement
=
a
[
(
left
+
right
)
/
2
];
partionElement
=
a
[(
left
+
right
)
/
2
];
// loop through the array until indices cross
// loop through the array until indices cross
while
(
leftIndex
<=
rightIndex
)
while
(
leftIndex
<=
rightIndex
)
{
{
/* find the first element that is greater than or equal to
/* find the first element that is greater than or equal to
* the partionElement starting from the leftIndex.
* the partionElement starting from the leftIndex.
*/
*/
while
(
(
leftIndex
<
right
)
&&
(
a
[
leftIndex
]
<
partionElement
)
)
while
((
leftIndex
<
right
)
&&
(
a
[
leftIndex
]
<
partionElement
))
{
++
leftIndex
;
++
leftIndex
;
}
/* find an element that is smaller than or equal to
/* find an element that is smaller than or equal to
* the partionElement starting from the rightIndex.
* the partionElement starting from the rightIndex.
*/
*/
while
(
(
rightIndex
>
left
)
&&
while
((
rightIndex
>
left
)
&&
(
a
[
rightIndex
]
>
partionElement
))
{
(
a
[
rightIndex
]
>
partionElement
)
)
--
rightIndex
;
--
rightIndex
;
}
// if the indexes have not crossed, swap
// if the indexes have not crossed, swap
if
(
leftIndex
<=
rightIndex
)
if
(
leftIndex
<=
rightIndex
)
{
{
swap
(
a
,
leftIndex
,
rightIndex
);
swap
(
a
,
leftIndex
,
rightIndex
);
++
leftIndex
;
++
leftIndex
;
--
rightIndex
;
--
rightIndex
;
...
@@ -221,27 +238,27 @@ class Model3D {
...
@@ -221,27 +238,27 @@ class Model3D {
/* If the right index has not reached the left side of array
/* If the right index has not reached the left side of array
* must now sort the left partition.
* must now sort the left partition.
*/
*/
if
(
left
<
rightIndex
)
if
(
left
<
rightIndex
)
{
quickSort
(
a
,
left
,
rightIndex
);
quickSort
(
a
,
left
,
rightIndex
);
}
/* If the left index has not reached the right side of array
/* If the left index has not reached the right side of array
* must now sort the right partition.
* must now sort the right partition.
*/
*/
if
(
leftIndex
<
right
)
if
(
leftIndex
<
right
)
{
quickSort
(
a
,
leftIndex
,
right
);
quickSort
(
a
,
leftIndex
,
right
);
}
}
}
}
}
private
void
swap
(
int
a
[],
int
i
,
int
j
)
private
void
swap
(
int
a
[],
int
i
,
int
j
)
{
{
int
T
;
int
T
;
T
=
a
[
i
];
T
=
a
[
i
];
a
[
i
]
=
a
[
j
];
a
[
i
]
=
a
[
j
];
a
[
j
]
=
T
;
a
[
j
]
=
T
;
}
}
/** eliminate duplicate lines */
/** eliminate duplicate lines */
void
compress
()
{
void
compress
()
{
int
limit
=
ncon
;
int
limit
=
ncon
;
...
@@ -259,7 +276,6 @@ class Model3D {
...
@@ -259,7 +276,6 @@ class Model3D {
}
}
ncon
=
d
;
ncon
=
d
;
}
}
static
Color
gr
[];
static
Color
gr
[];
/** Paint this model to a graphics context. It uses the matrix associated
/** Paint this model to a graphics context. It uses the matrix associated
...
@@ -267,13 +283,14 @@ class Model3D {
...
@@ -267,13 +283,14 @@ class Model3D {
The next version of the browser should have double buffering,
The next version of the browser should have double buffering,
which will make this *much* nicer */
which will make this *much* nicer */
void
paint
(
Graphics
g
)
{
void
paint
(
Graphics
g
)
{
if
(
vert
==
null
||
nvert
<=
0
)
if
(
vert
==
null
||
nvert
<=
0
)
{
return
;
return
;
}
transform
();
transform
();
if
(
gr
==
null
)
{
if
(
gr
==
null
)
{
gr
=
new
Color
[
16
];
gr
=
new
Color
[
16
];
for
(
int
i
=
0
;
i
<
16
;
i
++)
{
for
(
int
i
=
0
;
i
<
16
;
i
++)
{
int
grey
=
(
int
)
(
170
*(
1
-
Math
.
pow
(
i
/
15.0
,
2.3
)));
int
grey
=
(
int
)
(
170
*
(
1
-
Math
.
pow
(
i
/
15.0
,
2.3
)));
gr
[
i
]
=
new
Color
(
grey
,
grey
,
grey
);
gr
[
i
]
=
new
Color
(
grey
,
grey
,
grey
);
}
}
}
}
...
@@ -281,17 +298,20 @@ class Model3D {
...
@@ -281,17 +298,20 @@ class Model3D {
int
lim
=
ncon
;
int
lim
=
ncon
;
int
c
[]
=
con
;
int
c
[]
=
con
;
int
v
[]
=
tvert
;
int
v
[]
=
tvert
;
if
(
lim
<=
0
||
nvert
<=
0
)
if
(
lim
<=
0
||
nvert
<=
0
)
{
return
;
return
;
}
for
(
int
i
=
0
;
i
<
lim
;
i
++)
{
for
(
int
i
=
0
;
i
<
lim
;
i
++)
{
int
T
=
c
[
i
];
int
T
=
c
[
i
];
int
p1
=
((
T
>>
16
)
&
0xFFFF
)
*
3
;
int
p1
=
((
T
>>
16
)
&
0xFFFF
)
*
3
;
int
p2
=
(
T
&
0xFFFF
)
*
3
;
int
p2
=
(
T
&
0xFFFF
)
*
3
;
int
grey
=
v
[
p1
+
2
]
+
v
[
p2
+
2
];
int
grey
=
v
[
p1
+
2
]
+
v
[
p2
+
2
];
if
(
grey
<
0
)
if
(
grey
<
0
)
{
grey
=
0
;
grey
=
0
;
if
(
grey
>
15
)
}
if
(
grey
>
15
)
{
grey
=
15
;
grey
=
15
;
}
if
(
grey
!=
lg
)
{
if
(
grey
!=
lg
)
{
lg
=
grey
;
lg
=
grey
;
g
.
setColor
(
gr
[
grey
]);
g
.
setColor
(
gr
[
grey
]);
...
@@ -303,128 +323,155 @@ class Model3D {
...
@@ -303,128 +323,155 @@ class Model3D {
/** Find the bounding box of this model */
/** Find the bounding box of this model */
void
findBB
()
{
void
findBB
()
{
if
(
nvert
<=
0
)
if
(
nvert
<=
0
)
{
return
;
return
;
}
float
v
[]
=
vert
;
float
v
[]
=
vert
;
float
xmin
=
v
[
0
],
xmax
=
xmin
;
float
_xmin
=
v
[
0
],
_xmax
=
_
xmin
;
float
ymin
=
v
[
1
],
ymax
=
ymin
;
float
_ymin
=
v
[
1
],
_ymax
=
_
ymin
;
float
zmin
=
v
[
2
],
zmax
=
zmin
;
float
_zmin
=
v
[
2
],
_zmax
=
_
zmin
;
for
(
int
i
=
nvert
*
3
;
(
i
-=
3
)
>
0
;)
{
for
(
int
i
=
nvert
*
3
;
(
i
-=
3
)
>
0
;)
{
float
x
=
v
[
i
];
float
x
=
v
[
i
];
if
(
x
<
xmin
)
if
(
x
<
_xmin
)
{
xmin
=
x
;
_xmin
=
x
;
if
(
x
>
xmax
)
}
xmax
=
x
;
if
(
x
>
_xmax
)
{
_xmax
=
x
;
}
float
y
=
v
[
i
+
1
];
float
y
=
v
[
i
+
1
];
if
(
y
<
ymin
)
if
(
y
<
_ymin
)
{
ymin
=
y
;
_ymin
=
y
;
if
(
y
>
ymax
)
}
ymax
=
y
;
if
(
y
>
_ymax
)
{
_ymax
=
y
;
}
float
z
=
v
[
i
+
2
];
float
z
=
v
[
i
+
2
];
if
(
z
<
zmin
)
if
(
z
<
_zmin
)
{
zmin
=
z
;
_zmin
=
z
;
if
(
z
>
zmax
)
}
zmax
=
z
;
if
(
z
>
_zmax
)
{
}
_zmax
=
z
;
this
.
xmax
=
xmax
;
}
this
.
xmin
=
xmin
;
}
this
.
ymax
=
ymax
;
this
.
xmax
=
_xmax
;
this
.
ymin
=
ymin
;
this
.
xmin
=
_xmin
;
this
.
zmax
=
zmax
;
this
.
ymax
=
_ymax
;
this
.
zmin
=
zmin
;
this
.
ymin
=
_ymin
;
this
.
zmax
=
_zmax
;
this
.
zmin
=
_zmin
;
}
}
}
}
/** An applet to put a 3D model into a page */
/** An applet to put a 3D model into a page */
@SuppressWarnings
(
"serial"
)
public
class
ThreeD
extends
Applet
public
class
ThreeD
extends
Applet
implements
Runnable
,
MouseListener
,
MouseMotionListener
{
implements
Runnable
,
MouseListener
,
MouseMotionListener
{
Model3D
md
;
Model3D
md
;
boolean
painted
=
true
;
boolean
painted
=
true
;
float
xfac
;
float
xfac
;
int
prevx
,
prevy
;
int
prevx
,
prevy
;
float
xtheta
,
ytheta
;
float
scalefudge
=
1
;
float
scalefudge
=
1
;
Matrix3D
amat
=
new
Matrix3D
(),
tmat
=
new
Matrix3D
();
Matrix3D
amat
=
new
Matrix3D
(),
tmat
=
new
Matrix3D
();
String
mdname
=
null
;
String
mdname
=
null
;
String
message
=
null
;
String
message
=
null
;
@Override
public
void
init
()
{
public
void
init
()
{
mdname
=
getParameter
(
"model"
);
mdname
=
getParameter
(
"model"
);
try
{
try
{
scalefudge
=
Float
.
valueOf
(
getParameter
(
"scale"
)).
floatValue
();
scalefudge
=
Float
.
valueOf
(
getParameter
(
"scale"
)).
floatValue
();
}
catch
(
Exception
e
){};
}
catch
(
Exception
ignored
)
{
// fall back to default scalefudge = 1
}
amat
.
yrot
(
20
);
amat
.
yrot
(
20
);
amat
.
xrot
(
20
);
amat
.
xrot
(
20
);
if
(
mdname
==
null
)
if
(
mdname
==
null
)
{
mdname
=
"model.obj"
;
mdname
=
"model.obj"
;
}
resize
(
getSize
().
width
<=
20
?
400
:
getSize
().
width
,
resize
(
getSize
().
width
<=
20
?
400
:
getSize
().
width
,
getSize
().
height
<=
20
?
400
:
getSize
().
height
);
getSize
().
height
<=
20
?
400
:
getSize
().
height
);
addMouseListener
(
this
);
addMouseListener
(
this
);
addMouseMotionListener
(
this
);
addMouseMotionListener
(
this
);
}
}
@Override
public
void
destroy
()
{
public
void
destroy
()
{
removeMouseListener
(
this
);
removeMouseListener
(
this
);
removeMouseMotionListener
(
this
);
removeMouseMotionListener
(
this
);
}
}
@Override
public
void
run
()
{
public
void
run
()
{
InputStream
is
=
null
;
InputStream
is
=
null
;
try
{
try
{
Thread
.
currentThread
().
setPriority
(
Thread
.
MIN_PRIORITY
);
Thread
.
currentThread
().
setPriority
(
Thread
.
MIN_PRIORITY
);
is
=
new
URL
(
getDocumentBase
(),
mdname
).
openStream
();
is
=
new
URL
(
getDocumentBase
(),
mdname
).
openStream
();
Model3D
m
=
new
Model3D
(
is
);
Model3D
m
=
new
Model3D
(
is
);
md
=
m
;
md
=
m
;
m
.
findBB
();
m
.
findBB
();
m
.
compress
();
m
.
compress
();
float
xw
=
m
.
xmax
-
m
.
xmin
;
float
xw
=
m
.
xmax
-
m
.
xmin
;
float
yw
=
m
.
ymax
-
m
.
ymin
;
float
yw
=
m
.
ymax
-
m
.
ymin
;
float
zw
=
m
.
zmax
-
m
.
zmin
;
float
zw
=
m
.
zmax
-
m
.
zmin
;
if
(
yw
>
xw
)
if
(
yw
>
xw
)
{
xw
=
yw
;
xw
=
yw
;
if
(
zw
>
xw
)
}
if
(
zw
>
xw
)
{
xw
=
zw
;
xw
=
zw
;
}
float
f1
=
getSize
().
width
/
xw
;
float
f1
=
getSize
().
width
/
xw
;
float
f2
=
getSize
().
height
/
xw
;
float
f2
=
getSize
().
height
/
xw
;
xfac
=
0.7f
*
(
f1
<
f2
?
f1
:
f2
)
*
scalefudge
;
xfac
=
0.7f
*
(
f1
<
f2
?
f1
:
f2
)
*
scalefudge
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
md
=
null
;
md
=
null
;
message
=
e
.
toString
();
message
=
e
.
toString
();
}
}
try
{
try
{
if
(
is
!=
null
)
if
(
is
!=
null
)
{
is
.
close
();
is
.
close
();
}
catch
(
Exception
e
)
{
}
}
catch
(
Exception
e
)
{
}
}
repaint
();
repaint
();
}
}
@Override
public
void
start
()
{
public
void
start
()
{
if
(
md
==
null
&&
message
==
null
)
if
(
md
==
null
&&
message
==
null
)
{
new
Thread
(
this
).
start
();
new
Thread
(
this
).
start
();
}
}
}
@Override
public
void
stop
()
{
public
void
stop
()
{
}
}
@Override
public
void
mouseClicked
(
MouseEvent
e
)
{
public
void
mouseClicked
(
MouseEvent
e
)
{
}
}
@Override
public
void
mousePressed
(
MouseEvent
e
)
{
public
void
mousePressed
(
MouseEvent
e
)
{
prevx
=
e
.
getX
();
prevx
=
e
.
getX
();
prevy
=
e
.
getY
();
prevy
=
e
.
getY
();
e
.
consume
();
e
.
consume
();
}
}
@Override
public
void
mouseReleased
(
MouseEvent
e
)
{
public
void
mouseReleased
(
MouseEvent
e
)
{
}
}
@Override
public
void
mouseEntered
(
MouseEvent
e
)
{
public
void
mouseEntered
(
MouseEvent
e
)
{
}
}
@Override
public
void
mouseExited
(
MouseEvent
e
)
{
public
void
mouseExited
(
MouseEvent
e
)
{
}
}
@Override
public
void
mouseDragged
(
MouseEvent
e
)
{
public
void
mouseDragged
(
MouseEvent
e
)
{
int
x
=
e
.
getX
();
int
x
=
e
.
getX
();
int
y
=
e
.
getY
();
int
y
=
e
.
getY
();
...
@@ -444,9 +491,11 @@ public class ThreeD extends Applet
...
@@ -444,9 +491,11 @@ public class ThreeD extends Applet
e
.
consume
();
e
.
consume
();
}
}
@Override
public
void
mouseMoved
(
MouseEvent
e
)
{
public
void
mouseMoved
(
MouseEvent
e
)
{
}
}
@Override
public
void
paint
(
Graphics
g
)
{
public
void
paint
(
Graphics
g
)
{
if
(
md
!=
null
)
{
if
(
md
!=
null
)
{
md
.
mat
.
unit
();
md
.
mat
.
unit
();
...
@@ -469,20 +518,18 @@ public class ThreeD extends Applet
...
@@ -469,20 +518,18 @@ public class ThreeD extends Applet
painted
=
true
;
painted
=
true
;
notifyAll
();
notifyAll
();
}
}
// private synchronized void waitPainted() {
// while (!painted)
// wait();
// painted = false;
// }
@Override
public
String
getAppletInfo
()
{
public
String
getAppletInfo
()
{
return
"Title: ThreeD \nAuthor: James Gosling? \nAn applet to put a 3D model into a page."
;
return
"Title: ThreeD \nAuthor: James Gosling? \n"
+
"An applet to put a 3D model into a page."
;
}
}
@Override
public
String
[][]
getParameterInfo
()
{
public
String
[][]
getParameterInfo
()
{
String
[][]
info
=
{
String
[][]
info
=
{
{
"model"
,
"path string"
,
"The path to the model to be displayed."
},
{
"model"
,
"path string"
,
"The path to the model to be displayed."
},
{
"scale"
,
"float"
,
"The scale of the model. Default is 1."
}
{
"scale"
,
"float"
,
"The scale of the model. Default is 1."
}
};
};
return
info
;
return
info
;
}
}
...
...
src/share/demo/applets/WireFrame/example1.html
浏览文件 @
ee28e50f
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<h1>
3D Model: Cube
</h1>
<h1>
3D Model: Cube
</h1>
<hr>
<hr>
<applet
code=
ThreeD.class
width=
100
height=
100
>
<applet
code=
ThreeD.class
width=
100
height=
100
>
<param
name=
model
value=
models/cube.obj
>
<param
name=
model
value=
"models/cube.obj"
>
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
Your browser is completely ignoring the
<
APPLET
>
tag!
Your browser is completely ignoring the
<
APPLET
>
tag!
</applet>
</applet>
...
...
src/share/demo/applets/WireFrame/example2.html
浏览文件 @
ee28e50f
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<h1>
3D Model: Dinosaur
</h1>
<h1>
3D Model: Dinosaur
</h1>
<hr>
<hr>
<applet
code=
ThreeD.class
width=
300
height=
300
>
<applet
code=
ThreeD.class
width=
300
height=
300
>
<param
name=
model
value=
models/dinasaur.obj
>
<param
name=
model
value=
"models/dinasaur.obj"
>
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
Your browser is completely ignoring the
<
APPLET
>
tag!
Your browser is completely ignoring the
<
APPLET
>
tag!
</applet>
</applet>
...
...
src/share/demo/applets/WireFrame/example3.html
浏览文件 @
ee28e50f
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<h1>
3D Model: Hughes
</h1>
<h1>
3D Model: Hughes
</h1>
<hr>
<hr>
<applet
code=
ThreeD.class
width=
300
height=
300
>
<applet
code=
ThreeD.class
width=
300
height=
300
>
<param
name=
model
value=
models/hughes_500.obj
>
<param
name=
model
value=
"models/hughes_500.obj"
>
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
Your browser is completely ignoring the
<
APPLET
>
tag!
Your browser is completely ignoring the
<
APPLET
>
tag!
</applet>
</applet>
...
...
src/share/demo/applets/WireFrame/example4.html
浏览文件 @
ee28e50f
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<h1>
3D Model: knoxS
</h1>
<h1>
3D Model: knoxS
</h1>
<hr>
<hr>
<applet
code=
ThreeD.class
width=
300
height=
300
>
<applet
code=
ThreeD.class
width=
300
height=
300
>
<param
name=
model
value=
models/knoxS.obj
>
<param
name=
model
value=
"models/knoxS.obj"
>
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
Your browser is completely ignoring the
<
APPLET
>
tag!
Your browser is completely ignoring the
<
APPLET
>
tag!
</applet>
</applet>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录