-
Notifications
You must be signed in to change notification settings - Fork 0
/
diagram_renderer.js
94 lines (76 loc) · 2.4 KB
/
diagram_renderer.js
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
93
94
function draw()
{
var canvas = document.getElementById("canvas"), ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
visibles = 0;
for(var t=0; t < myObjects.length; t++)
{
// only scale and draw an Object that can be seen i.e inside Frustrum and dot product >=0. Also that no div z = 0
if(myObjects[t].visibility)
{
Triangle_Helper.scaleProject(myObjects[t]);
if(Triangle_Helper.windowCheck(myObjects[t]))
{
Triangle_Helper.drawSelf(ctx, myObjects[t]);
visibles++;
}
}
}
}
function dot(ctx, p1, r, color, color1)
{
ctx.beginPath();
ctx.arc(p1.x, p1.y, r, 0, my360);
ctx.fillStyle = color;
ctx.lineWidth = 2;
ctx.strokeStyle = color1;
ctx.closePath();
ctx.fill();
ctx.stroke();
}
function drawLine(ctx, p1, p2, color, thickness)
{
ctx.beginPath();
ctx.moveTo(p1.x, p1.y);
ctx.lineTo(p2.x, p2.y);
ctx.strokeStyle = color;
ctx.lineWidth = thickness;
ctx.stroke();
}
function drawTri( ctx, points, fillColor, type, shade) // from cube only
{
ctx.strokeStyle = "black";
ctx.lineWidth = 1;
ctx.fillStyle = "rgb("+
colors[fillColor][0] * shade + "," + colors[fillColor][1] * shade + "," + colors[fillColor][2] * shade +")"; // fillColor;
ctx.beginPath();
ctx.moveTo(points[0].x, points[0].y);
for(var j=1; j<3; j++)
ctx.lineTo(points[j].x, points[j].y);
ctx.lineTo(points[0].x, points[0].y);
ctx.closePath();
if(type=="filled")
ctx.fill();
ctx.stroke();
}
/* 0 black= 000
1 blue = 001
2 green 010
3 cyan 011
4 red 100
5 mauve 101
6 yellow = 110
7 white 111 */
var colors = [[0,0,0],[0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]];
function randomColor()
{
return rndInt(0, colors.length);
}
function updateInfoBox(fps)
{
moverInfo = document.getElementById("moverInfo") ;
gameInfo = document.getElementById("gameInfo") ;
moverInfo.setAttribute("value", Point_Helper.textValue(moverPoint) + " // " + moverVector.textValue() + " // speed:" +
speed);
gameInfo.setAttribute("value", "objects:" + myObjects.length + " // visible " + visibles + "// FPS: " + fps ) ;
}