45 std::string filename = getAssetPath() +
"Jeep/JeepGltf/jeep.gltf";
46 if (this->varFilePath()->getValue() != filename)
48 this->varFilePath()->setValue(
FilePath(filename));
51 auto instances = this->varVehiclesTransform()->getValue();
52 uint vehicleNum = instances.size();
53 for (
size_t i = 0; i < vehicleNum; i++)
57 rigidbody.
friction = this->varFrictionCoefficient()->getValue();
59 auto texMesh = this->stateTextureMesh()->constDataPtr();
62 std::vector <int> Wheel_Id = { 0,1,2,3 };
63 std::map<int, CapsuleInfo> wheels;
64 std::map<int, std::shared_ptr<PdActor>> actors;
66 for (
auto it : Wheel_Id)
68 auto up = texMesh->shapes()[it]->boundingBox.v1;
69 auto down = texMesh->shapes()[it]->boundingBox.v0;
71 wheels[it].center =
Vec3f(0.0f);
73 wheels[it].halfLength = 0.1;
74 wheels[it].radius = std::abs(up.y - down.y) / 2;
76 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[it]->boundingTransform.translation()) + instances[i].translation();
79 actors[it] = this->
addCapsule(wheels[it], rigidbody, 100);
87 std::vector <int> box_Id = { body,backWheel };
88 std::map<int, BoxInfo> boxs;
90 for (
auto it : box_Id)
92 auto up = texMesh->shapes()[it]->boundingBox.v1;
93 auto down = texMesh->shapes()[it]->boundingBox.v0;
95 boxs[it].center =
Vec3f(0.0f);
97 boxs[it].halfLength = (up - down) / 2;
100 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[it]->boundingTransform.translation()) + instances[i].translation();
102 actors[it] = this->
addBox(boxs[it], rigidbody, 100);
106 for (
auto it : box_Id)
111 for (
auto it : Wheel_Id)
118 Real wheel_velocity = 10;
121 for (
auto it : Wheel_Id)
124 joint.setAnchorPoint(actors[it]->center);
125 joint.setMoter(wheel_velocity);
129 auto& jointBackWheel_Body = this->
createFixedJoint(actors[backWheel], actors[body]);
130 jointBackWheel_Body.setAnchorPoint(actors[backWheel]->center);
163 std::string filename = getAssetPath() +
"gltf/Tank/Tank.gltf";
164 if (this->varFilePath()->getValue() != filename)
166 this->varFilePath()->setValue(
FilePath(filename));
169 auto instances = this->varVehiclesTransform()->getValue();
170 uint vehicleNum = instances.size();
171 for (
size_t i = 0; i < vehicleNum; i++)
175 rigidbody.
friction = this->varFrictionCoefficient()->getValue();
177 auto texMesh = this->stateTextureMesh()->constDataPtr();
180 std::vector <int> Wheel_Id = { 2,3,4,5,6,7,8,9,10,11,12,13,14,15 };
181 std::map<int, CapsuleInfo> wheels;
182 std::map<int, std::shared_ptr<PdActor>> actors;
184 for (
auto it : Wheel_Id)
186 auto up = texMesh->shapes()[it]->boundingBox.v1;
187 auto down = texMesh->shapes()[it]->boundingBox.v0;
189 wheels[it].center =
Vec3f(0.0f);
191 wheels[it].halfLength = 0.1;
192 wheels[it].radius = std::abs(up.y - down.y) / 2;
194 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[it]->boundingTransform.translation()) + instances[i].translation();
196 actors[it] = this->
addCapsule(wheels[it], rigidbody, 100);
204 std::vector <int> box_Id = { body,gun };
205 std::map<int, BoxInfo> boxs;
207 for (
auto it : box_Id)
209 auto up = texMesh->shapes()[it]->boundingBox.v1;
210 auto down = texMesh->shapes()[it]->boundingBox.v0;
212 boxs[it].center =
Vec3f(0.0f);
214 boxs[it].halfLength = (up - down) / 2 * 0.5;
217 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[it]->boundingTransform.translation()) + instances[i].translation();
219 actors[it] = this->
addBox(boxs[it], rigidbody, 100);
223 for (
auto it : box_Id)
228 for (
auto it : Wheel_Id)
235 Real wheel_velocity = 10;
238 for (
auto it : Wheel_Id)
241 joint.setAnchorPoint(actors[it]->center);
242 joint.setMoter(wheel_velocity);
247 jointGun_Body.setAnchorPoint(actors[gun]->center);
287 std::string filename = getAssetPath() +
"gltf/Tank/TrackedTank.gltf";
288 if (this->varFilePath()->getValue() != filename)
290 this->varFilePath()->setValue(
FilePath(filename));
293 auto instances = this->varVehiclesTransform()->getValue();
294 uint vehicleNum = instances.size();
295 for (
size_t i = 0; i < vehicleNum; i++)
299 rigidbody.
friction = this->varFrictionCoefficient()->getValue();
301 auto texMesh = this->stateTextureMesh()->constDataPtr();
302 std::map<int, std::shared_ptr<PdActor>> actors;
308 std::vector <int> Wheel_Id = { 1,2,3,4,6,7,8,10,11,12,13,15,16,17 };
310 for (
auto it : Wheel_Id)
312 auto up = texMesh->shapes()[it]->boundingBox.v1;
313 auto down = texMesh->shapes()[it]->boundingBox.v0;
315 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[it]->boundingTransform.translation()) + instances[i].translation();
323 capsule.
radius = (up[1] - down[1]) / 2;
326 float r = (up[1] - down[1]) / 2;
334 std::vector<int> gear = {0,5,9,14};
335 for (
size_t c = 0; c < 4; c++)
338 auto up = texMesh->shapes()[cid]->boundingBox.v1;
339 auto down = texMesh->shapes()[cid]->boundingBox.v0;
341 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[cid]->boundingTransform.translation()) + instances[i].translation();
348 for (
uint sec = 0; sec < 14; sec++)
354 float theta = sec *
M_PI / 7;
361 float r = (up[1] - down[1]) / 3;
362 float theta2 = sec *
M_PI / 7;
363 float y = r *
sin(theta2);
364 float z = r *
cos(theta2);
381 auto up = texMesh->shapes()[head]->boundingBox.v1;
382 auto down = texMesh->shapes()[head]->boundingBox.v0;
384 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[head]->boundingTransform.translation()) + instances[i].translation();
389 actors[head] = actor;
411 auto up = texMesh->shapes()[body]->boundingBox.v1;
412 auto down = texMesh->shapes()[body]->boundingBox.v0;
414 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[body]->boundingTransform.translation()) + instances[i].translation();
419 actors[body] = actor;
430 std::vector<int> caterpillarTrack_L;
431 std::vector<int> caterpillarTrack_R;
433 for (
int cid = 20; cid < 160; cid++)
435 auto up = texMesh->shapes()[cid]->boundingBox.v1;
436 auto down = texMesh->shapes()[cid]->boundingBox.v0;
438 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[cid]->boundingTransform.translation()) + instances[i].translation();
445 caterpillarTrack_L.push_back(cid);
447 caterpillarTrack_R.push_back(cid);
461 Real wheel_velocity = 10;
464 for (
auto it : Wheel_Id)
467 joint.setAnchorPoint(actors[it]->center);
468 joint.setMoter(wheel_velocity);
476 joint.setAnchorPoint(actors[it]->center);
477 joint.setMoter(wheel_velocity);
482 jointGun_Body.setAnchorPoint(actors[body]->center);
487 auto edgeset = this->statecaterpillarTrack()->getDataPtr();
488 std::vector<TopologyModule::Edge> edges;
489 std::vector<Vec3f> points;
490 for (
int k = 0; k < caterpillarTrack_L.size(); k++)
492 auto start = caterpillarTrack_L[k];
493 auto end = k != caterpillarTrack_L.size() - 1 ? caterpillarTrack_L[k + 1] : caterpillarTrack_L[0];
496 joint.setAnchorPoint((actors[start]->center + actors[end]->center) / 2);
499 points.push_back(actors[start]->center);
501 if (k != caterpillarTrack_L.size() - 1)
508 auto edgeOffset = points.size();
509 for (
int k = 0; k < caterpillarTrack_R.size(); k++)
511 auto start = caterpillarTrack_R[k];
512 auto end = k != caterpillarTrack_R.size() - 1 ? caterpillarTrack_R[k + 1] : caterpillarTrack_R[0];
515 joint.setAnchorPoint((actors[start]->center + actors[end]->center) / 2);
518 points.push_back(actors[start]->center);
520 if (k != caterpillarTrack_R.size() - 1)
526 edgeset->setPoints(points);
527 edgeset->setEdges(edges);
564 std::string filename = getAssetPath() +
"gltf/UAV/UAV.gltf";
565 if (this->varFilePath()->getValue() != filename)
567 this->varFilePath()->setValue(
FilePath(filename));
570 auto instances = this->varVehiclesTransform()->getValue();
571 uint vehicleNum = instances.size();
572 for (
size_t i = 0; i < vehicleNum; i++)
576 rigidbody.
friction = this->varFrictionCoefficient()->getValue();
578 auto texMesh = this->stateTextureMesh()->constDataPtr();
581 std::vector <int> Wheel_Id = { 0,1,2,3 };
582 std::map<int, CapsuleInfo> wheels;
583 std::map<int, std::shared_ptr<PdActor>> actors;
585 for (
auto it : Wheel_Id)
587 auto up = texMesh->shapes()[it]->boundingBox.v1;
588 auto down = texMesh->shapes()[it]->boundingBox.v0;
590 wheels[it].center =
Vec3f(0.0f);
592 auto rot = it == 0 || it == 3 ?
Vec3f(90, 45, 0) :
Vec3f(90, -45, 0);
602 wheels[it].halfLength = std::abs(up.x - down.x) / 1.5;
603 wheels[it].radius = std::abs(up.y - down.y) / 2;
605 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[it]->boundingTransform.translation()) + instances[i].translation();
608 actors[it] = this->
addCapsule(wheels[it], rigidbody, 100);
615 std::vector <int> box_Id = { body };
616 std::map<int, BoxInfo> boxs;
618 for (
auto it : box_Id)
620 auto up = texMesh->shapes()[it]->boundingBox.v1;
621 auto down = texMesh->shapes()[it]->boundingBox.v0;
623 boxs[it].center =
Vec3f(0.0f);
625 boxs[it].halfLength = (up - down) / 2 ;
628 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[it]->boundingTransform.translation()) + instances[i].translation();
631 actors[it] = this->
addBox(boxs[it], rigidbody, 100);
635 for (
auto it : box_Id)
640 for (
auto it : Wheel_Id)
650 for (
auto it : Wheel_Id)
652 Real wheel_velocity = (it == 0 || it == 3) ?
Real(20.0) :
Real(-20.0);
655 joint.setAnchorPoint(actors[it]->center);
656 joint.setMoter(wheel_velocity);
693 std::string filename = getAssetPath() +
"gltf/UUV/UUV.gltf";
694 if (this->varFilePath()->getValue() != filename)
696 this->varFilePath()->setValue(
FilePath(filename));
699 auto instances = this->varVehiclesTransform()->getValue();
700 uint vehicleNum = instances.size();
701 for (
size_t i = 0; i < vehicleNum; i++)
705 rigidbody.
friction = this->varFrictionCoefficient()->getValue();
707 auto texMesh = this->stateTextureMesh()->constDataPtr();
710 std::vector <int> Wheel_Id = { 1,2,3,4 };
711 std::map<int, CapsuleInfo> wheels;
712 std::map<int, std::shared_ptr<PdActor>> actors;
714 for (
auto it : Wheel_Id)
716 auto up = texMesh->shapes()[it]->boundingBox.v1;
717 auto down = texMesh->shapes()[it]->boundingBox.v0;
719 wheels[it].center =
Vec3f(0.0f);
721 auto rot = it == 1 || it == 2 ?
Vec3f(90, 30, 0) :
Vec3f(0, 0, 30);
731 wheels[it].halfLength = 0.13;
732 wheels[it].radius = 0.03;
734 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[it]->boundingTransform.translation()) + instances[i].translation();
737 actors[it] = this->
addCapsule(wheels[it], rigidbody, 100);
744 std::vector <int> box_Id = { body };
745 std::map<int, BoxInfo> boxs;
747 for (
auto it : box_Id)
749 auto up = texMesh->shapes()[it]->boundingBox.v1;
750 auto down = texMesh->shapes()[it]->boundingBox.v0;
752 boxs[it].center =
Vec3f(0.0f);
754 boxs[it].halfLength = (up - down) / 2;
757 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[it]->boundingTransform.translation()) + instances[i].translation();
760 actors[it] = this->
addBox(boxs[it], rigidbody, 100);
764 for (
auto it : box_Id)
769 for (
auto it : Wheel_Id)
779 for (
auto it : Wheel_Id)
781 Real wheel_velocity = 20;
784 joint.setAnchorPoint(actors[it]->center);
785 joint.setMoter(wheel_velocity);
787 joint.setAxis(
Quat1f(instances[i].rotation()).rotate(axis));
void bind(std::shared_ptr< PdActor > actor, Pair< uint, uint > shapeId)
std::shared_ptr< PdActor > addBox(const BoxInfo &box, const RigidBodyInfo &bodyDef, const Real density=Real(100))
HingeJoint & createHingeJoint(std::shared_ptr< PdActor > actor1, std::shared_ptr< PdActor > actor2)
std::shared_ptr< PdActor > createRigidBody(const Coord &p, const TQuat &q)
FixedJoint & createFixedJoint(std::shared_ptr< PdActor > actor1, std::shared_ptr< PdActor > actor2)
void bindBox(const std::shared_ptr< PdActor > actor, const BoxInfo &box, const Real density=Real(100))
std::shared_ptr< PdActor > addCapsule(const CapsuleInfo &capsule, const RigidBodyInfo &bodyDef, const Real density=Real(100))
void bindCapsule(const std::shared_ptr< PdActor > actor, const CapsuleInfo &capsule, const Real density=Real(100))
Vector< Real, 3 > offset
An offset from the barycenter to the geometric center.
Vector< Real, 3 > position
The barycenter of the body.