pull/7/head
ChenX 7 years ago
parent a61be4cc9d
commit 22f7832500

@ -0,0 +1,67 @@
import * as THREE from 'three';
import { GeUtils } from "../src/Geometry/GeUtils"
let v = new THREE.Vector3(1, 0, 0);
let v2 = new THREE.Vector3(1, 0.1, 0)
let an = v.angleTo(v2);
console.log('an: ', an);
console.log(an);
console.log(v.angleTo(v2));
console.log(Math.PI * 0.25);
console.log(v);
console.log(v2);
console.log(v.dot(v2));
function fixAngle(an)
{
let pi4 = Math.PI * 0.5;
let rem = an % pi4;
if (rem < 0.1)
{
an -= rem;
}
else
{
an += 0.2;
rem = an % pi4;
if (rem < 0.1)
{
an -= rem;
}
else
{
an -= 0.2
}
}
return an;
}
an = fixAngle(an);
console.log(an);
GeUtils.angle(v, an, 1);
console.log(v);
console.log(fixAngle(Math.PI / 2 + 0.0));
console.log(fixAngle(Math.PI / 2 + 0.05));
console.log(Math.PI % Math.PI);
console.log(fixAngle(Math.PI / 2 + 0.05) % Math.PI / 2);

@ -13,6 +13,7 @@ import { KeyBoardControls } from './KeyBoardControls';
import { MouseControls } from './MouseControls';
import { PromptPointResult, PromptStatus } from './PromptResult';
import { SelectControls } from './SelectControls';
import { GeUtils } from '../Geometry/GeUtils';
//TODO: 增加鼠标状态. 鼠标位置.
export class Editor
@ -39,7 +40,7 @@ export class Editor
this.m_InputState = InputState.GetPoint;
let retValue = new PromptPointResult();
let removeSnap = this.Snap();
let removeSnap = this.Snap(prompt ? prompt.BasePoint : undefined);
let res = new Promise<PromptPointResult>((resolve, reject) =>
{
let line: Line, removeDrag;
@ -139,10 +140,57 @@ export class Editor
}
noSnapList = new Set<THREE.Object3D>();
Snap()
Snap(basePoint?: THREE.Vector3)
{
let testSnap = () =>
{
if (basePoint)
{
function fixAngle(an)
{
let pi2 = Math.PI * 0.5;
let rem = an % pi2;
if (rem < 0.1)
{
an -= rem;
}
else
{
an += 0.2;
rem = an % pi2;
if (rem < 0.1)
{
an -= rem;
}
else
{
an -= 0.2
}
}
return an;
}
let p = this.m_MouseCtrl.m_CurMousePointWCS.clone().sub(basePoint);
let an = Math.atan2(p.y, p.x);
if (an < 0) an += Math.PI * 2;
an = fixAngle(an);
console.log('an: ', an);
if (an % (Math.PI * 0.5) < 0.01)
{
let ptC = basePoint.clone();
GeUtils.angle(ptC, an, basePoint.dot(this.m_MouseCtrl.m_CurMousePointWCS));
app.m_Viewer.WorldToScreen(ptC);
app.m_CursorViewer.SerCursorPostion(ptC);
app.m_CursorViewer.render();
return;
}
}
for (let obj of app.m_Viewer.m_Scene.children)
{
if (this.noSnapList.has(obj))

@ -10,6 +10,7 @@ import { Editor } from './Editor';
import { SelectBox } from './SelectBox';
import { SelectPick } from './SelectPick';
import { SelectSet, SelectType } from './SelectSet';
import { commandMachine } from './CommandMachine';
export class SelectControls
{
@ -88,6 +89,10 @@ export class SelectControls
let snapEvent = () =>
{
if (commandMachine.m_CommandIng)
{
return;
}
for (let pts of app.m_Viewer.m_GripScene.children)
{
if (pts instanceof THREE.Points)

@ -17,6 +17,12 @@ export namespace GeUtils
return v1.manhattanDistanceTo(v2) < 1e-8;
}
export function angle(v: THREE.Vector3, an: number, dis: number)
{
v.x += Math.cos(an) * dis;
v.y += Math.sin(an) * dis;
}
export function getLoocAtUpVec(dir: THREE.Vector3): THREE.Vector3
{
if (dir.equals(cZeroVec))

Loading…
Cancel
Save