Eye camera pointion scale

This commit is contained in:
MrKBear 2022-02-12 16:33:12 +08:00
parent 6e1469db53
commit 46f18b1780
3 changed files with 38 additions and 2 deletions

View File

@ -131,6 +131,27 @@ class Camera{
*/ */
public angleY:number = 0; public angleY:number = 0;
/**
*
*/
public get eyeDist(): number {
return vec3.length(this.eye);
}
/**
*
*/
public eyeScale(scale: number): this {
let dis = this.eyeDist;
if ((dis + scale) < 0) scale = .1 - dis;
vec3.set(this.eye,
(this.eye[0] / dis) * scale + this.eye[0],
(this.eye[1] / dis) * scale + this.eye[1],
(this.eye[2] / dis) * scale + this.eye[2]
);
return this;
}
/** /**
* *
*/ */
@ -140,7 +161,7 @@ class Camera{
vec3.sub(this.eye, this.eye, this.target); vec3.sub(this.eye, this.eye, this.target);
// 计算视点距离 // 计算视点距离
let dis = vec3.length(this.eye); let dis = this.eyeDist;
// 计算方向角 // 计算方向角
let anDir = vec3.create(); let anDir = vec3.create();

View File

@ -37,7 +37,11 @@ class ClassicRenderer extends BasicRenderer<{}, IClassicRendererParams> {
this.canvas.on("mouseup", () => { this.canvas.on("mouseup", () => {
this.canvas.can.style.cursor = "grab" this.canvas.can.style.cursor = "grab"
}) });
this.canvas.on("mousewheel", () => {
this.camera.eyeScale(this.canvas.wheelDelta / 100);
});
// 运行 // 运行
this.run(); this.run();

View File

@ -34,6 +34,7 @@ type GLCanvasEvent = {
mouseup: GLCanvas, mouseup: GLCanvas,
mousemove: GLCanvas, mousemove: GLCanvas,
mousedown: GLCanvas, mousedown: GLCanvas,
mousewheel: GLCanvas,
resize: GLCanvas, resize: GLCanvas,
}; };
@ -244,6 +245,11 @@ class GLCanvas extends Emitter<GLCanvasEvent> {
*/ */
public mouseDown:boolean = false; public mouseDown:boolean = false;
/**
*
*/
public wheelDelta: number = 0;
/** /**
* canvas * canvas
*/ */
@ -364,6 +370,11 @@ class GLCanvas extends Emitter<GLCanvasEvent> {
}); });
this.canvas.addEventListener("mousewheel", (e) => {
this.wheelDelta = (e as any)?.wheelDelta ?? 0;
this.emit("mousewheel", this);
})
} }
} }