-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcam.html
More file actions
93 lines (69 loc) · 2.17 KB
/
cam.html
File metadata and controls
93 lines (69 loc) · 2.17 KB
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
<!DOCTYPE html>
<HTML>
<HEAD>
<title>WebGL Blank Template - Alexandr Poltavsky, software developer</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<link rel="stylesheet" type="text/css" href="css/common.css" />
<link rel="stylesheet" href="highlight/styles/hybrid.css">
</HEAD>
<BODY>
<div id="wrap">
<div id="content" style="clear: left">
<canvas id="demo" width="300" height="300"></canvas>
<script src="js/common.js"></script>
<script src="js/math.js"></script>
<script src="js/camera.js"></script>
<script src="js/loader.js"></script>
<script>
/*
load_resources (["webgl/lenin2dec.obj"],
function(o,src,i){console.log("loading",src,i,dump(o));},
function(o,src,i){console.log("loaded",src,i,dump(o));}
);
*/
var canvas = document.getElementById( "demo" );
var w = canvas.width, h = canvas.height, wc = w/2, hc = h/2, len = 100;
var ctx = canvas.getContext("2d");
var cam = camera_create( { element: canvas, nobind: false, personal: false, pos: vec3(0,0,-1) } );
var x = vec3(), y = vec3(), z = vec3();
requestAnimationFrame(draw);
function draw() {
requestAnimationFrame(draw);
ctx.clearRect(0,0,w,h);
mulv( x, cam.m[0], len );
mulv( y, cam.m[1], len );
mulv( z, cam.m[2], len );
x[1]=-x[1];
y[1]=-y[1];
z[1]=-z[1];
ctx.beginPath();
if(x[2]>0) ctx.lineWidth = 1; else ctx.lineWidth = 3;
ctx.moveTo( wc, hc );
ctx.lineTo( wc+x[0], hc+x[1] );
ctx.stroke();
ctx.closePath();
ctx.beginPath();
if(y[2]>0) ctx.lineWidth = 1; else ctx.lineWidth = 3;
ctx.moveTo( wc, hc );
ctx.lineTo( wc+y[0], hc+y[1] );
ctx.stroke();
ctx.closePath();
ctx.beginPath();
if(z[2]>0) ctx.lineWidth = 1; else ctx.lineWidth = 3;
ctx.moveTo( wc, hc );
ctx.lineTo( wc+z[0], hc+z[1] );
ctx.stroke();
ctx.closePath();
}
</script>
<style>
#demo {
border: 1px solid;
}
</style>
</div>
</div>
</BODY>
</HTML>