-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add prettier and format multiscene example
- Loading branch information
Showing
6 changed files
with
93 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,41 @@ | ||
import {Component, Property} from "@wonderlandengine/api"; | ||
import { SwitchScene } from './switch'; | ||
import { vec3 } from 'gl-matrix'; | ||
import {Component, Property} from '@wonderlandengine/api'; | ||
import {SwitchScene} from './switch'; | ||
import {vec3} from 'gl-matrix'; | ||
|
||
/** | ||
* switch-scene | ||
*/ | ||
export class Portal extends Component { | ||
static TypeName = "portal"; | ||
/* Properties that are configurable in the editor */ | ||
static Properties = { | ||
target: Property.object(), | ||
translationDuration: Property.float(0.5), | ||
initialTranslate: Property.float(15), | ||
portalRotateSpeed: Property.float(1.0), | ||
}; | ||
static TypeName = 'portal'; | ||
/* Properties that are configurable in the editor */ | ||
static Properties = { | ||
target: Property.object(), | ||
translationDuration: Property.float(0.5), | ||
initialTranslate: Property.float(15), | ||
portalRotateSpeed: Property.float(1.0), | ||
}; | ||
|
||
onActivate() { | ||
this.target.translateObject([0, 0, this.initialTranslate]); | ||
} | ||
onActivate() { | ||
this.target.translateObject([0, 0, this.initialTranslate]); | ||
} | ||
|
||
update(dt) { | ||
this.object.rotateAxisAngleDegObject( | ||
[0, 0, 1], | ||
dt * 10000 * this.portalRotateSpeed, | ||
); | ||
const playerPosition = this.target.getPositionWorld([]); | ||
const portalPosition = this.object.getPositionWorld([]); | ||
const sqDist= vec3.squaredDistance(playerPosition, portalPosition) | ||
if (sqDist > 0.1) { | ||
const distanceRemaining = Math.abs( | ||
portalPosition[0] - playerPosition[0], | ||
); | ||
const alpha = | ||
1 - | ||
Math.exp(-dt / (this.translationDuration * distanceRemaining)); | ||
const newPosition= new Float32Array(3) | ||
vec3.lerp(newPosition,playerPosition,portalPosition,alpha,) | ||
this.target.setPositionWorld(newPosition); | ||
} | ||
else{ | ||
this.object.getComponent(SwitchScene).switch(); | ||
} | ||
} | ||
update(dt) { | ||
this.object.rotateAxisAngleDegObject( | ||
[0, 0, 1], | ||
dt * 10000 * this.portalRotateSpeed | ||
); | ||
const playerPosition = this.target.getPositionWorld([]); | ||
const portalPosition = this.object.getPositionWorld([]); | ||
const sqDist = vec3.squaredDistance(playerPosition, portalPosition); | ||
if (sqDist > 0.1) { | ||
const distanceRemaining = Math.abs(portalPosition[0] - playerPosition[0]); | ||
const alpha = | ||
1 - Math.exp(-dt / (this.translationDuration * distanceRemaining)); | ||
const newPosition = new Float32Array(3); | ||
vec3.lerp(newPosition, playerPosition, portalPosition, alpha); | ||
this.target.setPositionWorld(newPosition); | ||
} else { | ||
this.object.getComponent(SwitchScene).switch(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters