first commit

This commit is contained in:
2026-06-22 11:49:35 +02:00
commit d805f2ba86
619 changed files with 126873 additions and 0 deletions

View File

@ -0,0 +1,47 @@
/* -----------------------------------------------------------------------------
GSFramework
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */
#ifndef __NPHYSIC_CONSTRAINT__
#define __NPHYSIC_CONSTRAINT__
#include "physic/physic_item.h"
#include "physic/physic_constraint_desc.h"
namespace GS {
class Matrix4;
namespace S3D {
/*
@short Base physic constraint.
@author Emmanuel Julien (ejulien@gsworks.fr)
*/
class PhysicConstraint
{
protected:
PhysicConstraintDesc::Type type;
sPhysicItem item_a, item_b;
public:
virtual void SetPivotA(const Matrix4 &) = 0;
virtual void SetPivotB(const Matrix4 &) = 0;
virtual bool SetupConstraint(const PhysicConstraintDesc &) = 0;
virtual void DeleteConstraint() = 0;
virtual void Enable(bool = true) = 0;
PhysicConstraint() : type(PhysicConstraintDesc::TypeNone) {}
virtual ~PhysicConstraint() {}
};
} // S3D
} // GS
#endif // __NPHYSIC_CONSTRAINT__

View File

@ -0,0 +1,43 @@
/* -----------------------------------------------------------------------------
GSFramework
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */
#ifndef __NPHYSIC_CONSTRAINT_DESC__
#define __NPHYSIC_CONSTRAINT_DESC__
#include "scene3d/mitem.h"
#include "math/matrix4.h"
#include "memory/nweak_ptr.h"
namespace GS {
namespace NML { class Tag; }
namespace S3D {
//
struct PhysicConstraintDesc
{
enum Type
{
TypeNone = 0,
TypePoint,
TypeHinge
};
Type type;
WeakPtr <MItem> item_a, item_b;
Matrix4 pivot_a, pivot_b;
bool FromMetaTag(NML::Tag &);
NML::Tag *AsMetaTag() const;
};
} // S3D
} // GS
#endif // __NPHYSIC_CONSTRAINT_DESC__

View File

