2023-05-12 22:06:21 +02:00
|
|
|
xrf.frag.pos = function(v, opts){
|
2023-05-09 17:42:29 +02:00
|
|
|
let { frag, mesh, model, camera, scene, renderer, THREE} = opts
|
2023-11-24 17:32:53 +01:00
|
|
|
|
2024-01-24 18:11:37 +00:00
|
|
|
let pos = v
|
2023-11-24 17:32:53 +01:00
|
|
|
// spec: indirect coordinate using objectname: https://xrfragment.org/#navigating%203D
|
2024-01-24 18:11:37 +00:00
|
|
|
if( pos.x == undefined ){
|
2023-11-24 17:32:53 +01:00
|
|
|
let obj = scene.getObjectByName(v.string)
|
2024-10-08 17:11:14 +02:00
|
|
|
if( !obj ) return console.warn("#pos="+v.string+" not found")
|
2024-12-10 14:41:07 +00:00
|
|
|
obj.add(camera) // follow animation of targeted position
|
2025-01-14 15:36:36 +01:00
|
|
|
camera.position.set(0,1.6,0) // set playerheight
|
2024-12-10 14:49:23 +00:00
|
|
|
//let c = camera.rotation
|
|
|
|
|
//c.set( c.x, obj.rotation.y, c.z )
|
2024-10-07 19:02:52 +00:00
|
|
|
|
2023-11-24 17:32:53 +01:00
|
|
|
}else{
|
|
|
|
|
// spec: direct coordinate: https://xrfragment.org/#navigating%203D
|
2024-01-24 18:11:37 +00:00
|
|
|
camera.position.x = pos.x
|
|
|
|
|
camera.position.y = pos.y
|
|
|
|
|
camera.position.z = pos.z
|
2023-11-24 17:32:53 +01:00
|
|
|
}
|
2024-01-24 18:11:37 +00:00
|
|
|
|
2024-02-01 09:04:01 +00:00
|
|
|
if( xrf.debug ) console.log(`#pos.js: setting camera to position ${pos.x},${pos.y},${pos.z}`)
|
2024-04-25 15:56:29 +00:00
|
|
|
xrf.frag.pos.last = v.string // remember
|
2024-06-07 07:33:00 +00:00
|
|
|
xrf.frag.pos.lastVector3 = camera.position.clone()
|
2024-01-24 18:11:37 +00:00
|
|
|
|
2023-12-12 18:09:30 +01:00
|
|
|
camera.updateMatrixWorld()
|
2024-10-13 14:03:31 +02:00
|
|
|
camera.getCam().updateMatrixWorld()
|
2023-05-04 21:28:12 +02:00
|
|
|
}
|
2024-02-01 09:04:01 +00:00
|
|
|
|
2024-04-15 14:06:54 +00:00
|
|
|
xrf.frag.pos.get = function(precision,randomize){
|
|
|
|
|
if( !precision ) precision = 2;
|
|
|
|
|
if( typeof THREE == 'undefined' ) THREE = xrf.THREE
|
|
|
|
|
let radToDeg = THREE.MathUtils.radToDeg
|
|
|
|
|
let toDeg = (x) => x / (Math.PI / 180)
|
|
|
|
|
let camera = xrf.camera
|
|
|
|
|
if( randomize ){
|
|
|
|
|
camera.position.x += Math.random()/10
|
|
|
|
|
camera.position.z += Math.random()/10
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// *TODO* add camera direction
|
|
|
|
|
let direction = new xrf.THREE.Vector3()
|
|
|
|
|
camera.getWorldDirection(direction)
|
|
|
|
|
const pitch = Math.asin(direction.y);
|
|
|
|
|
const yaw = Math.atan2(direction.x, direction.z);
|
|
|
|
|
const pitchInDegrees = pitch * 180 / Math.PI;
|
|
|
|
|
const yawInDegrees = yaw * 180 / Math.PI;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
x: String(camera.position.x.toFixed(2)),
|
|
|
|
|
y: String(camera.position.y.toFixed(2)),
|
|
|
|
|
z: String(camera.position.z.toFixed(2)),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-01 09:04:01 +00:00
|
|
|
xrf.addEventListener('reset', (opts) => {
|
|
|
|
|
// set the player to position 0,0,0
|
|
|
|
|
xrf.camera.position.set(0,0,0)
|
|
|
|
|
})
|