differentiate between setPosition/queuePositionUpdate (+rotate), use EntityId in collision callback, fix collisions + add skiing effect
This commit is contained in:
@@ -39,8 +39,10 @@ namespace polyvox
|
||||
void transformToUnitCube(EntityId e);
|
||||
inline void updateTransform(EntityId e);
|
||||
void setScale(EntityId e, float scale);
|
||||
void setPosition(EntityId e, float x, float y, float z, bool relative);
|
||||
void setRotation(EntityId e, float rads, float x, float y, float z, float w, bool relative);
|
||||
void setPosition(EntityId e, float x, float y, float z);
|
||||
void setRotation(EntityId e, float rads, float x, float y, float z, float w);
|
||||
void queuePositionUpdate(EntityId e, float x, float y, float z, bool relative);
|
||||
void queueRotationUpdate(EntityId e, float rads, float x, float y, float z, float w, bool relative);
|
||||
const utils::Entity *getCameraEntities(EntityId e);
|
||||
size_t getCameraEntityCount(EntityId e);
|
||||
const utils::Entity *getLightEntities(EntityId e) const noexcept;
|
||||
@@ -101,7 +103,7 @@ namespace polyvox
|
||||
const char *entityName);
|
||||
int getEntityCount(EntityId entity, bool renderableOnly);
|
||||
const char* getEntityNameAt(EntityId entity, int index, bool renderableOnly);
|
||||
void addCollisionComponent(EntityId entity);
|
||||
void addCollisionComponent(EntityId entity, void (*onCollisionCallback)(EntityId entityId));
|
||||
|
||||
private:
|
||||
AssetLoader *_assetLoader = nullptr;
|
||||
|
||||
@@ -146,8 +146,10 @@ extern "C"
|
||||
FLUTTER_PLUGIN_EXPORT void clear_assets(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT bool set_material_color(void *assetManager, EntityId asset, const char *meshName, int materialIndex, const float r, const float g, const float b, const float a);
|
||||
FLUTTER_PLUGIN_EXPORT void transform_to_unit_cube(void *assetManager, EntityId asset);
|
||||
FLUTTER_PLUGIN_EXPORT void set_position(void *assetManager, EntityId asset, float x, float y, float z, bool relative);
|
||||
FLUTTER_PLUGIN_EXPORT void set_rotation(void *assetManager, EntityId asset, float rads, float x, float y, float z, float w, bool relative);
|
||||
FLUTTER_PLUGIN_EXPORT void queue_position_update(void *assetManager, EntityId asset, float x, float y, float z, bool relative);
|
||||
FLUTTER_PLUGIN_EXPORT void queue_rotation_update(void *assetManager, EntityId asset, float rads, float x, float y, float z, float w, bool relative);
|
||||
FLUTTER_PLUGIN_EXPORT void set_position(void *assetManager, EntityId asset, float x, float y, float z);
|
||||
FLUTTER_PLUGIN_EXPORT void set_rotation(void *assetManager, EntityId asset, float rads, float x, float y, float z, float w);
|
||||
FLUTTER_PLUGIN_EXPORT void set_scale(void *assetManager, EntityId asset, float scale);
|
||||
|
||||
// Camera methods
|
||||
@@ -176,14 +178,14 @@ extern "C"
|
||||
FLUTTER_PLUGIN_EXPORT void set_post_processing(void *const viewer, bool enabled);
|
||||
FLUTTER_PLUGIN_EXPORT void pick(void *const viewer, int x, int y, EntityId *entityId);
|
||||
FLUTTER_PLUGIN_EXPORT const char *get_name_for_entity(void *const assetManager, const EntityId entityId);
|
||||
FLUTTER_PLUGIN_EXPORT const EntityId find_child_entity_by_name(void *const assetManager, const EntityId parent, const char* name);
|
||||
FLUTTER_PLUGIN_EXPORT EntityId find_child_entity_by_name(void *const assetManager, const EntityId parent, const char* name);
|
||||
FLUTTER_PLUGIN_EXPORT int get_entity_count(void *const assetManager, const EntityId target, bool renderableOnly);
|
||||
FLUTTER_PLUGIN_EXPORT const char* get_entity_name_at(void *const assetManager, const EntityId target, int index, bool renderableOnly);
|
||||
FLUTTER_PLUGIN_EXPORT void set_recording(void *const viewer, bool recording);
|
||||
FLUTTER_PLUGIN_EXPORT void set_recording_output_directory(void *const viewer, const char* outputDirectory);
|
||||
FLUTTER_PLUGIN_EXPORT void ios_dummy();
|
||||
FLUTTER_PLUGIN_EXPORT void flutter_filament_free(void *ptr);
|
||||
FLUTTER_PLUGIN_EXPORT void add_collision_component(void *const assetManager, EntityId entityId);
|
||||
FLUTTER_PLUGIN_EXPORT void add_collision_component(void *const assetManager, EntityId entityId, void (*callback)(const EntityId entityId));
|
||||
FLUTTER_PLUGIN_EXPORT EntityId create_geometry(void *const viewer, float* vertices, int numVertices, uint16_t* indices, int numIndices, const char* materialPath);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -7,54 +7,71 @@
|
||||
#include "filament/TransformManager.h"
|
||||
#include "gltfio/FilamentAsset.h"
|
||||
#include "gltfio/FilamentInstance.h"
|
||||
#include "Log.hpp"
|
||||
|
||||
namespace polyvox
|
||||
{
|
||||
|
||||
class FloatComponentManager : public utils::SingleInstanceComponentManager<float, float, float, float> {
|
||||
|
||||
static constexpr size_t DIRECTION = 0;
|
||||
static constexpr size_t POSITION = 1;
|
||||
static constexpr size_t MAX = 2;
|
||||
static constexpr size_t SPEED = 2;
|
||||
|
||||
// void update() {
|
||||
// const auto* entities = getEntities();
|
||||
// for(int i = 0; i < getComponentCount(); i++) {
|
||||
// // const auto instance = getInstance();
|
||||
// // elementAt<POSITION>
|
||||
// // const auto component = get
|
||||
// // const auto entity = entities[i];
|
||||
|
||||
// }
|
||||
// }
|
||||
};
|
||||
|
||||
class CollisionComponentManager : public utils::SingleInstanceComponentManager<filament::gltfio::FilamentInstance*> {
|
||||
|
||||
static constexpr size_t INSTANCE = 0;
|
||||
typedef void(*CollisionCallback)(int32_t entityId) ;
|
||||
class CollisionComponentManager : public utils::SingleInstanceComponentManager<filament::Aabb, CollisionCallback> {
|
||||
|
||||
const filament::TransformManager& _transformManager;
|
||||
public:
|
||||
CollisionComponentManager(const filament::TransformManager& transformManager) : _transformManager(transformManager) {}
|
||||
|
||||
bool collides(filament::Aabb sourceBox) {
|
||||
std::vector<filament::math::float3> collides(filament::Aabb sourceBox, filament::math::float3 direction) {
|
||||
auto sourceCorners = sourceBox.getCorners();
|
||||
const auto& entities = getEntities();
|
||||
std::vector<filament::math::float3> collision_axes;
|
||||
for(auto it = begin(); it < end(); it++) {
|
||||
auto entity = entities[it];
|
||||
|
||||
auto targetInstance = elementAt<INSTANCE>(it);
|
||||
auto entity = getEntity(it);
|
||||
auto targetXformInstance = _transformManager.getInstance(entity);
|
||||
auto targetXform = _transformManager.getWorldTransform(targetXformInstance);
|
||||
auto targetBox = targetInstance->getBoundingBox().transform(targetXform);
|
||||
auto targetBox = elementAt<0>(it).transform(targetXform);
|
||||
|
||||
// iterate over every vertex in the source AABB
|
||||
for(int i = 0; i < 8; i++) {
|
||||
// if the vertex has insersected with the target AABB
|
||||
if(targetBox.contains(sourceCorners.vertices[i]) < 0) {
|
||||
return true;
|
||||
|
||||
auto intersecting = sourceCorners.vertices[i];
|
||||
auto min = targetBox.min;
|
||||
auto max = targetBox.max;
|
||||
|
||||
float xmin = min.x - intersecting.x;
|
||||
float ymin = min.y - intersecting.y;
|
||||
float zmin = min.z - intersecting.z;
|
||||
float xmax = intersecting.x - max.x;
|
||||
float ymax = intersecting.y - max.y;
|
||||
float zmax = intersecting.z - max.z;
|
||||
|
||||
auto maxD = std::max(xmin,std::max(ymin,std::max(zmin,std::max(xmax,std::max(ymax,zmax)))));
|
||||
filament::math::float3 axis;
|
||||
if(maxD == xmin) {
|
||||
axis = {-1.0f,0.0f, 0.0f};
|
||||
} else if(maxD == ymin) {
|
||||
axis = {0.0f,-1.0f, 0.0f};
|
||||
} else if(maxD == zmin) {
|
||||
axis = {0.0f,0.0f, -1.0f};
|
||||
} else if(maxD == xmax) {
|
||||
axis = {1.0f,0.0f, 0.0f};
|
||||
} else if(maxD == ymax) {
|
||||
axis = {0.0f,1.0f, 0.0f};
|
||||
} else {
|
||||
axis = { 0.0f, 0.0f, 1.0f};
|
||||
}
|
||||
collision_axes.push_back(axis);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(collision_axes.size() > 0) {
|
||||
auto callback = elementAt<1>(it);
|
||||
if(callback) {
|
||||
callback(utils::Entity::smuggle(entity));
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
return collision_axes;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user