@ -0,0 +1,122 @@
/* -----------------------------------------------------------------------------
GSFramework
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */
#ifndef __NPHYSICITEM__
#define __NPHYSICITEM__
#include "memory/nshared_ptr.h"
#include "ntypes.h"
namespace GS {
struct Vector4;
class Matrix3;
class Matrix4;
namespace S3D {
struct PhysicItemDesc;
class PhysicWorld;
/*!
@short Abstract physic item.
@author Emmanuel Julien (ejulien@gsworks.fr)
*/
class PhysicItem : public SharedObject
{
protected:
void *user_ptr;
public:
void SetUserPointer(void *p) { user_ptr = p; }
void *GetUserPointer() const { return user_ptr; }
virtual void SetSelfMask(uint) = 0;
virtual void SetCollisionMask(uint) = 0;
virtual void SetLinearFactor(const Vector4 &) = 0;
virtual void SetAngularFactor(const Vector4 &) = 0;
virtual void SetScale(const Vector4 &) = 0;
virtual Vector4 GetScale() const = 0;
virtual void SetGravity(const Vector4 &) = 0;
virtual Vector4 GetGravity() const = 0;
virtual void ApplyImpulse(const Vector4 &I, const Vector4 *p = 0) = 0;
virtual void ApplyForce(const Vector4 &F, const Vector4 *p = 0) = 0;
virtual void ApplyTorque(const Vector4 &) = 0;
virtual void SetAngularVelocity(const Vector4 &) = 0;
virtual Vector4 GetAngularVelocity() const = 0;
virtual void SetLinearVelocity(const Vector4 &) = 0;
virtual Vector4 GetLinearVelocity() const = 0;
virtual Vector4 GetLocalPointVelocity(const Vector4 &) const = 0;
virtual Vector4 GetWorldPointVelocity(const Vector4 &) const = 0;
virtual void SetLinearDamping(float) = 0;
virtual float GetLinearDamping() const = 0;
virtual void SetAngularDamping(float) = 0;
virtual float GetAngularDamping() const = 0;
virtual Vector4 GetCenterOfMass() const = 0;
/*!
@short Vehicle.
@{
*/
virtual void VehicleSetForce(float nUnused(F), uint nUnused(wheel_index)) = 0;
virtual void VehicleSetBrake(float nUnused(F), uint nUnused(wheel_index)) = 0;
virtual void VehicleSetSteering(float nUnused(v), uint nUnused(wheel_index)) = 0;
virtual void VehicleSetFriction(float nUnused(f), uint nUnused(wheel_index)) = 0;
/// Get wheel matrix as returned by the model.
virtual Matrix4 VehicleGetWheelMatrix(uint nUnused(wheel_index)) = 0;
/// @}
/*!
@short Character.
@{
*/
virtual void CharacterSetRotationMatrix(const Matrix3 &) = 0;
virtual void CharacterSetVelocity(const Vector4 &) = 0;
/// @}
/*!
@short Get graphic matrix.
This is usually an interpolated version of the internal
current and previous matrices.
*/
virtual void GetGraphicMatrix(Matrix4 &) = 0;
virtual void SetEngineMatrix(const Matrix4 &) = 0;
virtual void GetMatrix(Matrix4 &) = 0;
virtual void SetMatrix(const Matrix4 &) = 0;
virtual void SetSleeping(bool = false) = 0;
virtual bool IsSleeping() const = 0;
virtual void SetActive(bool = true) = 0;
virtual bool GetActive() const = 0;
virtual void ResetBody() = 0;
virtual bool SetupBody(const PhysicItemDesc &, PhysicWorld *) = 0;
virtual void ForceUpdateMassShapePhysic(const PhysicItemDesc &, PhysicWorld *) = 0;
virtual void DeleteBody() = 0;
PhysicItem() : user_ptr(0) {}
virtual ~PhysicItem() {}
};
typedef SharedPtr <PhysicItem> sPhysicItem;
} // S3D
} // GS
#endif // __NPHYSICITEM__

View File

@ -0,0 +1,89 @@
/* -----------------------------------------------------------------------------
GSFramework
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */
#ifndef __NPHYSICITEMDESC__
#define __NPHYSICITEMDESC__
#include "physic/physic_shape.h"
#include "physic/physic_wheel.h"
#include "memory/bit_field.h"
namespace GS {
namespace S3D {
//
struct PhysicItemDesc
{
/// Physic mode.
enum Mode
{
Mode_None = 0,
Mode_Static,
Mode_Kinematic,
Mode_Dynamic,
Mode_Character,
Mode_Vehicle
};
/// Physic flag.
enum
{
PhysicFlag_None = 0,
PhysicFlag_NoGravity = (1 << 0),
PhysicFlag_Ghost = (1 << 1)
};
Mode physic_mode;
BitField physic_flags;
uint self_mask, collision_mask;
AutoList <PhysicShape *> shape_list;
float linear_damping, angular_damping;
Vector4 linear_factor, angular_factor;
struct Vehicle
{
AutoList <PhysicWheel *> wheel_list;
};
Vehicle vehicle;
struct Character
{
float radius;
float height;
float max_step;
Character() : radius(1), height(1), max_step(0.2f) {}
};
Character character;
float GetMass() const;
bool FromMetaTag(NML::Tag &);
NML::Tag *AsMetaTag() const;
PhysicItemDesc()
{
physic_mode = Mode_None;
linear_factor.Set(1, 1, 1);
angular_factor.Set(1, 1, 1);
linear_damping = 1;
angular_damping = 1;
self_mask = collision_mask = 1;
}
};
} // S3D
} // GS
#endif // __NPHYSICITEMDESC__

View File

