Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #35023

Trying to do 3D (THIRD TRY)

Newsgroups comp.lang.javascript
Date 2018-05-13 12:35 -0700
Message-ID <e6827ca4-d196-4e91-a9de-42a8f76dfbb4@googlegroups.com> (permalink)
Subject Trying to do 3D (THIRD TRY)
From bit-naughty@hotmail.com

Show all headers | View raw


..OK, I just give up. It's past 1 in the morning - all I'm trying to do is spin a a triangle round the y axis in 3D. Here's my code so far, I cleaned it up since last time. Could someone please tell me what's wrong??:



<html>


<head>
<style>

canvas {
	border: 1px solid black;
}
</style>

<script>




window.onload = function() {

	var canvas = document.getElementById("drawingCanvas");
	var context = canvas.getContext("2d");

function drawpoly(twodpoly) {
	
	context.moveTo (twodpoly[0].x,twodpoly[0].y);
	context.lineTo (twodpoly[1].x,twodpoly[1].y);
	context.lineTo (twodpoly[2].x,twodpoly[2].y);
	context.closePath();
	
	
	context.fill();
	
	
}



var threedpoly = [
	{
		x:50,
		y:50,
		z:1
	},
	
	{
		x:150,
		y:250,
		z:1
	},
	
	{
		x:500,
		y:50,
		z:1
	}
];

var twodpoly = [{
	x:0,
	y:0
	},
	
	{
	x:0,
	y:0
	},
	
	{
	x:0,
	y:0
	
}];




function rotatethreedpoly(threedpoly, angle) {

	
	
	for (var i=0; i<2; i++) {
		threedpoly[i].x = (Math.cos(angle) * threedpoly[i].x) - (Math.sin(angle) * threedpoly[i].z) ;
		threedpoly[i].y = threedpoly[i].y ;
		threedpoly[i].z = (Math.sin(angle) * threedpoly[i].x) + (Math.cos(angle) * threedpoly[i].z) ;
		
	}
	

};

	
function perspproject(threedpoly) {


for (var i=0; i<2; i++) {


	twodpoly[i].x = threedpoly[i].x/threedpoly[i].z ;
	twodpoly[i].y = (threedpoly[i].y/threedpoly[i].z) ;

	}		

}

// DRAW SHIT - MAIN LOOP


var i=0.01;

var rad = i * 0.017453293;



for (x=1; x<30; x++) {
	



rotatethreedpoly(threedpoly, rad);

perspproject(threedpoly);

drawpoly(twodpoly);




canvas.width = canvas.width;

}





}





</script>
</head>

<body>
<canvas id = "drawingCanvas" width="500" height="300">
</canvas>
</body>

</html>

Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Trying to do 3D (THIRD TRY) bit-naughty@hotmail.com - 2018-05-13 12:35 -0700
  Re: Trying to do 3D (THIRD TRY) Leonardo Campos <leonardoscampos@gmail.com> - 2018-05-14 22:29 -0700
    Re: Trying to do 3D (THIRD TRY) bit-naughty@hotmail.com - 2018-05-15 08:15 -0700
      Re: Trying to do 3D (THIRD TRY) Leonardo Campos <leonardoscampos@gmail.com> - 2018-05-15 18:10 -0700
        Re: Trying to do 3D (THIRD TRY) bit-naughty@hotmail.com - 2018-05-16 05:23 -0700
          Re: Trying to do 3D (THIRD TRY) Leonardo Campos <leonardoscampos@gmail.com> - 2018-05-16 21:38 -0700
            Re: Trying to do 3D (THIRD TRY) bit-naughty@hotmail.com - 2018-05-16 23:18 -0700
              Re: Trying to do 3D (THIRD TRY) bit-naughty@hotmail.com - 2018-05-16 23:47 -0700
                Re: Trying to do 3D (THIRD TRY) Leonardo Campos <leonardoscampos@gmail.com> - 2018-05-17 01:03 -0700
              Re: Trying to do 3D (THIRD TRY) Leonardo Campos <leonardoscampos@gmail.com> - 2018-05-17 00:56 -0700
  Re: Trying to do 3D (THIRD TRY) bit-naughty@hotmail.com - 2018-05-15 10:48 -0700
  Re: Trying to do 3D (THIRD TRY) "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-05-15 12:48 -0700
    Re: Trying to do 3D (THIRD TRY) bit-naughty@hotmail.com - 2018-05-16 05:29 -0700
  Re: Trying to do 3D (THIRD TRY) bit-naughty@hotmail.com - 2018-05-16 05:27 -0700
    Re: Trying to do 3D (THIRD TRY) "Christoph M. Becker" <cmbecker69@arcor.de> - 2018-05-16 23:31 +0200
      Re: Trying to do 3D (THIRD TRY) bit-naughty@hotmail.com - 2018-05-16 21:11 -0700
        Re: Trying to do 3D (THIRD TRY) "Christoph M. Becker" <cmbecker69@arcor.de> - 2018-05-17 13:35 +0200
  Re: Trying to do 3D (THIRD TRY) bit-naughty@hotmail.com - 2018-05-22 05:57 -0700
    Re: Trying to do 3D (THIRD TRY) "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-05-22 13:50 -0700

csiph-web