更新屏幕点转换代码 清理mouse鼠标控制中 屏幕转世界点的方法.

pull/7/head
ChenX 7 years ago
parent 635da7410e
commit 4762ee7a8b

@ -34,16 +34,7 @@ export class MouseControls
updateWordPoint = (e: MouseEvent) =>
{
this.m_CurMousePointVCS.set(e.offsetX, e.offsetY, 0);
//变换和求交点
let plan = new PlaneExt(new Vector3(0, 0, 1));
this.raycaster.setFromCamera(
{
x: (e.offsetX / this.m_View.m_HtmlElement.scrollWidth) * 2 - 1,
y: - (e.offsetY / this.m_View.m_HtmlElement.scrollHeight) * 2 + 1
}
, this.m_View.m_Camera.m_CurCamera
)
plan.intersectRay(this.raycaster.ray, this.m_CurMousePointWCS, true);
this.m_CurMousePointWCS.copy(this.m_CurMousePointVCS);
this.m_View.ScreenToWorld(this.m_CurMousePointWCS);
}
}

@ -6,6 +6,7 @@ import { RenderType } from './Enum';
import * as xaop from 'xaop';
import { GeUtils } from "../Geometry/GeUtils";
import { Entity } from '../DatabaseServices/Entity';
import { PlaneExt } from '../Geometry/Plane';
//导入其他js模块
require("three-CopyShader");
@ -162,23 +163,27 @@ export class Viewer
}
ScreenToWorld(pt: THREE.Vector3)
{
pt.x -= this.m_HtmlElement.scrollWidth * 0.5;
pt.y -= this.m_HtmlElement.scrollHeight * 0.5;
pt.y *= -1;
pt.multiplyScalar(this.m_ViewHeight / this.m_HtmlElement.scrollHeight);
this.m_Camera.m_CurCamera.updateMatrix();
pt.applyMatrix4(this.m_Camera.m_CurCamera.matrix);
//变换和求交点
let plan = new PlaneExt(new THREE.Vector3(0, 0, 1));
let raycaster = new THREE.Raycaster();
raycaster.setFromCamera(
{
x: (pt.x / this.m_HtmlElement.scrollWidth) * 2 - 1,
y: - (pt.y / this.m_HtmlElement.scrollHeight) * 2 + 1
}
, this.m_Camera.m_CurCamera
)
plan.intersectRay(raycaster.ray, pt, true);
}
WorldToScreen(pt: THREE.Vector3)
{
this.m_Camera.m_CurCamera.updateMatrix();
pt.applyMatrix4(this.m_Camera.m_CurCamera.matrixWorldInverse);
let widthHalf = this.m_HtmlElement.scrollWidth * 0.5;
let heightHalf = this.m_HtmlElement.scrollHeight * 0.5;
pt.project(this.m_Camera.m_CurCamera);
pt.multiplyScalar(this.m_HtmlElement.scrollHeight / this.m_ViewHeight)
pt.y *= -1
pt.x += this.m_HtmlElement.scrollWidth * 0.5;
pt.y += this.m_HtmlElement.scrollHeight * 0.5;
pt.x = (pt.x * widthHalf) + widthHalf;
pt.y = - (pt.y * heightHalf) + heightHalf;
}
onSize = (width?, height?) =>
{

Loading…
Cancel
Save