-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WebXR] Helpers for working with simd types
https://bugs.webkit.org/show_bug.cgi?id=264910 rdar://118482297 Reviewed by Tim Horton. PlatformXRPose is a helper for working with transforms as simd4_float4x4. * Source/WebCore/SourcesCocoa.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/platform/xr/cocoa/PlatformXRPose.cpp: Added. (PlatformXRPose::position const): (PlatformXRPose::orientation const): (PlatformXRPose::pose const): (PlatformXRPose::distanceToPose const): (PlatformXRPose::verticalTransformPose const): (PlatformXRPose::PlatformXRPose): * Source/WebCore/platform/xr/cocoa/PlatformXRPose.h: Added. Canonical link: https://commits.webkit.org/270803@main
- Loading branch information
Showing
4 changed files
with
95 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (C) 2021 Apple Inc. All rights reserved. | ||
*/ | ||
|
||
#include "config.h" | ||
#include "PlatformXRPose.h" | ||
|
||
#if ENABLE(WEBXR) && PLATFORM(COCOA) | ||
|
||
WebCore::FloatPoint3D PlatformXRPose::position() const | ||
{ | ||
simd_float3 simdPosition = this->simdPosition(); | ||
return { static_cast<float>(simdPosition.x), static_cast<float>(simdPosition.y), static_cast<float>(simdPosition.z) }; | ||
} | ||
|
||
PlatformXR::Device::FrameData::FloatQuaternion PlatformXRPose::orientation() const | ||
{ | ||
simd_quatf simdOrientation = this->simdOrientation(); | ||
return { simdOrientation.vector.x, simdOrientation.vector.y, simdOrientation.vector.z, simdOrientation.vector.w }; | ||
} | ||
|
||
PlatformXR::Device::FrameData::Pose PlatformXRPose::pose() const | ||
{ | ||
PlatformXR::Device::FrameData::Pose pose; | ||
pose.position = position(); | ||
pose.orientation = orientation(); | ||
return pose; | ||
} | ||
|
||
float PlatformXRPose::distanceToPose(const PlatformXRPose& otherPose) const | ||
{ | ||
simd_float3 position = simdPosition(); | ||
simd_float3 otherPosition = otherPose.simdPosition(); | ||
return simd_distance(position, otherPosition); | ||
} | ||
|
||
PlatformXRPose PlatformXRPose::verticalTransformPose() const | ||
{ | ||
simd_float3 position = simdPosition(); | ||
simd_float4x4 transform = matrix_identity_float4x4; | ||
transform.columns[3].y = position.y; | ||
return PlatformXRPose(transform); | ||
} | ||
|
||
PlatformXRPose::PlatformXRPose(const simd_float4x4& transform) | ||
: m_simdTransform(transform) | ||
{ | ||
} | ||
|
||
PlatformXRPose::PlatformXRPose(const simd_float4x4& transform, const simd_float4x4& parentTransform) | ||
{ | ||
m_simdTransform = simd_mul(parentTransform, transform); | ||
} | ||
|
||
#endif // ENABLE(WEBXR) && PLATFORM(COCOA) |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (C) 2021 Apple Inc. All rights reserved. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#if ENABLE(WEBXR) && PLATFORM(COCOA) | ||
|
||
#include <WebCore/PlatformXR.h> | ||
#include <simd/simd.h> | ||
|
||
class PlatformXRPose { | ||
WTF_MAKE_FAST_ALLOCATED; | ||
|
||
public: | ||
simd_float4x4 simdTransform() const { return m_simdTransform; } | ||
simd_float3 simdPosition() const { return m_simdTransform.columns[3].xyz; } | ||
simd_quatf simdOrientation() const { return simd_quaternion(m_simdTransform); } | ||
WEBCORE_EXPORT WebCore::FloatPoint3D position() const; | ||
WEBCORE_EXPORT PlatformXR::Device::FrameData::FloatQuaternion orientation() const; | ||
WEBCORE_EXPORT PlatformXR::Device::FrameData::Pose pose() const; | ||
|
||
WEBCORE_EXPORT float distanceToPose(const PlatformXRPose&) const; | ||
WEBCORE_EXPORT PlatformXRPose verticalTransformPose() const; | ||
|
||
WEBCORE_EXPORT PlatformXRPose(const simd_float4x4&); | ||
WEBCORE_EXPORT PlatformXRPose(const simd_float4x4&, const simd_float4x4& parentTransform); | ||
|
||
private: | ||
simd_float4x4 m_simdTransform; | ||
}; | ||
|
||
#endif // ENABLE(WEBXR) && PLATFORM(COCOA) |