-
Notifications
You must be signed in to change notification settings - Fork 0
/
testphysics.html
92 lines (64 loc) · 2.86 KB
/
testphysics.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<html>
<head>
<script src="math.js"></script>
<script src="verb.js"></script>
<script src="physics.js"></script>
<script src="misc.js"></script>
<style> body { margin: 0; } </style>
</head>
<body>
<script>
//var wurst = new Vector2d(2,1,0);
//var ball = Object.create( phys_obj(wurst) );
//defineProp(ball,"radius", 2);
var tick = 0.5; //testing
var pos = new Vector2d(2,3,0);
var pos2 = new Vector2d(4,5,0);
var pos3 = new Vector2d(0,5,0);
var speed = new Vector2d(1,1,1);
var acc = new Vector2d(1,3,1);
var acc2 = new Vector2d(1,1,1);
var phys_objs = [];
var mat = new Material(0.8,0);
var circle = new Circle(2,pos,10,mat);
var circle2 = new Circle(1,pos3,10,mat);
var p1a = [-5,0,0], p2a = [0,0,0], p3a = [5,0,0];
var ptsa = [p1a, p2a, p3a];
var floor = new Environment(1,ptsa);
circle.speed = speed;
circle.acc =acc;
phys_objs.push(circle);
phys_objs.push(circle2);
var ellipse = new Ellipse(2,1,pos2,10,mat)
ellipse.speed = speed;
ellipse.acc =acc2;
phys_objs.push(ellipse);
phys_objs.push(floor);
var gravity = new Gravity();
var collision_handler = new CollisionHandler();
var t = circle instanceof Circle;
var s = circle instanceof Phys_obj;
//console.log(s,t,circle.pos,circle2.pos);
//circle.rotate();
var error_count = 0;
console.log("--------------------------------------------------------")
console.log("-------------------Test Physic functions----------------")
console.log("--------------------------------------------------------")
if(!circle.pos.compare_exact(pos) || t == false || s == false){error_count++; throw new Error('Circle inheritance error')};
console.log("Test circle inheritance: should true, true,[2,3,0] is :", t,s,circle.pos.x1,circle.pos.x2,circle.pos.x3);
circle.move();
if(!circle.pos.compare_exact(new Vector2d(2.625,3.875,0.625))){error_count++; throw new Error('Circle movement error')};
console.log("Test Circle movement: should [2.625,3.875,0.625] is :", circle.pos.x1,circle.pos.x2,circle.pos.x3);
gravity.on(phys_objs,-10); //turn gravity on !
console.log("------------Gravity acceleration is: " ,gravity.acc, "--------------");
move_phys_objs(phys_objs);
if(!circle.pos.compare_exact(new Vector2d(3.5,4.25,1.5))){error_count++; throw new Error('Circle gravity/movement error')};
console.log("Test Gravity: should [3.5,4.25,1.5] is :", circle.pos.x1,circle.pos.x2,circle.pos.x3);
console.log("Test Collision circle vs. env.: should [3.5,4.25,1.5] is :", circle.pos.x1,circle.pos.x2,circle.pos.x3);
console.log("--------------------------------------------------------")
console.log("---------------"+ error_count +" errors found in physics.js-------------")
console.log("--------------------------------------------------------")
//Testing functions:
</script>
</body>
</html>