better zoom management
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
<v-textarea :label="l.description" v-model="modelValue.description"></v-textarea>
|
<v-textarea :label="l.description" v-model="modelValue.description"></v-textarea>
|
||||||
<v-checkbox density="compact" v-model="modelValue.hud" hide-details label="Observe in head-up display"></v-checkbox>
|
<v-checkbox density="compact" v-model="modelValue.hud" hide-details label="Observe in head-up display"></v-checkbox>
|
||||||
<v-checkbox density="compact" v-model="modelValue.exclude" hide-details label="Disable interactions"></v-checkbox>
|
<v-checkbox density="compact" v-model="modelValue.exclude" hide-details label="Disable interactions"></v-checkbox>
|
||||||
<v-checkbox density="compact" v-model="modelValue.noPhysics" hide-details label="Disable physics"></v-checkbox>
|
<v-checkbox density="compact" v-model="modelValue.noPhysics" hide-details label="Disable collisions"></v-checkbox>
|
||||||
<v-img :src="`/asset/thumb/${modelValue.go}.webp`" />
|
<v-img :src="`/asset/thumb/${modelValue.go}.webp`" />
|
||||||
<div class="text-caption text-center">{{ modelValue.title }}</div>
|
<div class="text-caption text-center">{{ modelValue.title }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,13 +2,18 @@ import * as THREE from 'three'
|
|||||||
import { QueryFilterFlags } from '@dimforge/rapier3d';
|
import { QueryFilterFlags } from '@dimforge/rapier3d';
|
||||||
|
|
||||||
export class CharacterControls {
|
export class CharacterControls {
|
||||||
|
|
||||||
// temporary data
|
|
||||||
walkDirection = new THREE.Vector3()
|
walkDirection = new THREE.Vector3()
|
||||||
rotateAngle = new THREE.Vector3(0, 1, 0)
|
rotateAngle = new THREE.Vector3(0, 1, 0)
|
||||||
rotateQuarternion = new THREE.Quaternion()
|
|
||||||
cameraTarget = new THREE.Vector3()
|
|
||||||
cameraY = 3
|
cameraY = 3
|
||||||
|
#cameraZ = 5
|
||||||
|
|
||||||
|
get cameraZ(){
|
||||||
|
return this.#cameraZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
set cameraZ(v){
|
||||||
|
this.#cameraZ = Math.min(Math.max(v, 2), 10);
|
||||||
|
}
|
||||||
|
|
||||||
// constants
|
// constants
|
||||||
fadeDuration = 0.2
|
fadeDuration = 0.2
|
||||||
@@ -39,7 +44,6 @@ export class CharacterControls {
|
|||||||
|
|
||||||
this.orbitControl = engine.orbitControls
|
this.orbitControl = engine.orbitControls
|
||||||
this.camera = engine.camera
|
this.camera = engine.camera
|
||||||
//this.updateCameraTarget(new THREE.Vector3(0,1,5))
|
|
||||||
|
|
||||||
this.direction = this.model.rotation.y;
|
this.direction = this.model.rotation.y;
|
||||||
this.directionVelocity = 0;
|
this.directionVelocity = 0;
|
||||||
@@ -149,9 +153,9 @@ export class CharacterControls {
|
|||||||
|
|
||||||
let cameraPosition = new THREE.Vector3().copy(this.camera.position)
|
let cameraPosition = new THREE.Vector3().copy(this.camera.position)
|
||||||
let cameraDesiredPosition = new THREE.Vector3(
|
let cameraDesiredPosition = new THREE.Vector3(
|
||||||
this.model.position.x + 5* Math.sin(this.model.rotation.y + Math.PI + this.cameraDelta + this.cameraIdleDelta),
|
this.model.position.x + this.#cameraZ* Math.sin(this.model.rotation.y + Math.PI + this.cameraDelta + this.cameraIdleDelta),
|
||||||
this.cameraY,
|
this.cameraY,
|
||||||
this.model.position.z + 5* Math.cos(this.model.rotation.y + Math.PI + this.cameraDelta + this.cameraIdleDelta)
|
this.model.position.z + this.#cameraZ* Math.cos(this.model.rotation.y + Math.PI + this.cameraDelta + this.cameraIdleDelta)
|
||||||
)
|
)
|
||||||
|
|
||||||
cameraPosition.lerp(cameraDesiredPosition, delta*2)
|
cameraPosition.lerp(cameraDesiredPosition, delta*2)
|
||||||
|
|||||||
@@ -170,10 +170,14 @@ class GameEngine extends THREE.EventDispatcher{
|
|||||||
scene.background = new THREE.Color(1, 1, 1);
|
scene.background = new THREE.Color(1, 1, 1);
|
||||||
//console.log('GameEngine started')
|
//console.log('GameEngine started')
|
||||||
renderer.domElement.addEventListener('wheel', (event) => {
|
renderer.domElement.addEventListener('wheel', (event) => {
|
||||||
|
if (gameEngine.hero){
|
||||||
|
gameEngine.hero.characterControls.cameraZ += event.deltaY / 33;
|
||||||
|
}else{
|
||||||
gameEngine.camera.zoom -= event.deltaY / 1000;
|
gameEngine.camera.zoom -= event.deltaY / 1000;
|
||||||
gameEngine.camera.zoom = Math.max(gameEngine.camera.zoom, .4);
|
gameEngine.camera.zoom = Math.max(gameEngine.camera.zoom, .4);
|
||||||
controls.rotateSpeed = 1 / gameEngine.camera.zoom;
|
controls.rotateSpeed = 1 / gameEngine.camera.zoom;
|
||||||
gameEngine.camera.updateProjectionMatrix();
|
gameEngine.camera.updateProjectionMatrix();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
await this.initPhysics();
|
await this.initPhysics();
|
||||||
|
|||||||
+15
-4
@@ -1,4 +1,5 @@
|
|||||||
import * as RAPIER from '@dimforge/rapier3d'
|
import * as RAPIER from '@dimforge/rapier3d'
|
||||||
|
import { Vector3 } from 'three';
|
||||||
class Physics{
|
class Physics{
|
||||||
constructor(engine){
|
constructor(engine){
|
||||||
this.engine = engine
|
this.engine = engine
|
||||||
@@ -51,10 +52,20 @@ class Physics{
|
|||||||
break
|
break
|
||||||
|
|
||||||
default:{
|
default:{
|
||||||
colliderDesc = RAPIER.ColliderDesc.trimesh(
|
const vertices = [];
|
||||||
mesh.geometry.attributes.position.array,
|
const vertex = new Vector3();
|
||||||
mesh.geometry.index?.array
|
const position = mesh.geometry.getAttribute( 'position' );
|
||||||
)
|
for ( let i = 0; i < position.count; i ++ ) {
|
||||||
|
vertex.fromBufferAttribute( position, i );
|
||||||
|
vertices.push( vertex.x, vertex.y, vertex.z );
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the buffer is non-indexed, generate an index buffer
|
||||||
|
const indices = mesh.geometry.getIndex() === null
|
||||||
|
? Uint32Array.from( Array( parseInt( vertices.length / 3 ) ).keys() )
|
||||||
|
: mesh.geometry.getIndex().array;
|
||||||
|
|
||||||
|
colliderDesc = RAPIER.ColliderDesc.trimesh( vertices, indices );
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user