Explorar o código

script and html structure - fix

Iñigo Valentin %!s(int64=12) %!d(string=hai) anos
pai
achega
f37954f1d0
Modificáronse 2 ficheiros con 82 adicións e 0 borrados
  1. 22 0
      index.html
  2. 60 0
      script/ObJS.js

+ 22 - 0
index.html

@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+	<head>
+		<meta content="text/html; charset=windows-1252" http-equiv="content-type"/>
+		<title>ObJS</title>
+		<!--Script files -->
+		<script type="text/javascript" src="script/ObJS.js"></script>
+		<!-- CSS files -->
+	</head>
+	<body>
+		<select id="objSelector" name="objSelector" onChange="loadModel(this)">
+			<option value="cube" selected="selected">Cube</option>
+			<option value="2cube">Two Cubes</option>
+			<option value="complex">Complex Object</option>
+			<option value="2complex">Two Complex Objects</option>
+		</select>
+		<br/>
+		<canvas id="ObJSCanvas" width="400" height="400">
+			Your browser does not support the HTML5 canvas tag.
+		</canvas>
+	</body>
+</html>

+ 60 - 0
script/ObJS.js

@@ -0,0 +1,60 @@
+var backColor = "rgba(200, 200, 200, 255)";
+var vertColor = "rgba(10, 10, 10, 255)";
+var edgeColor = "rgba(200, 0, 0, 255)";
+var faceColor = "rgba(180, 180, 255, 200)";
+var textColor = "rgba(0, 0, 0, 255)";
+var vertSize = 5;
+
+var mDown = false;
+
+var canvas;
+var ctx;
+
+function loadModel(val){
+	//Get file
+	xmlhttp = new XMLHttpRequest();
+	xmlhttp.open("GET","/obj/" + val.value + ".obj", false);
+	xmlhttp.send();
+	var fileContent = xmlhttp.responseText;
+	
+	initCanvas();
+	writeCredits();
+}
+
+function initCanvas(){
+	canvas = document.getElementById("ObJSCanvas");
+	ctx = canvas.getContext("2d");
+	
+	ctx.fillStyle = backColor;
+	ctx.fillRect(0, 0, canvas.width, canvas.height);
+	
+	
+	canvas.onmousedown = function(e){
+		
+		mDown = true;
+	}
+	
+	canvas.onmouseup = function(e){
+		if(mDown) mouseClick(e);
+		
+		mDown = false;
+	}
+	
+	canvas.onmousemove = function(e){
+		if(!mDown) return;
+		
+		return false;
+	}
+}
+
+function mouseClick(){
+	//TODO: Element clicked
+}
+
+function writeCredits(){
+	ctx.fillStyle = textColor;
+	ctx.font = "12px Arial";
+	var h = canvas.height - 14;
+	var w = canvas.width - 45;
+	ctx.fillText("ObJS", w, h);
+}