2013-02-20 52 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; 

在可變度你有度值來旋轉你的立方體