@ -0,0 +1,57 @@
/* -----------------------------------------------------------------------------
GSFramework
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */
#ifndef __NPHYSIC_MESSAGE__
#define __NPHYSIC_MESSAGE__
class nPhysicConstraint;
class nPhysicItem;
/*
@short Physic message enum.
@author Emmanuel Julien (ejulien@gsworks.fr)
*/
enum nPhysicMessage
{
PhysicMsg_None = 0, ///< No message.
PhysicMsg_AddingConstraint,
PhysicMsg_ConstraintAdded,
PhysicMsg_DeletingConstraint,
PhysicMsg_ConstraintDeleted,
PhysicMsg_LastMessage
};
/*
@short Physic message return value.
@author Emmanuel Julien (ejulien@gsworks.fr)
*/
enum nPhysicReturnValue
{
PhysicReturn_Ok = 0
};
//
struct nPhysicConstraintMessage
{
nPhysicConstraint *c;
nPhysicConstraintMessage(nPhysicConstraint *_c)
{ c = _c; }
};
/// Physic listener.
class nPhysicListener
{
public:
virtual nPhysicReturnValue ProcessMessage(nPhysicMessage message, void *parm) = 0;
};
#endif // __NPHYSIC_MESSAGE__

View File

@ -0,0 +1,89 @@
/* -----------------------------------------------------------------------------
GSFramework
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */
#ifndef __NPHYSICSHAPE__
#define __NPHYSICSHAPE__
#include "physic/physic_wheel.h"
#include "container/narray.h"
#include "nstring/nstring.h"
namespace GS {
namespace NML { class Tag; }
namespace S3D {
/*!
@short Physic shape.
@author Emmanuel Julien (ejulien@gsworks.fr)
*/
struct PhysicShape
{
enum Type
{
TypeNone = 0,
TypeBox,
TypeSphere,
TypeConvex,
TypeCylinder,
TypeCone,
TypeCapsule,
TypeMesh,
TypeHeightmap
};
protected:
Type type;
int width, height;
Array <float> heightmap;
float resolution;
public:
void Free();
Matrix4 GetMatrix();
void SetMatrix(const Matrix4 &);
String path;
Vector4 position, ///< Position.
rotation, ///< Rotation.
scale, ///< Scale.
dimensions; ///< Dimensions.
float mass,
restitution,
dynamic_friction,
static_friction;
float *GetHeightmap() const { return heightmap; }
int GetWidth() const { return width; }
int GetHeight() const { return height; }
float GetResolution() const { return resolution; }
bool Set(float *heightmap, int width, int height, float resolution);
bool Set(Type, const char *path);
bool Set(Type = TypeNone, const Vector4 & = Vector4(1, 1, 1));
Type GetType() const { return type; }
bool FromMetaTag(NML::Tag &);
NML::Tag *AsMetaTag() const;
PhysicShape();
~PhysicShape();
};
} // S3D
} // GS
#endif // __NPHYSICSHAPE__

View File

@ -0,0 +1,61 @@
/* -----------------------------------------------------------------------------
GSFramework
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */
#ifndef __NPHYSICWHEEL__
#define __NPHYSICWHEEL__
#include "math/matrix4.h"
#include "memory/nshared_ptr.h"
#include "container/nlist.h"
namespace GS {
namespace NML { class Tag; }
namespace S3D {
/*!
@short Abstract physic wheel for the physic vehicle model.
@author Emmanuel Julien (ejulien@gsworks.fr)
*/
struct PhysicWheel
{
/*!
@name Wheel section.
@{
*/
float friction, radius;
/*!
@}
@name Suspension section.
@{
*/
Matrix4 ref_matrix; ///< Suspension origin in vehicle body space.
float rest_length,
max_compression,
stiffness,
damping;
/// @}
/*!
@name Serialization.
@{
*/
bool FromMetaTag(NML::Tag &tag);
NML::Tag *AsMetaTag() const;
/// @}
PhysicWheel();
};
typedef List <PhysicWheel *> PhysicWheelList;
} // S3D
} // GS
#endif // __NPHYSICWHEEL__

View File

