From b14014e6133e50c4a861f9784ae8b29922340e4c Mon Sep 17 00:00:00 2001 From: ChenX Date: Fri, 24 Nov 2017 17:12:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86=E4=BB=A3=E7=A0=81=20?= =?UTF-8?q?=E4=BF=9D=E8=AF=81=E8=AF=A5=E8=A7=86=E5=9B=BE=E7=9A=84=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E6=98=AF2=E7=9A=84=E5=80=8D=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/GraphicsSystem/CursorViewer.ts | 47 +++++++++++++----------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/src/GraphicsSystem/CursorViewer.ts b/src/GraphicsSystem/CursorViewer.ts index 3a9afd662..500d36576 100644 --- a/src/GraphicsSystem/CursorViewer.ts +++ b/src/GraphicsSystem/CursorViewer.ts @@ -19,6 +19,9 @@ export class CursorViewer m_LastEntity: THREE.Object3D; m_LastIndex: number; + private m_Width:number; + private m_Height:number; + //容器节点 private m_DomEl: HTMLElement; constructor(container: HTMLElement) @@ -28,7 +31,7 @@ export class CursorViewer this.InitCamera(); this.InitRender(); this.InitCursor(); - this.SetSize(container.scrollWidth, container.scrollHeight); + this.onSize(); } get Scene() { return this.m_Scene; } @@ -37,14 +40,10 @@ export class CursorViewer private InitCamera() { this.m_Camera = new CameraControl(); - this.m_Camera.ViewHeight = this.m_DomEl.scrollHeight; - this.m_Camera.SetSize(this.m_DomEl.scrollWidth, this.m_DomEl.scrollHeight); + this.m_Camera.ViewHeight = 1; + this.m_Camera.SetSize(1, 1); this.m_Camera.Update(); } - onSize() - { - this.SetSize(this.m_DomEl.scrollWidth, this.m_DomEl.scrollHeight); - } private InitRender() { let canvas = document.createElement("canvas"); @@ -112,34 +111,28 @@ export class CursorViewer */ ScreenPointToViewerPoint(p: THREE.Vector3) { - let width = this.m_DomEl.scrollWidth; - if (width % 2 == 1) - { - width -= 1; - } - let height = this.m_DomEl.scrollHeight; - if (height % 2 == 1) - { - height -= 1; - } - p.x = p.x - this.m_DomEl.scrollWidth * 0.5; - p.y = this.m_DomEl.scrollHeight * 0.5 - p.y; + p.x = p.x - this.m_Width * 0.5; + p.y = this.m_Height * 0.5 - p.y; } - SetSize(width, height) + + onSize() { - if (width % 2 == 1) + this.m_Width = this.m_DomEl.scrollWidth; + this.m_Height = this.m_DomEl.scrollHeight; + if (this.m_Width % 2 == 1) { - width -= 1; + this.m_Width -= 1; } - if (height % 2 == 1) + if (this.m_Height % 2 == 1) { - height -= 1; + this.m_Height -= 1; } - this.m_Camera.SetSize(width, height); - this.m_Camera.ViewHeight = height; + + this.m_Camera.SetSize(this.m_Width, this.m_Height); + this.m_Camera.ViewHeight = this.m_Height; this.m_Camera.Update(); - this.m_Render.setSize(width, height); + this.m_Render.setSize(this.m_Width, this.m_Height); } HideCursor()