Three?js, camera and angle rollover

C++, C#, Java, PHP, ect...
Post Reply
Thunder_X
Posts: 11
Joined: Tue Apr 30, 2013 7:04 pm

Three?js, camera and angle rollover

Post by Thunder_X »

Hey Gang!
Okay, I'm making (duh) a something, using Three.js. So far, I've been able to import a landscape (collada) and set up a skybox. With he mouse I control the rotation of the player, this angle gets stored. I use that to calculate the next X/Y position of the player as (s)he moves forward, using Trigonometry.
As I move the mouse, I read the angle of the camera, it's in Radians, so I convert it. That all seems to work, however, the camera either keeps adding the angle (to 700° - that's not even an angle anymore) or comes up with negative numbers. At one try, it even only counted up to 180 and reset its count...
I use the perspective camera in Three.js...
This is the function I use to read the camera's angle...

Code: Select all

function MouseMove(evt)
{
	if(mousestatus == "down")
	{
		//console.log("cammove");
		var deltaX = evt.clientX - intMousePosX;
		var deltaY = evt.clientY - intMousePosY;
		TheCamera.rotation.y += deltaX / 100;
		fltCamAngle = RadToDeg(TheCamera.rotation.y);
		if(fltCamAngle>360)
		{
			fltCamAngle = fltCamAngle - 360;
		}
		if(fltCamAngle<0)
		{
			fltCamAngle = Math.abs(fltCamAngle);	
		}
		intMousePosX = evt.clientX;
		intMousePosY = evt.clientY;			
	}
}
Thanks for any help.
Maybe I'd better use the trackball controlls or so, but I was'nt able to get that working...
Thunder
Post Reply

Return to “Coding”