2013-02-20 58 views
0

如何根据方向移动对象?我的意思是,我在一个位置有一个立方体,我想围绕Y轴旋转并根据它们的方向移动。然后再次移动并旋转以改变方向。事情是这样的:方向,方向对象

enter image description here

+1

您可以提取轴直接来自变换矩阵。你如何改变这个物体? – JasonD 2013-02-20 22:32:53

+0

我使用glRotatef - > glTranslatef – 2013-02-20 23:11:20

回答

0

在JS你可以尝试这样的事:

var previousPosition = [x, y]; //change x and y with the coordinate of the object 
var nextPosition = [x, y]; //change x and y with the new coordinate of the object 

var x = previousPosition[0] - previousPosition[0]; 
var y = nextPosition[1] - nextPosition[1]; 

var rad = Math.atan(y/x); 
var deg = rad * 180/3.14; 

在可变度你有度值来旋转你的立方体