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

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

@ -34,16 +34,7 @@ export class MouseControls
updateWordPoint = (e: MouseEvent) => updateWordPoint = (e: MouseEvent) =>
{ {
this.m_CurMousePointVCS.set(e.offsetX, e.offsetY, 0); this.m_CurMousePointVCS.set(e.offsetX, e.offsetY, 0);
this.m_CurMousePointWCS.copy(this.m_CurMousePointVCS);
//变换和求交点 this.m_View.ScreenToWorld(this.m_CurMousePointWCS);
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);
} }
} }

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

Loading…
Cancel
Save