Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在哪里(在object3d中)可以找到更改点坐标?_Javascript_Three.js - Fatal编程技术网

Javascript 在哪里(在object3d中)可以找到更改点坐标?

Javascript 在哪里(在object3d中)可以找到更改点坐标?,javascript,three.js,Javascript,Three.js,这显示一个点绕Y轴旋转。 我想看到旋转时X坐标的变化。 显示起始坐标,但不改变。 变化的坐标一定在某个地方,对吗?哪里? 我以为“pointa.geometry.vertices[0].x”就是这个地方 编辑:我将旋转点设置为固定场景下的旋转组 <!doctype html> <html> <head> <title> a point </title> <script src="http://threejs.o

这显示一个点绕Y轴旋转。
我想看到旋转时X坐标的变化。
显示起始坐标,但不改变。
变化的坐标一定在某个地方,对吗?哪里?
我以为“pointa.geometry.vertices[0].x”就是这个地方

编辑:我将旋转点设置为固定场景下的旋转组

<!doctype html>
<html>
  <head>
    <title> a point </title>
    <script src="http://threejs.org/build/three.js"></script>
    <script type="text/javascript">
  "use strict";
  var js3canvas, renderer, camera, world, pointa, geometry, material, datadiv;
  var norotate;
window.onload = function() { 
  "use strict";
  js3canvas = document.getElementById("js3canvas");
  datadiv = document.getElementById("data");
  renderer = new THREE.WebGLRenderer( { canvas:js3canvas } );
  camera = new THREE.PerspectiveCamera(50, 1, 1, 20);
  camera.position.set(0,5,10);
  camera.lookAt(0,0,0);
  norotate = new THREE.Scene();
  norotate.background = new THREE.Color(0x888888);
  world = new THREE.Group();
  norotate.add(world);
  // make point
  geometry = new THREE.Geometry();
  geometry.vertices.push(new THREE.Vector3(2.3456,0,0));
  material = new THREE.PointsMaterial( { color:0xffffff } );
  pointa = new THREE.Points(geometry, material);
  world.add(pointa);
  animate();
}
function animate() { 
  datadiv.innerHTML = "X coordinate: " + pointa.geometry.vertices[0].x; // the x coordinate
  renderer.render( norotate, camera );
  world.rotateY(.03);
  requestAnimationFrame(animate);
}
    </script>
  </head>
  <body>
    <canvas width="200" height="200" id="js3canvas"></canvas>
    <div id="data"></div>
  </body>
</html>

一点
“严格使用”;
var js3canvas、渲染器、摄影机、世界、pointa、几何体、材质、数据div;
正硝酸变种;
window.onload=函数(){
“严格使用”;
js3canvas=document.getElementById(“js3canvas”);
datadiv=document.getElementById(“数据”);
renderer=new THREE.WebGLRenderer({canvas:js3canvas});
摄像机=新的三个透视摄像机(50,1,1,20);
摄像机位置设置(0,5,10);
摄像机。注视(0,0,0);
norotate=new THREE.Scene();
norotate.background=新的三种颜色(0x888888);
世界=新三组();
添加(世界);
//表明观点
几何体=新的三个。几何体();
几何学.顶点.推(新的三矢量3(2.3456,0,0));
材质=新的三点材质({color:0xffffff});
pointa=新的三个点(几何、材料);
添加(点A);
制作动画();
}
函数animate(){
datadiv.innerHTML=“X坐标:”+pointa.geometry.vertices[0].X;//X坐标
渲染器。渲染(无旋转,摄影机);
世界轮换指数(0.03);
请求动画帧(动画);
}

更改对象的旋转、位置或比例时,只需将变换矩阵应用于几何体的点,保持点的数据完整

设置临时向量,将顶点复制到此向量,从局部坐标系转换为世界坐标系:

var js3canvas、渲染器、摄影机、世界、pointa、几何体、材质、数据div;
正硝酸变种;
js3canvas=document.getElementById(“js3canvas”);
datadiv=document.getElementById(“数据”);
renderer=new THREE.WebGLRenderer({
画布:js3canvas
});
摄像机=新的三个透视摄像机(50,1,1,20);
摄像机位置设置(0,5,10);
摄像机。注视(0,0,0);
norotate=new THREE.Scene();
norotate.background=新的三种颜色(0x888888);
世界=新三组();
添加(世界);
//表明观点
几何体=新的三个。几何体();
几何学.顶点.推(新的三.向量3(2.3456,0,0));
材料=新的三点材料({
颜色:0xffffff
});
pointa=新的三个点(几何、材料);
添加(点A);
var tempV3=new THREE.Vector3();
制作动画();
函数animate(){
localToWorld(tempV3.copy(pointa.geometry.vertices[0]);
datadiv.innerHTML=“X坐标:”+tempV3.X;//X坐标
渲染器。渲染(无旋转,摄影机);
世界轮换指数(0.03);
请求动画帧(动画);
}


看起来该点的x坐标实际上没有改变-您正在旋转整个场景,而不是改变该点的位置。我不确定你到底想要什么坐标?@Matthew Adams如果世界在转,我会认为坐标必须改变。我猜WebGL比我想象的更神奇。我认为坐标是相对于世界的。例如,如果您驾驶的是您的汽车,即使汽车本身在移动,您在汽车中的位置(读取:坐标)也不会改变。谢谢!正是我想要的!我有一些学习要做。如果我有问题,我可以打电话给你吗?:)@dcromley不客气:)欢迎在论坛上提问: