我正在尝试使用旋转来计算Line的结尾,但似乎无法使其正确。
我目前正在尝试以下方式:
function createLine(x, y, z, length, zrad, xrad)
{
var points = [
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(length/8, length*0.75, 0),
new THREE.Vector3(0, length, 0),
];
var spline = new THREE.SplineCurve3(points);
var material = new THREE.LineBasicMaterial({
color: 0xff00f0,
});
var geometry = new THREE.Geometry();
var splinePoints = spline.getPoints(numPoints);
for(var i = 0; i < splinePoints.length; i++){
geometry.vertices.push(splinePoints[i]);
}
var line = new THREE.Line(geometry, material);
line.position.x = x;
line.position.y = y;
line.position.z = z;
line.rotateZ(zrad);
line.rotateX(xrad);
// This is probably not the proper way to store the length of the Line
line.length = length;
return line;
}
function splitLine(line){
var lines = [];
var vector = new THREE.Vector3(0, line.length, 0);
vector.applyAxisAngle(new THREE.Vector3(0, 0, 1), line.rotation.z);
vector.applyAxisAngle(new THREE.Vector3(1, 0, 0), line.rotation.x);
var endPoint = vector.add(line.position);
console.log(endPoint);
lines.push(createLine(endPoint.x, endPoint.y, endPoint.z, line.length/1.3, line.rotation.z - 45 * (Math.PI/180), line.rotation.x - 45 * (Math.PI/180))) //line.rotation.y - 45 * (Math.PI/180)));
lines.push(createLine(endPoint.x, endPoint.y, endPoint.z, line.length/1.3, line.rotation.z + 45 * (Math.PI/180), line.rotation.x + 45 * (Math.PI/180))) //line.rotation.y + 45 * (Math.PI/180)));
return lines;
}
var endPoint = vector.add(line.position);
给出错误的位置。
奇怪的是,如果line.rotation.x = 0
;