1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
//-----------------------------------------------------------------------------
// Name: bulletobject.h
// Developer: Wolfire Games LLC
// Description:
// License: Read below
//-----------------------------------------------------------------------------
//
// Copyright 2022 Wolfire Games LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-----------------------------------------------------------------------------
#pragma once
#include <Math/quaternions.h>
#include <opengl.h>
#include <vector>
#include <memory>
class btRigidBody;
class btCollisionShape;
class btTransform;
class Object;
struct CollideInfo;
enum CDLItype { _CDLI_CAPSULE };
class btTriangleIndexVertexArray;
struct btTriangleInfoMap;
struct ShapeDisposalData {
std::vector<int> faces;
btTriangleIndexVertexArray *index_vert_array;
btTriangleInfoMap *triangle_info_map;
ShapeDisposalData();
~ShapeDisposalData();
};
typedef std::shared_ptr<btCollisionShape> SharedShapePtr;
class BulletObject {
public:
mat4 transform;
mat4 old_transform;
std::vector<mat4> transform_history;
btRigidBody *body;
SharedShapePtr shape;
std::auto_ptr<ShapeDisposalData> shape_disposal_data;
bool visible;
vec3 com_offset;
short collision_group;
short collision_flags;
Object *owner_object;
vec3 color;
bool linked;
bool keep_history;
BulletObject();
~BulletObject();
void Collided(const vec3& pos, float impulse, const CollideInfo &collide_info);
void SetTransform( const vec4 &position, const mat4 &rotation, const vec4 &scale );
void SetTransform( const mat4 &transform );
void SetPosition( const vec3 &position);
void ApplyTransform(const mat4& transform);
void SetGravity(bool _gravity);
void SetDamping( float damping );
void SetDamping( float lin_damping, float ang_damping );
void ApplyTorque(const vec3 &torque);
vec3 GetInterpPosition();
mat4 GetInterpRotation();
void SetRotation( const mat4 &rotation);
void SetRotation( const quaternion &rotation);
void ClearVelocities();
void SetAngularVelocity(const vec3& vel);
void SetLinearVelocity(const vec3& vel);
vec3 GetPosition() const;
vec3 GetLinearVelocity() const;
vec3 GetAngularVelocity() const;
mat4 GetRotation() const;
vec3 ObjectToWorld(const vec3 &point);
void ApplyForceAtWorldPoint(const vec3 &point, const vec3 &impulse);
vec3 WorldToObject(const vec3 &world_point);
void SetVisibility(const bool _visible);
bool IsVisible() const;
void Activate();
void Freeze();
void UnFreeze();
void FixDiscontinuity();
void Dispose();
float GetMomentOfInertia(const vec3& axis);
void CopyObjectTransform(const BulletObject* other);
void MixObjectTransform( const BulletObject* other, float how_much );
float GetMass();
void SetMass(float mass);
void GetDisplayTransform(btTransform* display_transform);
quaternion GetQuatRotation();
void GetQuatDeltaRotation() const;
void UpdateTransform();
void SetPositionAndVel( const vec3 &position, int frames = 1);
void SetRotationAndVel( const mat4 &rotation, int frames = 1);
void SetRotationAndVel( const quaternion &rotation, int frames = 1);
void AddAngularVelocity( const vec3& vel );
void AddLinearVelocity( const vec3& vel );
bool IsActive();
void MixObjectVel( const BulletObject* other, float how_much );
void CopyObjectVel( const BulletObject* other );
mat4 GetTransform() const;
vec3 GetInterpPositionX( int num, int progress );
mat4 GetInterpRotationX( int num, int progress );
void Sleep();
void SetMargin( float _margin );
vec3 GetVelocityAtLocalPoint(const vec3& point);
void NoSleep();
void CanSleep();
void CheckForNAN();
float GetMargin( );
void SetShape(SharedShapePtr _shape);
void SetColShape(btCollisionShape *_shape);
vec3 GetHistoryInterpPositionX( int num, int progress, float offset );
mat4 GetHistoryInterpRotationX( int num, int progress, float offset );
vec3 GetInterpWeightPosition(float weight);
mat4 GetInterpWeightRotation(float weight);
};
void ValidateTransform(const btTransform &bt_transform);
|