Skip to content

Commit 2f3b945

Browse files
committed
Squash commits
1 parent a90a60c commit 2f3b945

111 files changed

Lines changed: 5330 additions & 556 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1k/build.profiles

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,5 @@ kcp=2.1.1
9999
lz4=v1.10.0
100100
sample-assets=master
101101
live2d-core=5.5
102+
openxr=release-1.1.60
102103
# --- endregion

1k/fetch.ps1

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,18 @@ if (!(Test-Path "$lib_src/.git" -PathType Container)) { $is_git_repo = $false }
207207

208208
# checkout revision for git repo
209209
if (!$revision) {
210-
# regard v as tag or doesn't ends with short git hash
211-
if ($version.StartsWith('v')) {
212-
$revision = $version
210+
# Treat versions ending with "-<git-hash>" as pinned commits, for example:
211+
# 1.2.3-a1b2c3d
212+
# release-1.2.3-a1b2c3d4e5f6
213+
# Other names, including "v1.2.3", "release-1.2.3" and custom tag/branch names,
214+
# are passed through as-is and resolved by git below.
215+
$match_info = [Regex]::Match($version, '^(.*)-([0-9a-fA-F]{7,40})$')
216+
if ($match_info.Success) {
217+
$version = $match_info.Groups[1].Value
218+
$revision = $match_info.Groups[2].Value
213219
}
214220
else {
215-
$ver_pair = [array]$version.Split('-')
216-
$use_hash = $ver_pair.Count -gt 1
217-
$revision = $ver_pair[$use_hash].Trim()
218-
$version = $ver_pair[0]
221+
$revision = $version
219222
}
220223
}
221224

1k/sources.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
"gitee": "https://gitee.com/simdsoft/lz4.git"
2929
}
3030
},
31+
"openxr": {
32+
"sources": { "origin": "https://github.com/KhronosGroup/OpenXR-SDK.git" }
33+
},
3134
"sample-assets": {
3235
"sources": {
3336
"origin": "https://github.com/axmolengine/axmol-sample-assets.git",

3rdparty/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ if(ANDROID)
140140
endif()
141141

142142
ax_add_3rd(fmt)
143+
if (TARGET fmt-c)
144+
set_target_properties(fmt-c PROPERTIES FOLDER "3rdparty")
145+
endif()
143146

144147
# bellow are non header only libs
145148

@@ -427,6 +430,12 @@ ax_add_3rd(yasio)
427430
# simdjson
428431
ax_add_3rd(simdjson)
429432

433+
# openxr
434+
if (AX_ENABLE_OPENXR)
435+
_1kfetch(openxr)
436+
ax_add_3rd(${openxr_SOURCE_DIR} TARGETS openxr_loader)
437+
endif()
438+
430439
if(ANDROID)
431440
function(config_android_shared_libs package_name target_folder)
432441
string(REPLACE "." "/" package_path ${package_name})

axmol/2d/Menu.cpp

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ THE SOFTWARE.
3434
#include "axmol/base/text_utils.h"
3535
#include "axmol/platform/StdC.h"
3636

37+
#include <cmath>
38+
#include <limits>
3739
#include <vector>
3840

3941
using namespace std;
@@ -46,6 +48,40 @@ enum
4648
kDefaultPadding = 5,
4749
};
4850

51+
static bool hitTestNodeWithPointer(PointerEvent* event, const Camera* camera, Node* node, Vec3* outLocalHit)
52+
{
53+
if (!event || !camera || !node)
54+
return false;
55+
56+
Rect rect;
57+
rect.size = node->getContentSize();
58+
if (rect.size.width <= 0.0f || rect.size.height <= 0.0f)
59+
return false;
60+
61+
if (event->hasRay())
62+
{
63+
Ray localRay(event->getRay().value());
64+
localRay.transform(node->getWorldToNodeTransform());
65+
66+
if (std::abs(localRay.direction.z) <= std::numeric_limits<float>::epsilon())
67+
return false;
68+
69+
const float t = -localRay.origin.z / localRay.direction.z;
70+
if (t < 0.0f)
71+
return false;
72+
73+
Vec3 localHit = localRay.origin + t * localRay.direction;
74+
if (!rect.containsPoint(Vec2(localHit.x, localHit.y)))
75+
return false;
76+
77+
if (outLocalHit)
78+
*outLocalHit = localHit;
79+
return true;
80+
}
81+
82+
return camera->isWorldPointInRect(event->getLocation(), node->getWorldToNodeTransform(), rect, outLocalHit);
83+
}
84+
4985
//
5086
// CCMenu
5187
//
@@ -228,7 +264,8 @@ bool Menu::onPointerHitTest(PointerEvent* event, const Camera* camera, Vec3* out
228264
if (!event || !camera)
229265
return false;
230266

231-
if (!event->isPrimaryPressed())
267+
const bool isControllerRay = event->getPointerType() == PointerType::Controller && event->hasRay();
268+
if (!event->isPrimaryPressed() && !isControllerRay)
232269
return false;
233270

234271
if (_state != Menu::State::WAITING || !_visible || !_enabled)
@@ -576,18 +613,24 @@ void Menu::alignItemsInRowsWithArray(const ValueVector& columns)
576613

577614
MenuItem* Menu::hitTestItem(PointerEvent* event, const Camera* camera, Vec3* outHitPoint)
578615
{
579-
Vec2 touchLocation = event->getLocation();
580616
for (const auto& item : _children)
581617
{
582618
MenuItem* child = dynamic_cast<MenuItem*>(item);
583619
if (!child || !child->isVisible() || !child->isEnabled())
584620
{
585621
continue;
586622
}
587-
Rect rect;
588-
rect.size = child->getContentSize();
589-
if (camera->isWorldPointInRect(touchLocation, child->getWorldToNodeTransform(), rect, outHitPoint))
623+
624+
Vec3 childLocalHit;
625+
if (hitTestNodeWithPointer(event, camera, child, &childLocalHit))
590626
{
627+
if (outHitPoint)
628+
{
629+
Vec3 worldHit = childLocalHit;
630+
child->getNodeToWorldTransform().transformPoint(&worldHit);
631+
*outHitPoint = worldHit;
632+
getWorldToNodeTransform().transformPoint(outHitPoint);
633+
}
591634
return child;
592635
}
593636
}

axmol/2d/NodeGrid.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ Camera* NodeGrid::getGridCamera()
8484
{
8585
if (!_gridCamera)
8686
{
87-
_gridCamera = Camera::createCanvasOrthographic(-1, 1);
87+
_gridCamera = Camera::createOrthographicView(_director->getCanvasSize(), -1, 1);
8888
AX_SAFE_RETAIN(_gridCamera);
8989
}
9090

91-
_gridCamera->initCanvasOrthographic(-1, 1);
91+
_gridCamera->initOrthographicView(_director->getCanvasSize(), -1, 1);
9292
_gridCamera->setAdditionalTransform(Mat4::identity);
9393

9494
auto visitingCamera = Camera::getVisitingCamera();

axmol/2d/Transition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ void TransitionCrossFade::onEnter()
11241124
Vec2 size = _director->getCanvasSize();
11251125
LayerColor* layer = LayerColor::create(color);
11261126

1127-
auto camera = Camera::createCanvasOrthographic(-1024, 1024);
1127+
auto camera = Camera::createOrthographicView(_director->getCanvasSize(), -1024, 1024);
11281128

11291129
// create the first render texture for inScene
11301130
RenderTexture* inTexture =

axmol/2d/TransitionProgress.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void TransitionProgress::onEnter()
7979
sprite->setAnchorPoint(Vec2(0.5f, 0.5f));
8080

8181
// render outScene to its texturebuffer
82-
auto camera = Camera::createCanvasOrthographic(-1024, 1024);
82+
auto camera = Camera::createOrthographicView(_director->getCanvasSize(), -1024, 1024);
8383

8484
{
8585
RefPtr<RenderTexturePass> pass(RenderTexturePass::obtain(texture), tlx::adopt_object);

axmol/3d/Terrain.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ THE SOFTWARE.
2929
using namespace ax;
3030
#include <stdlib.h>
3131
#include <float.h>
32+
#include <limits>
3233
#include <set>
3334
#include <stddef.h> // offsetof
3435
#include "axmol/renderer/Renderer.h"
@@ -38,6 +39,7 @@ using namespace ax;
3839
#include "axmol/rhi/Buffer.h"
3940
#include "axmol/base/Director.h"
4041
#include "axmol/base/Types.h"
42+
#include "axmol/base/PointerEvent.h"
4143
#include "axmol/tlx/vector.hpp"
4244
#include "axmol/tlx/utility.hpp"
4345
#include "axmol/base/EventType.h"
@@ -507,6 +509,49 @@ ax::Vec3 Terrain::getIntersectionPoint(const Ray& ray) const
507509
}
508510
}
509511

512+
bool Terrain::onPointerHitTest(PointerEvent* event, const Camera* camera, Vec3* outHitPoint)
513+
{
514+
if (!event || !camera || !isVisible())
515+
return false;
516+
517+
Ray ray = event->hasRay() ? event->getRay().value() : camera->screenToRay(event->getScreenLocation());
518+
if (event->hasRay())
519+
{
520+
auto sourceCamera = Camera::getDefaultCamera();
521+
if (sourceCamera && sourceCamera != camera)
522+
{
523+
ray.transform(sourceCamera->getWorldToNodeTransform());
524+
ray.transform(camera->getNodeToWorldTransform());
525+
}
526+
}
527+
Vec3 hitPoint;
528+
529+
bool hitted = getIntersectionPoint(ray, hitPoint);
530+
if (event->getPhase() == InputPhase::PointerDown)
531+
{
532+
AXLOGI("Terrain::onPointerHitTest: ray origin: ({}, {}, {}), direction: ({}, {}, {}), hitted: {}, camera: {}", ray.origin.x,
533+
ray.origin.y, ray.origin.z, ray.direction.x, ray.direction.y, ray.direction.z, hitted, (void*)camera);
534+
}
535+
if (!hitted)
536+
return false;
537+
538+
if (outHitPoint)
539+
{
540+
Vec3 worldHitPoint = hitPoint;
541+
getNodeToWorldTransform().transformPoint(&worldHitPoint);
542+
543+
auto distanceToRaySq = [&ray](const Vec3& point) {
544+
const float distance = (point - ray.origin).dot(ray.direction);
545+
const Vec3 closest = ray.origin + ray.direction * distance;
546+
return closest.distanceSquared(point);
547+
};
548+
549+
*outHitPoint = distanceToRaySq(worldHitPoint) < distanceToRaySq(hitPoint) ? worldHitPoint : hitPoint;
550+
}
551+
552+
return true;
553+
}
554+
510555
bool Terrain::getIntersectionPoint(const Ray& ray_, Vec3& intersectionPoint) const
511556
{
512557
// convert ray from world space to local space

axmol/3d/Terrain.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ class AX_DLL Terrain : public Node
415415

416416
// Overrides, internal use only
417417
void draw(ax::Renderer* renderer, const ax::Mat4& transform, uint32_t flags) override;
418+
bool onPointerHitTest(PointerEvent* event, const Camera* camera, Vec3* outHitPoint) override;
419+
418420
/**
419421
* Ray-Terrain intersection.
420422
* @return the intersection point

0 commit comments

Comments
 (0)