@ -0,0 +1,137 @@
/* -----------------------------------------------------------------------------
GSFramework
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */
#ifndef __NPHYSICWORLD__
#define __NPHYSICWORLD__
#include "physic/physic_world_interface.h"
#include "physic/physic_message.h"
#include "math/vector.h"
#include "timing/benchmark.h"
#include "container/nlist.h"
#include "nstring/nstring.h"
namespace GS {
namespace Core { class Camera; }
namespace Render {
class Renderer;
class RasterFont;
}
namespace S3D {
class PhysicItem;
class PhysicConstraint;
struct PhysicShape;
using Core::Camera;
using Render::Renderer;
using Render::RasterFont;
/// Raytrace hit result structure.
struct PhysicTrace
{
Vector4 n, p; ///< Intersection normal and point in world space.
String m; ///< Material name at intersection point.
PhysicShape *s;
PhysicItem *i;
PhysicTrace() : m(0), s(0), i(0) {}
};
/// Collision pair.
struct CollisionPair
{
PhysicItem *a, *b;
uint contact_count;
Vector4 contact[4], normal[4];
CollisionPair() : a(0), b(0), contact_count(0) {}
};
/*
@short Abstract physic world.
@author Emmanuel Julien (ejulien@gsworks.fr)
*/
class PhysicWorld
{
protected:
float timestep,
substep_dt;
Vector4 gravity;
IPhysicWorld *world_interface;
public:
Benchmark bench_step;
virtual PhysicItem *NewItem() = 0;
virtual PhysicConstraint *NewConstraint() = 0;
/// Clear convex/mesh cache.
virtual void ClearConvexMeshCache() = 0;
virtual bool HasDebugger() const { return false; }
virtual void CreateDebugger(Renderer * = 0) {}
/// Draw debug informations (native library display).
virtual void DrawDebug(Renderer &, Camera *, RasterFont *, bool xray_first_pass) {}
void SetWorldInterface(IPhysicWorld *i) { world_interface = i; }
IPhysicWorld *GetWorldInterface() const { return world_interface; }
void SetTimestep(float t = 1.f / 60.f) { timestep = t; }
float GetTimestep() const { return timestep; }
void SetGravity(const Vector4 &g) { gravity = g; }
const Vector4 &GetGravity() const { return gravity; }
virtual bool Create() = 0;
virtual void Delete() = 0;
/// Raytrace world.
virtual bool Raytrace(const Vector4 &s, const Vector4 &d, PhysicTrace &hit, int collision_mask = ~0, int shape_mask = ~0, float max_distance = -1.f) = 0;
/// Return the number of collision pair in the previous step.
virtual uint GetCollisionPairCount() = 0;
/// Return the number of collision pair in the previous step.
virtual bool GetCollisionPair(uint n, CollisionPair &) = 0;
virtual void Step(const Time &dt) = 0;
/*!
@name Low-level message broadcasting system.
@{
*/
protected:
/// Physics message listener.
List <nPhysicListener *> listener_list;
public:
bool RegisterMessageListener(nPhysicListener *listener) { return asbool(listener_list.Add(listener)); }
bool UnregisterMessageListener(nPhysicListener *listener) { return listener_list.Remove(listener); }
void BroadcastMessage(nPhysicMessage msg, void *parm = 0)
{
ListForeachPtr(nPhysicListener *, listener, listener_list)
listener->ProcessMessage(msg, parm);
}
/// @}
PhysicWorld();
virtual ~PhysicWorld() {}
};
} // S3D
} // GS
#endif // __NPHYSICWORLD__

View File

@ -0,0 +1,30 @@
/* -----------------------------------------------------------------------------
GSFramework
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */
#ifndef __PHYSICWORLDINTERFACE__
#define __PHYSICWORLDINTERFACE__
namespace GS {
namespace S3D {
/*
@short Physic world interface.
@author Emmanuel Julien (ejulien@gsworks.fr)
*/
struct IPhysicWorld
{
/// Called whenever a physic tick is done.
virtual void PhysicStep(float, bool = true) {}
virtual ~IPhysicWorld() {}
};
} // S3D
} // GS
#endif // __PHYSICWORLDINTERFACE__