Server Example: Primitive Grid
Overview
Spawns a grid of boxes, spheres, capsules, and cylinders to show the basic primitive creation APIs. It is a quick visual check for simple shapes and placements.
Screenshot
Binary
CMake target and executable name: primitive_grid.
Run
Build and run from your build directory:
cmake --build . --target primitive_grid
./primitive_grid
On Windows, run primitive_grid.exe instead.
This example uses RaisimServer. Start a visualizer client (RaisimUnity, RaisimUnreal, or the rayrai TCP viewer) and connect to port 8080.
Details
Creates a 3D lattice of boxes, spheres, capsules, and cylinders.
Assigns per-shape colors and positions them in a grid.
Useful for collision/rendering sanity checks.
Source
// This file is part of RaiSim. You must obtain a valid license from RaiSim Tech
// Inc. prior to usage.
#include "raisim/RaisimServer.hpp"
#include "raisim/World.hpp"
#include "rayrai_tcp_viewer_hint.hpp"
int main(int argc, char* argv[]) {
auto binaryPath = raisim::Path::setFromArgv(argv[0]);
raisim::World world;
world.setTimeStep(0.005);
/// create objects
auto ground = world.addGround();
ground->setName("ground");
// ground->setAppearance("grid");
std::vector<raisim::Box*> cubes;
std::vector<raisim::Sphere*> spheres;
std::vector<raisim::Capsule*> capsules;
std::vector<raisim::Cylinder*> cylinders;
static const int N = 6;
for (size_t i = 0; i < N; i++) {
for (size_t j = 0; j < N; j++) {
for (size_t k = 0; k < N; k++) {
std::string number =
std::to_string(i) + std::to_string(j) + std::to_string(k);
raisim::SingleBodyObject* ob = nullptr;
switch ((i + j + k) % 4) {
case 0:
cubes.push_back(world.addBox(1, 1, 1, 1));
ob = cubes.back();
ob->setAppearance("blue");
break;
case 1:
spheres.push_back(world.addSphere(0.5, 1));
ob = spheres.back();
ob->setAppearance("red");
break;
case 2:
capsules.push_back(world.addCapsule(0.5, 0.5, 1));
ob = capsules.back();
ob->setAppearance("green");
break;
case 3:
cylinders.push_back(world.addCylinder(0.5, 0.5, 1));
ob = cylinders.back();
ob->setAppearance("0.5, 0.5, 0.8, 1.0");
break;
}
ob->setPosition(-N + 2. * i, -N + 2. * j, 1. + 1.5 * k);
}
}
}
/// launch raisim server
raisim::RaisimServer server(&world);
server.launchServer();
raisim_examples::warnIfNoClientConnected(server);
while (1) {
RS_TIMED_LOOP(int(world.getTimeStep()*1e6))
server.integrateWorldThreadSafe();
}
server.killServer();
}