PeriDyno 1.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Gear.cpp
Go to the documentation of this file.
1#include "Gear.h"
2
3#include "Mapping/DiscreteElementsToTriangleSet.h"
5
6namespace dyno
7{
8 //Gear
9 IMPLEMENT_TCLASS(Gear, TDataType)
10
11 template<typename TDataType>
13 ArticulatedBody<TDataType>()
14 {
15 auto mapper = std::make_shared<DiscreteElementsToTriangleSet<DataType3f>>();
16 this->stateTopology()->connect(mapper->inDiscreteElements());
17 this->graphicsPipeline()->pushModule(mapper);
18
19 auto sRender = std::make_shared<GLSurfaceVisualModule>();
20 sRender->setColor(Color(1, 1, 0));
21 sRender->setAlpha(0.5f);
22 mapper->outTriangleSet()->connect(sRender->inTriangleSet());
23 this->graphicsPipeline()->pushModule(sRender);
24 }
25
26 template<typename TDataType>
28 {
29
30 }
31
32 template<typename TDataType>
34 {
36 this->clearVechicle();
37
38 std::string filename = getAssetPath() + "gear/gear_up.obj";
39 if (this->varFilePath()->getValue() != filename)
40 {
41 this->varFilePath()->setValue(FilePath(filename));
42 }
43
44 //first gear
45 RigidBodyInfo info;
46 info.position = Vec3f(0.445f, 1.204f, -0.151);
47 info.angularVelocity = Vec3f(1, 0, 0);
49 info.bodyId = 0;
50 auto actor = this->createRigidBody(info);
51
52 CapsuleInfo capsule;
53 capsule.rot = Quat1f(M_PI / 2, Vec3f(0, 0, 1));
54 capsule.radius = 0.05f;
55 capsule.halfLength = 0.26f;
56
57 float r = 0.798f;
58 for (uint sec = 0; sec < 24; sec++)
59 {
60 float theta = sec * M_PI / 12 + 0.115;
61 float y = r * sin(theta);
62 float z = r * cos(theta);
63
64 capsule.center = Vec3f(-0.042f, y, z);
65 this->bindCapsule(actor, capsule);
66 }
67
68 this->bind(actor, Pair<uint, uint>(0, 0));
69
70 //**************************************************//
72 }
73
75}
#define DEFINE_CLASS(name)
Definition Object.h:140
#define IMPLEMENT_TCLASS(name, T1)
Definition Object.h:103
#define M_PI
Definition Typedef.inl:36
void bind(std::shared_ptr< PdActor > actor, Pair< uint, uint > shapeId)
void resetStates() override
~Gear() override
Definition Gear.cpp:27
void resetStates() override
Definition Gear.cpp:33
std::shared_ptr< GraphicsPipeline > graphicsPipeline()
Definition Node.cpp:320
std::shared_ptr< PdActor > createRigidBody(const Coord &p, const TQuat &q)
void bindCapsule(const std::shared_ptr< PdActor > actor, const CapsuleInfo &capsule, const Real density=Real(100))
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
DYN_FUNC Complex< Real > sin(const Complex< Real > &)
Definition Complex.inl:564
Quat< float > Quat1f
Definition Quat.h:136
DYN_FUNC Complex< Real > cos(const Complex< Real > &)
Definition Complex.inl:573
@ Kinematic
Vector< float, 3 > Vec3f
Definition Vector3D.h:93
unsigned int uint
Definition VkProgram.h:14
Vector< Real, 3 > center
Vector< Real, 3 > angularVelocity
The angular velocity of the body.
Vector< Real, 3 > position
The barycenter of the body.