Skip to content

Instantly share code, notes, and snippets.

@lazyTai
Last active September 28, 2017 23:43
Show Gist options
  • Save lazyTai/61cb286e08890b5bcac2616e3f38ec42 to your computer and use it in GitHub Desktop.
Save lazyTai/61cb286e08890b5bcac2616e3f38ec42 to your computer and use it in GitHub Desktop.
rebound
be uesd in
loop
export class Spring {
static MAX_DELTA_TIME_SEC: number;
static SOLVER_TIMESTEP_SEC: number;
listeners: Array<Listener>|null;
constructor(system: SpringSystem);
destroy(): void;
getId(): number;
getSpringConfig(): SpringConfigDict;
setSpringConfig(value: SpringConfigDict): Spring;
getCurrentValue(): number;
setCurrentValue(currentValue: number, skipSetAtRest?: boolean): Spring;
getStartValue(): number;
getCurrentDisplacementDistance(): number;
getCurrentDisplacementDistanceForState(state: PhysicsState): number;
getEndValue(): number;
setEndValue(value: number): Spring;
getVelocity(): number;
setVelocity(value: number): Spring;
getRestSpeedThreshold(): number;
setRestSpeedThreshold(value: number): Spring;
getRestDisplacementThreshold(): number;
isOvershootClampingEnabled(): boolean;
setOvershootClampingEnabled(value: boolean): Spring;
isOvershooting(): boolean;
advance(time: number, realDeltaTime: number): void;
systemShouldAdvance(): boolean;
notifyPositionUpdated(notifyActivate?: boolean, notifyAtRest?: boolean): void;
wasAtRest(): boolean;
isAtRest(): boolean;
setAtRest(): Spring;
interpolate(value: number): void;
getListeners(): Array<Listener>;
addListener(value: Listener): Spring;
removeListener(value: Listener): Spring;
removeAllListeners(): Spring;
currentValueIsApproximately(value: number): boolean;
}
be used in
advance
inlude onSpringUpdate
onSpringUpdate in customer
advance
addListener
addListener: function(newListener) {
this.listeners.push(newListener);
return this;
},
onSpringUpdate
```
notifyPositionUpdated: function() {
for (var i = 0, len = this.listeners.length; i < len; i++) {
var listener = this.listeners[i];
listener.onSpringUpdate(this);
}
},
```
SpringConfig
.fromOrigamiTensionAndFriction
```
fromOrigamiTensionAndFriction: function(tension, friction) {
return new SpringConfig(
OrigamiValueConverter.tensionFromOrigamiValue(tension),
OrigamiValueConverter.frictionFromOrigamiValue(friction));
},
```
SpringConfig
des:store tension friction
```
function SpringConfig(tension, friction) {
this.tension = tension;
this.friction = friction;
};
```
createSpring
return Spring
params tension?: number, friction?: number
what is tension(n. 张力,拉力;紧张,不安;电压) friction(n. 摩擦,[力] 摩擦力)
spring
store a lot of property and methods
```
createSpring: function(tension, friction) {
var springConfig;
if (tension === undefined || friction === undefined) {
springConfig = SpringConfig.DEFAULT_ORIGAMI_SPRING_CONFIG;
} else {
springConfig =
SpringConfig.fromOrigamiTensionAndFriction(tension, friction);
}
return this.createSpringWithConfig(springConfig);
},
```
```
createSpring: function(tension, friction) {
springConfig =
SpringConfig.fromOrigamiTensionAndFriction(tension, friction);
return this.createSpringWithConfig(springConfig);
},
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment