我想让汽车沿着弯曲的路径移动/旋转。我想根据路径设置车轮和车的方向。
我可以设置一个初始方向,但其余的路径呢?
(这是我试过的
var agl = Math.atan2(
this.latLonG[0].lat - this.tiler.lastBbox.c.lat//this.latLonG[0].lat
,this.latLonG[0].lon - this.tiler.lastBbox.c.lon//this.latLonG[0].lon
);
备注:
答案 0 :(得分:1)
沿着曲线移动汽车,按照其方向:
让汽车更进一步。
Tools > Options
要使车轮转动,您可以获得方向矢量和先前方向矢量的叉积。假设您在x轴和z轴的平面上移动汽车,则车轮的方向将与结果矢量的y值成比例:
//1. create spline's points
var points = [
new THREE.Vector3( x1, y1, z1 ),
new THREE.Vector3( x2, y2, z2 ),
...
new THREE.Vector3( xn, yn, zn )
];
//2. create spline
var spline = new THREE.CatmullRomCurve3( points );
//since r72. Before : THREE.SplineCurve3
//3. define the car position on the spline, between its start (0) and end (1)
var carPositionOnSpline = 0;
//Then at each increment (in your render loop or in the 'update' function of a tween)
var newPosition = spline.getPoint( carPositionOnSpline );
car.position.copy( newPosition );
//Also update the car's orientation so it looks at the road
var target = spline.getPoint( carPositionOnSpline + .001 );
car.lookAt( target );//+.001 or whatever