Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
fix physics rotation and scaling (#10823)
Browse files Browse the repository at this point in the history
  • Loading branch information
HexaField authored Aug 3, 2024
1 parent 32cb0b0 commit c013946
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { defineQuery, defineSystem, Entity, getComponent } from '@etherealengine
import { ECSState } from '@etherealengine/ecs/src/ECSState'
import { getState } from '@etherealengine/hyperflux'

import { Vector3_Zero } from '../../common/constants/MathConstants'
import { Vector3_One, Vector3_Zero } from '../../common/constants/MathConstants'
import { SceneComponent } from '../../renderer/components/SceneComponents'
import { EntityTreeComponent, getAncestorWithComponent, iterateEntityNode } from '../../transform/components/EntityTree'
import { TransformComponent } from '../../transform/components/TransformComponent'
Expand All @@ -38,9 +38,8 @@ import { Physics } from '../classes/Physics'
import { ColliderComponent } from '../components/ColliderComponent'
import { RigidBodyComponent } from '../components/RigidBodyComponent'

const _vec3 = new Vector3()
const _quat = new Quaternion()

const localMatrix = new Matrix4()
const parentMatrixInverse = new Matrix4()
const position = new Vector3()
const rotation = new Quaternion()
const scale = new Vector3()
Expand Down Expand Up @@ -82,10 +81,10 @@ export const lerpTransformFromRigidbody = (entity: Entity, alpha: number) => {

const sceneEntity = getAncestorWithComponent(entity, SceneComponent)
const sceneTransform = getComponent(sceneEntity, TransformComponent)
// if the entity has a parent, we need to use the scene space
TransformComponent.getMatrixRelativeToScene(entity, mat4)
mat4.decompose(_vec3, _quat, scale)
transform.matrix.compose(position, rotation, scale)
parentMatrixInverse.copy(sceneTransform.matrixWorld).invert()
localMatrix.compose(position, rotation, Vector3_One).premultiply(parentMatrixInverse)
localMatrix.decompose(position, rotation, scale)
transform.matrix.compose(position, rotation, transform.scale)
transform.matrixWorld.multiplyMatrices(sceneTransform.matrixWorld, transform.matrix)

/** set all children dirty deeply, but set this entity to clean */
Expand Down

0 comments on commit c013946

Please sign in to comment.