Question??

Hello, I am a PhD student and I need to use the following piece of code for my research but I do not understand it in partycular I do not know what AnalyticCollisionObject is doing

auto sphere_transform1 = [](T time, AnalyticCollisionObject<T, dim>& object) {
object.setTranslation(TV(4.25, 5, 5), TV(0, 0, 0));
};
auto sphere_transform2 = [](T time, AnalyticCollisionObject<T, dim>& object) {
T stretch_time = 3; // 3
T release_time = 4; // 4
if (time < stretch_time) {
T f = 0.1;
T theta = 2 * M_PI * f;
TV omega(-theta, 0, 0);
object.setRotation(Vector<T, 4>(1, 0, 0, 0));
object.setAngularVelocity(omega);
object.setTranslation(TV(5.75, 5, 5), TV(0, 0, 0));
}
else if (time < release_time) {
TV omega(0, 0, 0);
object.setRotation(Vector<T, 4>(1, 0, 0, 0));
object.setAngularVelocity(omega);
object.setTranslation(TV(5.75, 5, 5), TV(0, 0, 0));
}
else {
object.setTranslation(TV(15, 5, 5), TV(0, 0, 0));
}
};

TV sphere_center1(0, 0, 0);
Sphere<T, dim> sphere1(sphere_center1, 0.2);
AnalyticCollisionObject<T, dim> sphere_object1(sphere_transform1, sphere1, AnalyticCollisionObject<T, dim>::STICKY);
init_helper.addAnalyticCollisionObject(sphere_object1);
TV sphere_center2(0, 0, 0);
Sphere<T, dim> sphere2(sphere_center2, 0.2);
AnalyticCollisionObject<T, dim> sphere_object2(sphere_transform2, sphere2, AnalyticCollisionObject<T, dim>::STICKY);
init_helper.addAnalyticCollisionObject(sphere_object2);
First, please use code tags and consistent indentation when posting code. See https://www.cplusplus.com/articles/jEywvCM9/

This "code" is part of some function. All we see is some objects created, etc.

The "AnalyticCollisionObject" is a template for some type. The only thing that it apparently "does" occurs in its constructor. You did not show definition of that constructor. It is hard to explain what you can't observe.
AnalyticCollisionObject is a user defined variable type here.
it is being used to create the variable named 'object' which is then being used in the code.

This is an object (unfortunately his object name and the thing itself are going to make this hard to read!) from a template class, which may have syntax you do not understand (have you done templates in c++?) and that is why it looks odd to you.
note that it also uses lambda functions, which may also seem strange if you have not yet looked at those.

object.setRotation(Vector<T, 4>(1, 0, 0, 0));
object.setAngularVelocity(omega);
object.setTranslation(TV(5.75, 5, 5), TV(0, 0, 0));

the words used here tell us a bit more... its some sort of physics or graphics simulation on said object, its spinning and moving and such.

This is what I would call fairly advanced and modern c++ that will be challenging to read if you only know a little c++, or learned it long ago.
Last edited on
Try ROS.org. If you really are doing a PhD in a relevant discipline (i.e. not macrame etc) then you should be referring to that, not some code snippet the dog dragged in.
Topic archived. No new replies allowed.