112 lines
2.6 KiB
C
Raw Normal View History

2013-08-29 11:45:22 +09:00
/*
Copyright (c) 2013 yvt
2013-08-29 11:45:22 +09:00
This file is part of OpenSpades.
2013-08-29 11:45:22 +09:00
OpenSpades is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
2013-08-29 11:45:22 +09:00
OpenSpades is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
2013-08-29 11:45:22 +09:00
You should have received a copy of the GNU General Public License
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
2013-08-29 11:45:22 +09:00
*/
2013-08-18 16:18:06 +09:00
#pragma once
#include <Core/Math.h>
2013-08-18 16:18:06 +09:00
namespace spades {
namespace client {
class IRenderer;
class GameMap;
class Player;
class IModel;
2013-08-18 16:18:06 +09:00
class Corpse {
enum NodeType {
// torso in CW seen from front
Torso1,
Torso2,
Torso3,
Torso4,
2013-08-18 16:18:06 +09:00
Arm1, // Torso1
Arm2, // Torso2
Leg1, // Torso3
Leg2, // Torso4
2013-08-18 16:18:06 +09:00
Head,
2013-08-18 16:18:06 +09:00
NodeCount
};
2013-08-18 16:18:06 +09:00
struct Node {
Vector3 pos, vel;
Vector3 lastPos;
2013-08-18 16:18:06 +09:00
Vector3 lastForce;
};
2013-09-13 01:33:51 +09:00
struct Edge {
NodeType node1, node2;
Vector3 lastVelDiff;
Vector3 velDiff;
Edge() { node1 = node2 = NodeCount; }
2013-09-13 01:33:51 +09:00
};
IRenderer &renderer;
GameMap &map;
2013-08-18 16:18:06 +09:00
Vector3 color;
int playerId;
2013-08-18 16:18:06 +09:00
Node nodes[NodeCount];
2013-09-13 01:33:51 +09:00
Edge edges[8];
2013-08-18 16:18:06 +09:00
void SetNode(NodeType n, Vector3);
void SetNode(NodeType n, Vector4);
void Spring(NodeType n1, NodeType n2, float distance, float dt);
void Spring(NodeType n1a, NodeType n1b, NodeType n2, float distance, float dt);
void AngleSpring(NodeType base, NodeType a, NodeType b, float minDot, float maxDot,
float dt);
void AngleSpring(NodeType a, NodeType b, Vector3 dir, float minDot, float maxDot,
float dt);
void AngularMomentum(int eId, NodeType a, NodeType b);
2013-08-18 16:18:06 +09:00
void ApplyConstraint(float dt);
2013-08-18 16:18:06 +09:00
void LineCollision(NodeType a, NodeType b, float dt);
2013-08-18 16:18:06 +09:00
public:
/**
* Construct a "corpse" client object.
*
* @param renderer The renderer. Must outlive `Corpse`.
* @param map The game map, used for physics. Must outlive `Corpse`.
* @param p The player to create a corpse from. Can be destroyed
* after `Corpse` is constructed.
*/
Corpse(IRenderer &renderer, GameMap &map, Player &p);
2013-08-18 16:18:06 +09:00
~Corpse();
2013-08-18 16:18:06 +09:00
void Update(float dt);
int GetPlayerId() { return playerId; }
2013-08-18 16:18:06 +09:00
void AddToScene();
2013-08-18 16:18:06 +09:00
Vector3 GetCenter();
bool IsVisibleFrom(Vector3 eye);
2013-08-18 16:18:06 +09:00
void AddImpulse(Vector3);
};
2019-07-17 00:31:22 +09:00
} // namespace client
} // namespace spades