mirror of https://github.com/zeldaret/botw.git
ksys/phys: Add CharacterControllerParam shape creation
This commit is contained in:
parent
dfcfbbe4a4
commit
a6268d3815
|
|
@ -94786,9 +94786,9 @@ Address,Quality,Size,Name
|
|||
0x0000007101281318,O,000420,_ZN4ksys4phys24CharacterControllerParam4Form5parseEN3agl3utl16ResParameterListEPN4sead4HeapE
|
||||
0x00000071012814bc,U,000112,phys::CharacterControllerParam::createController
|
||||
0x000000710128152c,U,000732,phys::CharacterControllerParam::createControllerState
|
||||
0x0000007101281808,O,000116,_ZN4ksys4phys24CharacterControllerParam10createFormEiPN4sead4HeapE
|
||||
0x000000710128187c,U,002128,phys::CharacterControllerParam::Form::createForm
|
||||
0x00000071012820cc,O,000120,_ZThn72_N4ksys4phys24CharacterControllerParam10createFormEiPN4sead4HeapE
|
||||
0x0000007101281808,O,000116,_ZN4ksys4phys24CharacterControllerParam11createShapeEiPN4sead4HeapE
|
||||
0x000000710128187c,O,002128,_ZNK4ksys4phys24CharacterControllerParam4Form11createShapeEPN4sead4HeapE
|
||||
0x00000071012820cc,O,000120,_ZThn72_N4ksys4phys24CharacterControllerParam11createShapeEiPN4sead4HeapE
|
||||
0x0000007101282144,O,000544,_ZN4ksys4phys24CharacterControllerParam4FormC1Ev
|
||||
0x0000007101282364,O,000168,_ZN4ksys4phys24CharacterControllerParam4FormD1Ev
|
||||
0x000000710128240c,O,000112,_ZN4ksys4phys24CharacterControllerParam4FormD0Ev
|
||||
|
|
|
|||
|
Can't render this file because it is too large.
|
|
|
@ -8,9 +8,9 @@ namespace ksys::phys {
|
|||
class PolytopeShape;
|
||||
|
||||
struct CharacterPrismShapeParam {
|
||||
float radius;
|
||||
sead::Vector3f translate_0;
|
||||
sead::Vector3f translate_1;
|
||||
float radius = 0.35;
|
||||
sead::Vector3f translate_0 = {0.5, 1.5, 1.8};
|
||||
sead::Vector3f translate_1 = sead::Vector3f::zero;
|
||||
CommonShapeParam common;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,15 @@
|
|||
#include "KingSystem/Physics/System/physCharacterControllerParam.h"
|
||||
#include <basis/seadRawPrint.h>
|
||||
#include "KingSystem/Physics/RigidBody/Shape/Box/physBoxShape.h"
|
||||
#include "KingSystem/Physics/RigidBody/Shape/Capsule/physCapsuleShape.h"
|
||||
#include "KingSystem/Physics/RigidBody/Shape/CharacterPrism/physCharacterPrismShape.h"
|
||||
#include "KingSystem/Physics/RigidBody/Shape/Cylinder/physCylinderShape.h"
|
||||
#include "KingSystem/Physics/RigidBody/Shape/List/physListShape.h"
|
||||
#include "KingSystem/Physics/RigidBody/Shape/Polytope/physPolytopeShape.h"
|
||||
#include "KingSystem/Physics/RigidBody/Shape/Sphere/physSphereShape.h"
|
||||
#include "KingSystem/Physics/RigidBody/Shape/physShape.h"
|
||||
#include "KingSystem/Physics/RigidBody/Shape/physShapeParamObj.h"
|
||||
#include "KingSystem/Utils/SafeDelete.h"
|
||||
|
||||
namespace ksys::phys {
|
||||
|
||||
|
|
@ -66,10 +76,10 @@ bool CharacterControllerParam::parse(agl::utl::ResParameterList res_list, sead::
|
|||
return true;
|
||||
}
|
||||
|
||||
void* CharacterControllerParam::createForm(int form_idx, sead::Heap* heap) {
|
||||
Shape* CharacterControllerParam::createShape(int form_idx, sead::Heap* heap) {
|
||||
if (form_idx >= getNumForms() || form_idx < 0)
|
||||
return nullptr;
|
||||
return forms[form_idx].createForm(heap);
|
||||
return forms[form_idx].createShape(heap);
|
||||
}
|
||||
|
||||
CharacterControllerParam::Form::Form()
|
||||
|
|
@ -102,6 +112,131 @@ bool CharacterControllerParam::Form::parse(agl::utl::ResParameterList res_list,
|
|||
return true;
|
||||
}
|
||||
|
||||
Shape* CharacterControllerParam::Form::createShape(sead::Heap* heap) const {
|
||||
if (*shape_num == 1) {
|
||||
switch (shape_params[0].getShapeType()) {
|
||||
case ShapeType::Sphere: {
|
||||
SphereShapeParam param;
|
||||
shape_params[0].getSphere(¶m);
|
||||
return SphereShape::make(param, heap);
|
||||
}
|
||||
|
||||
case ShapeType::Capsule: {
|
||||
CapsuleShapeParam param;
|
||||
shape_params[0].getCapsule(¶m);
|
||||
return CapsuleShape::make(param, heap);
|
||||
}
|
||||
|
||||
case ShapeType::Box: {
|
||||
BoxShapeParam param;
|
||||
shape_params[0].getBox(¶m);
|
||||
return BoxShape::make(param, heap);
|
||||
}
|
||||
|
||||
case ShapeType::Cylinder: {
|
||||
CylinderShapeParam param;
|
||||
shape_params[0].getCylinder(¶m);
|
||||
return CylinderShape::make(param, heap);
|
||||
}
|
||||
|
||||
case ShapeType::Polytope: {
|
||||
PolytopeShapeParam param;
|
||||
shape_params[0].getPolytope(¶m);
|
||||
auto* shape = PolytopeShape::make(param, heap);
|
||||
for (int i = 0, n = *shape_params[0].vertex_num; i < n; ++i) {
|
||||
shape->setVertex(i, *shape_params[0].vertices[i]);
|
||||
}
|
||||
shape->updateHavokShape();
|
||||
return shape;
|
||||
}
|
||||
|
||||
case ShapeType::CharacterPrism: {
|
||||
CharacterPrismShapeParam param;
|
||||
shape_params[0].getCharacterPrism(¶m);
|
||||
return CharacterPrismShape::make(param, heap);
|
||||
}
|
||||
|
||||
case ShapeType::List:
|
||||
case ShapeType::BoxWater:
|
||||
case ShapeType::CylinderWater:
|
||||
case ShapeType::Unknown:
|
||||
break;
|
||||
}
|
||||
|
||||
SEAD_ASSERT_MSG(false, "unsupported shape type for CharacterController with one shape");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ListShapeParam list_param;
|
||||
list_param.num_shapes = static_cast<decltype(list_param.num_shapes)>(*shape_num);
|
||||
|
||||
auto* list_shape = ListShape::make(list_param, heap);
|
||||
|
||||
for (int i = 0; i < int(list_param.num_shapes); ++i) {
|
||||
switch (shape_params[i].getShapeType()) {
|
||||
case ShapeType::Sphere: {
|
||||
SphereShapeParam param;
|
||||
shape_params[i].getSphere(¶m);
|
||||
list_shape->replaceWithNewSphere(i, param, heap);
|
||||
continue;
|
||||
}
|
||||
|
||||
case ShapeType::Capsule: {
|
||||
CapsuleShapeParam param;
|
||||
shape_params[i].getCapsule(¶m);
|
||||
list_shape->replaceWithNewCapsule(i, param, heap);
|
||||
continue;
|
||||
}
|
||||
|
||||
case ShapeType::Box: {
|
||||
BoxShapeParam param;
|
||||
shape_params[i].getBox(¶m);
|
||||
list_shape->replaceWithNewBox(i, param, heap);
|
||||
continue;
|
||||
}
|
||||
|
||||
case ShapeType::Cylinder: {
|
||||
CylinderShapeParam param;
|
||||
shape_params[i].getCylinder(¶m);
|
||||
list_shape->replaceWithNewCylinder(i, param, heap);
|
||||
continue;
|
||||
}
|
||||
|
||||
case ShapeType::Polytope: {
|
||||
PolytopeShapeParam param;
|
||||
shape_params[i].getPolytope(¶m);
|
||||
auto* shape =
|
||||
static_cast<PolytopeShape*>(list_shape->replaceWithNewPolytope(i, param, heap));
|
||||
for (int vertex = 0, n = *shape_params[i].vertex_num; vertex < n; ++vertex) {
|
||||
shape->setVertex(vertex, *shape_params[i].vertices[vertex]);
|
||||
}
|
||||
shape->updateHavokShape();
|
||||
continue;
|
||||
}
|
||||
|
||||
case ShapeType::CharacterPrism: {
|
||||
CharacterPrismShapeParam param;
|
||||
shape_params[i].getCharacterPrism(¶m);
|
||||
list_shape->replaceWithNewCharacterPrism(i, param, heap);
|
||||
continue;
|
||||
}
|
||||
|
||||
case ShapeType::List:
|
||||
case ShapeType::BoxWater:
|
||||
case ShapeType::CylinderWater:
|
||||
case ShapeType::Unknown:
|
||||
break;
|
||||
}
|
||||
|
||||
SEAD_ASSERT_MSG(false, "unsupported child shape type for CharacterController");
|
||||
util::safeDelete(list_shape);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
list_shape->updateHavokShape();
|
||||
return list_shape;
|
||||
}
|
||||
|
||||
int CharacterControllerParam::findFormIdx(const sead::SafeString& form_type) const {
|
||||
for (int i = 0, n = forms.size(); i < n; ++i) {
|
||||
if (form_type == *forms[i].form_type)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
namespace ksys::phys {
|
||||
|
||||
class Shape;
|
||||
struct ShapeParamObj;
|
||||
|
||||
SEAD_ENUM(NavMeshCharacterType,
|
||||
|
|
@ -37,8 +38,7 @@ bool navMeshCharacterTypeFromText(NavMeshCharacterType& value, const sead::SafeS
|
|||
|
||||
struct ICharacterControllerParam {
|
||||
virtual int getNumForms() = 0;
|
||||
// TODO: return type
|
||||
virtual void* createForm(int form_idx, sead::Heap* heap) = 0;
|
||||
virtual Shape* createShape(int form_idx, sead::Heap* heap) = 0;
|
||||
};
|
||||
|
||||
struct CharacterControllerParam : agl::utl::ParameterList, ICharacterControllerParam {
|
||||
|
|
@ -50,8 +50,7 @@ struct CharacterControllerParam : agl::utl::ParameterList, ICharacterControllerP
|
|||
|
||||
bool parse(agl::utl::ResParameterList res_list, sead::Heap* heap);
|
||||
|
||||
// TODO: return type
|
||||
void* createForm(sead::Heap* heap);
|
||||
Shape* createShape(sead::Heap* heap) const;
|
||||
|
||||
agl::utl::ParameterObj form_header_obj;
|
||||
agl::utl::Parameter<int> shape_num;
|
||||
|
|
@ -65,7 +64,7 @@ struct CharacterControllerParam : agl::utl::ParameterList, ICharacterControllerP
|
|||
auto operator=(const CharacterControllerParam&) = delete;
|
||||
|
||||
int getNumForms() override { return forms.size(); }
|
||||
void* createForm(int form_idx, sead::Heap* heap) override;
|
||||
Shape* createShape(int form_idx, sead::Heap* heap) override;
|
||||
|
||||
// TODO: return type
|
||||
void* createController(sead::Heap* heap);
|
||||
|
|
|
|||
Loading…
Reference in New Issue