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);
172 std::string filename = getAssetPath() +
"gltf/Tank/Tank.gltf";
173 if (this->varFilePath()->getValue() != filename)
175 this->varFilePath()->setValue(
FilePath(filename));
178 auto instances = this->varVehiclesTransform()->getValue();
179 uint vehicleNum = instances.size();
180 for (
size_t i = 0; i < vehicleNum; i++)
184 rigidbody.
friction = this->varFrictionCoefficient()->getValue();
186 auto texMesh = this->stateTextureMesh()->constDataPtr();
189 std::vector <int> Wheel_Id = { 2,3,4,5,6,7,8,9,10,11,12,13,14,15 };
190 std::map<int, CapsuleInfo> wheels;
191 std::map<int, std::shared_ptr<PdActor>> actors;
193 for (
auto it : Wheel_Id)
195 auto up = texMesh->shapes()[it]->boundingBox.v1;
196 auto down = texMesh->shapes()[it]->boundingBox.v0;
198 wheels[it].center =
Vec3f(0.0f);
200 wheels[it].halfLength = 0.1;
201 wheels[it].radius = std::abs(up.y - down.y) / 2;
203 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[it]->boundingTransform.translation()) + instances[i].translation();
205 actors[it] = this->
addCapsule(wheels[it], rigidbody, 100);
213 std::vector <int> box_Id = { body,gun };
214 std::map<int, BoxInfo> boxs;
216 for (
auto it : box_Id)
218 auto up = texMesh->shapes()[it]->boundingBox.v1;
219 auto down = texMesh->shapes()[it]->boundingBox.v0;
221 boxs[it].center =
Vec3f(0.0f);
223 boxs[it].halfLength = (up - down) / 2 * 0.5;
226 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[it]->boundingTransform.translation()) + instances[i].translation();
228 actors[it] = this->
addBox(boxs[it], rigidbody, 100);
232 for (
auto it : box_Id)
237 for (
auto it : Wheel_Id)
244 Real wheel_velocity = 10;
247 for (
auto it : Wheel_Id)
250 joint.setAnchorPoint(actors[it]->center);
251 joint.setMoter(wheel_velocity);
256 jointGun_Body.setAnchorPoint(actors[gun]->center);
296 std::string filename = getAssetPath() +
"gltf/Tank/TrackedTank.gltf";
297 if (this->varFilePath()->getValue() != filename)
299 this->varFilePath()->setValue(
FilePath(filename));
302 auto instances = this->varVehiclesTransform()->getValue();
303 uint vehicleNum = instances.size();
304 for (
size_t i = 0; i < vehicleNum; i++)
308 rigidbody.
friction = this->varFrictionCoefficient()->getValue();
310 auto texMesh = this->stateTextureMesh()->constDataPtr();
311 std::map<int, std::shared_ptr<PdActor>> actors;
317 std::vector <int> Wheel_Id = { 1,2,3,4,6,7,8,10,11,12,13,15,16,17 };
319 for (
auto it : Wheel_Id)
321 auto up = texMesh->shapes()[it]->boundingBox.v1;
322 auto down = texMesh->shapes()[it]->boundingBox.v0;
324 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[it]->boundingTransform.translation()) + instances[i].translation();
332 capsule.
radius = (up[1] - down[1]) / 2;
335 float r = (up[1] - down[1]) / 2;
343 std::vector<int> gear = { 0,5,9,14 };
344 for (
size_t c = 0; c < 4; c++)
347 auto up = texMesh->shapes()[cid]->boundingBox.v1;
348 auto down = texMesh->shapes()[cid]->boundingBox.v0;
350 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[cid]->boundingTransform.translation()) + instances[i].translation();
357 for (
uint sec = 0; sec < 14; sec++)
363 float theta = sec *
M_PI / 7;
370 float r = (up[1] - down[1]) / 3;
371 float theta2 = sec *
M_PI / 7;
372 float y = r *
sin(theta2);
373 float z = r *
cos(theta2);
390 auto up = texMesh->shapes()[head]->boundingBox.v1;
391 auto down = texMesh->shapes()[head]->boundingBox.v0;
393 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[head]->boundingTransform.translation()) + instances[i].translation();
398 actors[head] = actor;
420 auto up = texMesh->shapes()[body]->boundingBox.v1;
421 auto down = texMesh->shapes()[body]->boundingBox.v0;
423 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[body]->boundingTransform.translation()) + instances[i].translation();
428 actors[body] = actor;
439 std::vector<int> caterpillarTrack_L;
440 std::vector<int> caterpillarTrack_R;
442 for (
int cid = 20; cid < 160; cid++)
444 auto up = texMesh->shapes()[cid]->boundingBox.v1;
445 auto down = texMesh->shapes()[cid]->boundingBox.v0;
447 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[cid]->boundingTransform.translation()) + instances[i].translation();
451 rigidbody.
bodyId = i * 2 + 1;
455 caterpillarTrack_L.push_back(cid);
457 caterpillarTrack_R.push_back(cid);
464 capsule.
center =
Vec3f((up[0] - down[0]) / 2 - 0.05, 0, 0);
466 capsule.
center =
Vec3f((up[0] - down[0]) / 2 + 0.05, 0, 0);
470 capsule.
center =
Vec3f(-(up[0] - down[0]) / 2, 0, 0);
477 Real wheel_velocity = 10;
480 for (
auto it : Wheel_Id)
483 joint.setAnchorPoint(actors[it]->center);
492 joint.setAnchorPoint(actors[it]->center);
493 joint.setMoter(wheel_velocity);
498 jointGun_Body.setAnchorPoint(actors[body]->center);
503 auto edgeset = this->statecaterpillarTrack()->getDataPtr();
504 std::vector<TopologyModule::Edge> edges;
505 std::vector<Vec3f> points;
506 for (
int k = 0; k < caterpillarTrack_L.size(); k++)
508 auto start = caterpillarTrack_L[k];
509 auto end = k != caterpillarTrack_L.size() - 1 ? caterpillarTrack_L[k + 1] : caterpillarTrack_L[0];
512 joint.setAnchorPoint((actors[start]->center + actors[end]->center) / 2);
515 points.push_back(actors[start]->center);
517 if (k != caterpillarTrack_L.size() - 1)
524 auto edgeOffset = points.size();
525 for (
int k = 0; k < caterpillarTrack_R.size(); k++)
527 auto start = caterpillarTrack_R[k];
528 auto end = k != caterpillarTrack_R.size() - 1 ? caterpillarTrack_R[k + 1] : caterpillarTrack_R[0];
531 joint.setAnchorPoint((actors[start]->center + actors[end]->center) / 2);
534 points.push_back(actors[start]->center);
536 if (k != caterpillarTrack_R.size() - 1)
542 edgeset->setPoints(points);
543 edgeset->setEdges(edges);
580 std::string filename = getAssetPath() +
"gltf/UAV/UAV.gltf";
581 if (this->varFilePath()->getValue() != filename)
583 this->varFilePath()->setValue(
FilePath(filename));
586 auto instances = this->varVehiclesTransform()->getValue();
587 uint vehicleNum = instances.size();
588 for (
size_t i = 0; i < vehicleNum; i++)
592 rigidbody.
friction = this->varFrictionCoefficient()->getValue();
594 auto texMesh = this->stateTextureMesh()->constDataPtr();
597 std::vector <int> Wheel_Id = { 0,1,2,3 };
598 std::map<int, CapsuleInfo> wheels;
599 std::map<int, std::shared_ptr<PdActor>> actors;
601 for (
auto it : Wheel_Id)
603 auto up = texMesh->shapes()[it]->boundingBox.v1;
604 auto down = texMesh->shapes()[it]->boundingBox.v0;
606 wheels[it].center =
Vec3f(0.0f);
608 auto rot = it == 0 || it == 3 ?
Vec3f(90, 45, 0) :
Vec3f(90, -45, 0);
618 wheels[it].halfLength = std::abs(up.x - down.x) / 1.5;
619 wheels[it].radius = std::abs(up.y - down.y) / 2;
621 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[it]->boundingTransform.translation()) + instances[i].translation();
624 actors[it] = this->
addCapsule(wheels[it], rigidbody, 100);
631 std::vector <int> box_Id = { body };
632 std::map<int, BoxInfo> boxs;
634 for (
auto it : box_Id)
636 auto up = texMesh->shapes()[it]->boundingBox.v1;
637 auto down = texMesh->shapes()[it]->boundingBox.v0;
639 boxs[it].center =
Vec3f(0.0f);
641 boxs[it].halfLength = (up - down) / 2;
644 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[it]->boundingTransform.translation()) + instances[i].translation();
647 actors[it] = this->
addBox(boxs[it], rigidbody, 100);
651 for (
auto it : box_Id)
656 for (
auto it : Wheel_Id)
666 for (
auto it : Wheel_Id)
668 Real wheel_velocity = (it == 0 || it == 3) ?
Real(20.0) :
Real(-20.0);
671 joint.setAnchorPoint(actors[it]->center);
672 joint.setMoter(wheel_velocity);
709 std::string filename = getAssetPath() +
"gltf/UUV/UUV.gltf";
710 if (this->varFilePath()->getValue() != filename)
712 this->varFilePath()->setValue(
FilePath(filename));
715 auto instances = this->varVehiclesTransform()->getValue();
716 uint vehicleNum = instances.size();
717 for (
size_t i = 0; i < vehicleNum; i++)
721 rigidbody.
friction = this->varFrictionCoefficient()->getValue();
723 auto texMesh = this->stateTextureMesh()->constDataPtr();
726 std::vector <int> Wheel_Id = { 1,2,3,4 };
727 std::map<int, CapsuleInfo> wheels;
728 std::map<int, std::shared_ptr<PdActor>> actors;
730 for (
auto it : Wheel_Id)
732 auto up = texMesh->shapes()[it]->boundingBox.v1;
733 auto down = texMesh->shapes()[it]->boundingBox.v0;
735 wheels[it].center =
Vec3f(0.0f);
737 auto rot = it == 1 || it == 2 ?
Vec3f(90, 30, 0) :
Vec3f(0, 0, 30);
747 wheels[it].halfLength = 0.13;
748 wheels[it].radius = 0.03;
750 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[it]->boundingTransform.translation()) + instances[i].translation();
753 actors[it] = this->
addCapsule(wheels[it], rigidbody, 100);
760 std::vector <int> box_Id = { body };
761 std::map<int, BoxInfo> boxs;
763 for (
auto it : box_Id)
765 auto up = texMesh->shapes()[it]->boundingBox.v1;
766 auto down = texMesh->shapes()[it]->boundingBox.v0;
768 boxs[it].center =
Vec3f(0.0f);
770 boxs[it].halfLength = (up - down) / 2;
773 rigidbody.
position =
Quat1f(instances[i].rotation()).
rotate(texMesh->shapes()[it]->boundingTransform.translation()) + instances[i].translation();
776 actors[it] = this->
addBox(boxs[it], rigidbody, 100);
780 for (
auto it : box_Id)
785 for (
auto it : Wheel_Id)
795 for (
auto it : Wheel_Id)
797 Real wheel_velocity = 20;
800 joint.setAnchorPoint(actors[it]->center);
801 joint.setMoter(wheel_velocity);
803 joint.setAxis(
Quat1f(instances[i].rotation()).rotate(axis));
void bindShape(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))
void bindSphere(const std::shared_ptr< PdActor > actor, const SphereInfo &sphere, const Real density=Real(100))
Vector< Real, 3 > offset
An offset from the barycenter to the geometric center.