Tweaked water physics
This commit is contained in:
@@ -15,11 +15,16 @@ CharacterModule::CharacterModule(flecs::world &ecs)
|
||||
AnimationControl::ANIM_NONE, false,
|
||||
false });
|
||||
player.set<CharacterBase>(
|
||||
{ "normal-male.glb", nullptr, nullptr, nullptr });
|
||||
{ "normal-male.glb", 0.0f, nullptr, nullptr, nullptr });
|
||||
player.set<CharacterBody>(
|
||||
{ nullptr, nullptr, nullptr, { 0, 0, 0 }, false, false });
|
||||
player.add<Character>();
|
||||
player.add<Player>();
|
||||
ecs.system<EngineData, CharacterBase>("UpdateTimer")
|
||||
.kind(flecs::OnUpdate)
|
||||
.each([this](EngineData &eng, CharacterBase &ch) {
|
||||
ch.mTimer += eng.delta;
|
||||
});
|
||||
ecs.system<Input, Camera>("HandleInput")
|
||||
.kind(flecs::OnUpdate)
|
||||
.each([this](Input &input, Camera &camera) {
|
||||
@@ -191,20 +196,30 @@ CharacterModule::CharacterModule(flecs::world &ecs)
|
||||
Ogre::Vector3 colNormal;
|
||||
bool is_on_floor = false;
|
||||
bool penetration = false;
|
||||
Ogre::Vector3 gravity(0, -9.8, 0);
|
||||
Ogre::Vector3 gravity(0, -9.8f, 0);
|
||||
if (e.has<InWater>()) {
|
||||
float volume = 2.0f * 0.5f * 0.5f;
|
||||
float density = 900.0f;
|
||||
float full_subm = 2.0f;
|
||||
float mass = 80.0f;
|
||||
float multiplier = 0.25f;
|
||||
float current_subm = -Ogre::Math::Clamp(
|
||||
pos.y, -full_subm, 0.0f);
|
||||
float b = 9.0 * current_subm / full_subm;
|
||||
body.gvelocity +=
|
||||
(gravity + Ogre::Vector3(0, b, 0)) *
|
||||
delta;
|
||||
pos.y + Ogre::Math::Sin(ch.mTimer *
|
||||
0.13f +
|
||||
130.0f) *
|
||||
0.07f,
|
||||
-full_subm, 0.0f);
|
||||
|
||||
Ogre::Vector3 b = -gravity * density * volume *
|
||||
multiplier * current_subm /
|
||||
full_subm / mass;
|
||||
body.gvelocity += (gravity + b) * delta;
|
||||
body.gvelocity.y = Ogre::Math::Clamp(
|
||||
body.gvelocity.y, -1.0f, 1.0f);
|
||||
body.gvelocity.y, -2.5f, 2.5f);
|
||||
std::cout << "InWater!!!!!!!\n";
|
||||
} else
|
||||
body.gvelocity += gravity * delta;
|
||||
body.gvelocity *= 0.99;
|
||||
velocity += body.gvelocity;
|
||||
Ogre::Vector3 rotMotion = velocity * delta;
|
||||
btVector3 currentPosition =
|
||||
|
||||
@@ -9,6 +9,7 @@ struct Character {}; /* tag */
|
||||
struct Player {}; /* tag */
|
||||
struct CharacterBase {
|
||||
Ogre::String type;
|
||||
float mTimer;
|
||||
Ogre::SceneNode *mBodyNode;
|
||||
Ogre::Entity *mBodyEnt;
|
||||
Ogre::Skeleton *mSkeleton;
|
||||
|
||||
@@ -300,21 +300,27 @@ WaterModule::WaterModule(flecs::world &ecs)
|
||||
int i;
|
||||
if (!body.mWaterBody) {
|
||||
btCompoundShape *shape = new btCompoundShape;
|
||||
btBoxShape *boxShape0 = new btBoxShape(
|
||||
btVector3(1000, 10, 1000));
|
||||
btBoxShape *boxShape1 = new btBoxShape(
|
||||
btVector3(1000, 20, 1000));
|
||||
btBoxShape *boxShape2 = new btBoxShape(
|
||||
btVector3(1000, 100, 1000));
|
||||
btBoxShape *boxShape3 = new btBoxShape(
|
||||
btVector3(1000, 1000, 1000));
|
||||
btTransform boxShapeXform0(btQuaternion(),
|
||||
btVector3(0, -10.2f,
|
||||
0));
|
||||
btTransform boxShapeXform1(btQuaternion(),
|
||||
btVector3(0, -20.2f,
|
||||
btVector3(0, -30.2f,
|
||||
0));
|
||||
btTransform boxShapeXform2(btQuaternion(),
|
||||
btVector3(0, -120.2f,
|
||||
btVector3(0, -130.2f,
|
||||
0));
|
||||
btTransform boxShapeXform3(
|
||||
btQuaternion(),
|
||||
btVector3(0, -1120.2f, 0));
|
||||
shape->addChildShape(boxShapeXform0, boxShape0);
|
||||
shape->addChildShape(boxShapeXform1, boxShape1);
|
||||
shape->addChildShape(boxShapeXform2, boxShape2);
|
||||
shape->addChildShape(boxShapeXform3, boxShape3);
|
||||
|
||||
@@ -42,9 +42,10 @@ uniform float noise; // the noise perturb as a factor of the time
|
||||
)
|
||||
#line 41
|
||||
//vec4 wave_a = vec4(1.0, 1.0, 0.35, 3.0); // xy = Direction, z = Steepness, w = Length
|
||||
f32vec4 wave_a = vec4(1.0, 1.0, 0.55, 24.3); // xy = Direction, z = Steepness, w = Length
|
||||
f32vec4 wave_b = vec4(1.0, 0.6, 0.29, 12.55); // xy = Direction, z = Steepness, w = Length
|
||||
f32vec4 wave_c = vec4(1.0, 1.41, 0.11, 10.8); // xy = Direction, z = Steepness, w = Length
|
||||
f32vec4 wave_a = vec4(1.0, 1.0, 0.08, 35.3); // xy = Direction, z = Steepness, w = Length
|
||||
f32vec4 wave_b = vec4(1.0, 0.6, 0.02, 21.55); // xy = Direction, z = Steepness, w = Length
|
||||
f32vec4 wave_c = vec4(1.0, 1.41, 0.01, 0.8); // xy = Direction, z = Steepness, w = Length
|
||||
f32vec4 wave_d = vec4(-1.2, 1.0, 0.01, 0.1); // xy = Direction, z = Steepness, w = Length
|
||||
|
||||
f32vec4 wave(f32vec4 parameter, f32vec2 position, float32_t t, inout f32vec3 tangent, inout f32vec3 binormal)
|
||||
{
|
||||
@@ -102,6 +103,7 @@ MAIN_DECLARATION
|
||||
position += wave(wave_a, vertex_position.xz, time, tang, bin);
|
||||
position += wave(wave_b, vertex_position.xz, time, tang, bin);
|
||||
position += wave(wave_c, vertex_position.xz, time, tang, bin);
|
||||
position += wave(wave_d, vertex_position.xz, time, tang, bin);
|
||||
vtangent = tang;
|
||||
vbinormal = bin;
|
||||
vertex_position = position.xyz;
|
||||
|
||||
Reference in New Issue
Block a user