<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script type="text/javascript" src="js/Silverlight.js"></script>
<script type="text/javascript" src="js/ball3d.1.1.js"></script>
</head>
<body>
<div id="wpfe">
<div id="wpfeHost" class="host"> </div>
<script type="text/javascript">
Sys.Silverlight.createObjectEx(
{
source: 'assets/ball_n.xaml',
parentElement: document.getElementById("wpfeHost"),
id: 'wpfeBlock',
properties:
{
width:'500',
height:'500',
background:'white',
isWindowless:'false',
framerate:'200',
version:'0.95.0'
},
events:
{
onError:null,
onLoad:null
},
context:null
}
);
</script>
</div>
<script language="JavaScript">
var startOnLoad = true;
var isLoaded = false;
var numBalls = 4;
var wpfeRoot;
var mouseData = null;
function changeNumberOfBalls(n) {
startOnLoad = true;
numBalls = n;
_wpfeTest.stop();
}
/**
* Silverlight (WPF/e) Balls test
*
* @param {Object} N
*/
function WPFETest(N) {
WPFETest.baseConstructor.call(this, N);
this._wpfeBlock = document.getElementById("wpfeBlock");
}
extend(WPFETest, BallsTest);
WPFETest.prototype.start = function(N) {
if (!WPFETest.base.start.call(this, N)) return;
this._savedXaml = this._wpfeBlock.source;
this._ballsO[0] = new WPFEBall(this._wpfeBlock, "wpfe_ball_0");
for (var i=1; i<this._N; i++) {
this._ballsO[i] = this._ballsO[0].clone("wpfe_ball_" + i);
}
this_ = this;
model.walls.makeWalls = function() {
model.walls.shapes = [];
var wall = new WPFEFace(this_._wpfeBlock, wpfeRoot,
[
[this.minx, 0, 0],
[this.maxx, 0, 0],
[0, this.maxy*Math.tan(60*Math.PI/180), 0]
]
);
wall._elem.fill = "#990000FF";
model.walls.shapes.push(wall);
wall = new WPFEFace(this_._wpfeBlock, wpfeRoot,
[
[this.minx, 0, 0],
[this.maxx, 0, 0],
[(this.minx+this.maxx)/3, this.maxy*Math.tan(60*Math.PI/180)/3, this.maxx*Math.tan(60*Math.PI/180)]
]
);
wall._elem.fill = "#99FF0000";
model.walls.shapes.push(wall);
wall = new WPFEFace(this_._wpfeBlock, wpfeRoot,
[
[this.maxx, 0, 0],
[0, this.maxy*Math.tan(60*Math.PI/180), 0],
[(this.minx+this.maxx)/3, this.maxy*Math.tan(60*Math.PI/180)/3, this.maxx*Math.tan(60*Math.PI/180)]
]
);
wall._elem.fill = "#9900FF00";
model.walls.shapes.push(wall);
wall = new WPFEFace(this_._wpfeBlock, wpfeRoot,
[
[this.minx, 0, 0],
[this.maxx, 0, 0],
[(this.minx+this.maxx)/3, this.maxy*Math.tan(60*Math.PI/180)/3, this.maxx*Math.tan(60*Math.PI/180)/2]
]
);
wall._elem.fill = "#99FFFF00";
model.walls.shapes.push(wall);
wall = new WPFEFace(this_._wpfeBlock, wpfeRoot,
[
[this.maxx, 0, 0],
[0, this.maxy*Math.tan(60*Math.PI/180), 0],
[(this.minx+this.maxx)/3, this.maxy*Math.tan(60*Math.PI/180)/3, this.maxx*Math.tan(60*Math.PI/180)/2]
]
);
wall._elem.fill = "#9900FFFF";
model.walls.shapes.push(wall);
wall = new WPFEFace(this_._wpfeBlock, wpfeRoot,
[
[0, this.maxy*Math.tan(60*Math.PI/180), 0],
[(this.minx+this.maxx)/3, this.maxy*Math.tan(60*Math.PI/180)/3, this.maxx*Math.tan(60*Math.PI/180)],
[(this.minx+this.maxx)/3, this.maxy*Math.tan(60*Math.PI/180)/3, this.maxx*Math.tan(60*Math.PI/180)/2]
]
);
wall._elem.fill = "#9900FFFF";
model.walls.shapes.push(wall);
}
model.walls.makeWalls();
}
WPFETest.prototype.stop = function(){
if (!WPFETest.base.stop.call(this)) return;
this._wpfeBlock.source = this._savedXaml;
isLoaded = false;
}
WPFETest.prototype._moveBalls = function(fps) {
/*
*/
this._ballsO = this._ballsO.sort(
function(a, b) {
return b.p.scale - a.p.scale;
}
);
// rotate it unless user moves the mouse
if (!mouseData)
this._angleY += 0.005;
model.setPOV(this._angleZ, this._angleY, this._distance);
}
WPFETest.prototype.setPOV = function(z, y) {
this._angleZ = z;
this._angleY = y;
model.setPOV(this._angleZ, this._angleY, this._distance);
}
WPFETest.prototype._gravity = false;
WPFETest.prototype.gravitySwitch = function() {
if (! this._gravity) {
model.gravity = -0.2; model.elastity = 0.8;
} else {
model.gravity = 0; model.elastity = 0.0;
}
this._gravity = !this._gravity;
}
var _wpfeTest = new WPFETest(numBalls);
// called from <Canvas ... Loaded="javascript:wpfeLoaded">
function wpfeLoaded(sender) {
//alert("hello");
wpfeRoot = sender;
if (startOnLoad) {
_wpfeTest.start(numBalls);
startOnLoad = false;
}
isLoaded = true;
}
function onMouseMove(sender, eventArgs) {
if (!mouseData) return;
var pt = eventArgs.getPosition(null);
var dy = (pt.y - mouseData.e.y)/200;
var dx = (pt.x - mouseData.e.x)/200;
_wpfeTest.setPOV(mouseData.start.z + dy, mouseData.start.y + dx);
}
function onLeftButtonDown(sender, eventArgs) {
sender.captureMouse();
mouseData = new Object();
mouseData.start = {"z":_wpfeTest._angleZ,"y":_wpfeTest._angleY};
mouseData.e = eventArgs.getPosition(null);
}
function onLeftButtonUp(sender) {
sender.releaseMouseCapture();
mouseData = null;
}
</script>
</body>
</html>