Skip to content

Commit

Permalink
v1.1.2: add body.setTransform(xf) signature
Browse files Browse the repository at this point in the history
  • Loading branch information
shakiba committed Dec 3, 2024
1 parent 0e58a85 commit 71f4e5c
Show file tree
Hide file tree
Showing 21 changed files with 109 additions and 34 deletions.
6 changes: 6 additions & 0 deletions dist/planck-with-testbed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,12 @@ declare class Body$1 {
* @param angle The world rotation in radians.
*/
setTransform(position: Vec2Value, angle: number): void;
/**
* Set the position of the body's origin and rotation. Manipulating a body's
* transform may cause non-physical behavior. Note: contacts are updated on the
* next call to World.step.
*/
setTransform(xf: Transform): void;
synchronizeTransform(): void;
/**
* Update fixtures in broad-phase.
Expand Down
10 changes: 7 additions & 3 deletions dist/planck-with-testbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.planck = {}));
})(this, function(exports2) {
"use strict";/**
* Planck.js v1.1.1
* Planck.js v1.1.2
* @license The MIT license
* @copyright Copyright (c) 2024 Erin Catto, Ali Shakiba
*
Expand Down Expand Up @@ -2641,11 +2641,15 @@
Body2.prototype.getTransform = function() {
return this.m_xf;
};
Body2.prototype.setTransform = function(position, angle) {
Body2.prototype.setTransform = function(a2, b2) {
if (this.isWorldLocked() == true) {
return;
}
this.m_xf.setNum(position, angle);
if (typeof b2 === "number") {
this.m_xf.setNum(a2, b2);
} else {
this.m_xf.setTransform(a2);
}
this.m_sweep.setTransform(this.m_xf);
var broadPhase = this.m_world.m_broadPhase;
for (var f = this.m_fixtureList; f; f = f.m_next) {
Expand Down
2 changes: 1 addition & 1 deletion dist/planck-with-testbed.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/planck-with-testbed.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/planck-with-testbed.min.js.map

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions dist/planck-with-testbed.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Planck.js v1.1.1
* Planck.js v1.1.2
* @license The MIT license
* @copyright Copyright (c) 2024 Erin Catto, Ali Shakiba
*
Expand Down Expand Up @@ -2637,11 +2637,15 @@ var Body = (
Body2.prototype.getTransform = function() {
return this.m_xf;
};
Body2.prototype.setTransform = function(position, angle) {
Body2.prototype.setTransform = function(a2, b2) {
if (this.isWorldLocked() == true) {
return;
}
this.m_xf.setNum(position, angle);
if (typeof b2 === "number") {
this.m_xf.setNum(a2, b2);
} else {
this.m_xf.setTransform(a2);
}
this.m_sweep.setTransform(this.m_xf);
var broadPhase = this.m_world.m_broadPhase;
for (var f = this.m_fixtureList; f; f = f.m_next) {
Expand Down
2 changes: 1 addition & 1 deletion dist/planck-with-testbed.mjs.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions dist/planck.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,12 @@ declare class Body$1 {
* @param angle The world rotation in radians.
*/
setTransform(position: Vec2Value, angle: number): void;
/**
* Set the position of the body's origin and rotation. Manipulating a body's
* transform may cause non-physical behavior. Note: contacts are updated on the
* next call to World.step.
*/
setTransform(xf: Transform): void;
synchronizeTransform(): void;
/**
* Update fixtures in broad-phase.
Expand Down
10 changes: 7 additions & 3 deletions dist/planck.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/planck.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/planck.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/planck.min.js.map

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions dist/planck.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Planck.js v1.1.1
* Planck.js v1.1.2
* @license The MIT license
* @copyright Copyright (c) 2024 Erin Catto, Ali Shakiba
*
Expand Down Expand Up @@ -2637,11 +2637,15 @@ var Body = (
Body2.prototype.getTransform = function() {
return this.m_xf;
};
Body2.prototype.setTransform = function(position, angle) {
Body2.prototype.setTransform = function(a2, b2) {
if (this.isWorldLocked() == true) {
return;
}
this.m_xf.setNum(position, angle);
if (typeof b2 === "number") {
this.m_xf.setNum(a2, b2);
} else {
this.m_xf.setTransform(a2);
}
this.m_sweep.setTransform(this.m_xf);
var broadPhase = this.m_world.m_broadPhase;
for (var f = this.m_fixtureList; f; f = f.m_next) {
Expand Down
2 changes: 1 addition & 1 deletion dist/planck.mjs.map

Large diffs are not rendered by default.

22 changes: 20 additions & 2 deletions docs/pages/api/classes/Body.md
Original file line number Diff line number Diff line change
Expand Up @@ -916,13 +916,15 @@ This will alter the mass and velocity.

### setTransform()

#### setTransform(position, angle)

> **setTransform**(`position`, `angle`): `void`
Set the position of the body's origin and rotation. Manipulating a body's
transform may cause non-physical behavior. Note: contacts are updated on the
next call to World.step.

#### Parameters
##### Parameters

**position**: [`Vec2Value`](../interfaces/Vec2Value)

Expand All @@ -932,7 +934,23 @@ The world position of the body's local origin.

The world rotation in radians.

#### Returns
##### Returns

`void`

#### setTransform(xf)

> **setTransform**(`xf`): `void`
Set the position of the body's origin and rotation. Manipulating a body's
transform may cause non-physical behavior. Note: contacts are updated on the
next call to World.step.

##### Parameters

**xf**: [`Transform`](Transform)

##### Returns

`void`

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/api/classes/World.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ World object.
#### Parameters

**def?**: [`Vec2`](Vec2) \| [`WorldDef`](../interfaces/WorldDef)
**def?**: [`Vec2Value`](../interfaces/Vec2Value) \| [`WorldDef`](../interfaces/WorldDef)

World definition or gravity vector.

Expand Down
22 changes: 20 additions & 2 deletions docs/pages/api/classes/body.md
Original file line number Diff line number Diff line change
Expand Up @@ -916,13 +916,15 @@ This will alter the mass and velocity.

### setTransform()

#### setTransform(position, angle)

> **setTransform**(`position`, `angle`): `void`
Set the position of the body's origin and rotation. Manipulating a body's
transform may cause non-physical behavior. Note: contacts are updated on the
next call to World.step.

#### Parameters
##### Parameters

**position**: [`Vec2Value`](../interfaces/Vec2Value)

Expand All @@ -932,7 +934,23 @@ The world position of the body's local origin.

The world rotation in radians.

#### Returns
##### Returns

`void`

#### setTransform(xf)

> **setTransform**(`xf`): `void`
Set the position of the body's origin and rotation. Manipulating a body's
transform may cause non-physical behavior. Note: contacts are updated on the
next call to World.step.

##### Parameters

**xf**: [`Transform`](Transform)

##### Returns

`void`

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/api/classes/world.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ World object.
#### Parameters

**def?**: [`Vec2`](Vec2) \| [`WorldDef`](../interfaces/WorldDef)
**def?**: [`Vec2Value`](../interfaces/Vec2Value) \| [`WorldDef`](../interfaces/WorldDef)

World definition or gravity vector.

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "planck",
"version": "1.1.1",
"version": "1.1.2",
"description": "2D JavaScript/TypeScript physics engine for cross-platform HTML5 game development",
"homepage": "https://github.com/piqnt/planck.js",
"keywords": [
Expand Down
17 changes: 14 additions & 3 deletions src/dynamics/Body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { options } from "../util/options";
import { Vec2, Vec2Value } from "../common/Vec2";
import { Rot } from "../common/Rot";
import { Sweep } from "../common/Sweep";
import { Transform } from "../common/Transform";
import { Transform, TransformValue } from "../common/Transform";
import { Velocity } from "./Velocity";
import { Position } from "./Position";
import { Fixture, FixtureDef, FixtureOpt } from "./Fixture";
Expand Down Expand Up @@ -565,13 +565,24 @@ export class Body {
* @param position The world position of the body's local origin.
* @param angle The world rotation in radians.
*/
setTransform(position: Vec2Value, angle: number): void {
setTransform(position: Vec2Value, angle: number): void;
/**
* Set the position of the body's origin and rotation. Manipulating a body's
* transform may cause non-physical behavior. Note: contacts are updated on the
* next call to World.step.
*/
setTransform(xf: Transform): void;
setTransform(a: Vec2Value | Transform, b?: number): void {
_ASSERT && console.assert(this.isWorldLocked() == false);
if (this.isWorldLocked() == true) {
return;
}
if (typeof b === "number") {
this.m_xf.setNum(a as Vec2Value, b);
} else {
this.m_xf.setTransform(a as TransformValue);
}

this.m_xf.setNum(position, angle);
this.m_sweep.setTransform(this.m_xf);

const broadPhase = this.m_world.m_broadPhase;
Expand Down

0 comments on commit 71f4e5c

Please sign in to comment.