Fast Library Browsing with ChatGPT

In the last article, some aspects of the use of ChatGPT in the narrowly focused area of ​​​​study of the Bullet Physics library were considered in theory. Now I will try to give a practical example.

Let's get serious about surfing, shall we?

Let’s get serious about surfing, shall we?

To begin with, in a general way, we will discuss the situation: a person and a language model think differently. I’m not sure if this verb can be applied to the second object at all.

Intuitive start-up scheme

Intuitive start-up scheme

Let’s imagine the following situation. ChatGPT is aware of the library, it represents what physics is, but it knows absolutely nothing about what a person needs. On the other hand, there is a person who has a task, he is familiar with physics, but in general he is not familiar with the library

This means that, intuitively at the level of the hypothesis, there are various ways of interaction:

  1. Concrete instructions to channel the creativity of ChatGPT and optimize its data tools;

  2. Tell ChatGPT about yourself in detail so that he has an understanding of the interlocutor;

  3. Offer ChatGPT a role model to limit its reactions.

Here the first option will be considered with an eye to the previous article.

We have three areas of information that need to be combined in order to achieve practical results.

We have three areas of information that need to be combined in order to achieve practical results.

Despite the fact that we have one goal – to achieve a solution to our problem using the Bullet library, in the process of achieving it, it will be necessary to solve several subtasks:

  1. Use concepts related to physics;

  2. Increase understanding of tasks for ChatGPT;

  3. Increase the understanding of the library for the individual.

So, maybe I have a limited imagination, but I could not think of anything better in the form of a task than the implementation of a rebound of objects when a massive object falls. This is definitely not in the library in the form of a ready-made function, which means the result is unpredictable and interesting.

Let’s create a request:

Use the repositoryhttps://github.com/bulletphysics/bullet3” We have to create a demo like HelloWorld. We have to use the methods from the source folder. There is a falling object, a static object, and some suffering objects. When a falling object collides with a static object, then a force depending on the momentum of the collision is applied to the suffering objects, even if the hurt object and the falling object don’t directly collide, how can i do that?

Request to ChatGPT

Request to ChatGPT

Hereinafter, I apologize for the “soap”, since the original dialogues were lost, only the video remains

ChatGPT responded in stages, stuttering intermittently, but ended up suggesting the following.

ChatGPT specified implementation

ChatGPT specified implementation

Let’s consider separately how information moves.

ChatGPT

Human

Bullet

It must be used, as an implementation example, take the file HelloWorld

To solve the problem, you need to use btPersistentManifold, btRigitBody. Must be placed after(?) stepSimulation

Physics

It’s about solids.

Collisions can be between rigid bodies

Task

Need to create a working example with instructions

The task is directly connected by collision points

The resulting code looks like this:

for (int i = 0; i < numManifolds; i++)

{

	auto man = manifolds[i];

	int num_contacts = man->getNumContacts();

	for (int j = 0; j < num_contacts; j++)

	{

		btManifoldPoint mpt = man->getContactPoint(j);

}}

For testing purposes, we render the collision points using the UE. As soon as contact occurs, we create spheres of visible size. At least that’s in theory. In practice, this means that we will examine the btPersistentManifold array.

Red dots correspond to an array of btPersistentManifold objects

Link to timing video: Can ChatGPT help developer to create for using C++ libraries?

The solution generated with ChatGPT outputs too many dots. At the same time, it is doubtful that the engine itself processes all the points in general in the course of its work.

While writing the article, I noticed that not all points are tinted with red. The top points of the blue cubes are not marked. Unfortunately, this will not be used in the future. A negative consequence of the haste, as I didn’t really want to devote a large amount of time to the tests.

ChatGPT

Human

Bullet

Collisions between static objects are also considered

btPersistentManifold has too many points

Physics

Task

Need to filter data

If we accept the hypothesis that the Bullet physical library optimizes calculations as true, then we can try to disassemble the internal processes into their constituents and pick up the filtered values.

We are aware of the stepSimulation function from previous ChatGPT answers. We can assume that in the course of its work, the above function will filter the data:

  1. Exclude;

  2. Unite;

  3. Group;

  4. Ungroup

Let’s put forward the following hypothesis: if we parse the stepSimulation function into subprocesses, then it is possible to find a function that deals with filtering and the results of which can be used later.

Let’s reformulate the query:

You can write and describe a complete and sorted list of functions that are called sequentially during the execution of the stepSimulation method of the btDiscreteDynamicsWorld class in the repository https://github.com/bulletphysics/bullet3 and the given file along the path examples/HelloWorld/HelloWorld.cpp. You must follow the following instructions. You start from the first line of stepSimulation, read the lines until you reach the function, then add to the list of methods, then remember this position and jump to this function and read the lines in this function and add the found functions to the list. Don’t jump more than twice. If you reach the end of the method, then return to the memorized position and continue reading. If you reach the end of stepSimulation, leave it.

Request Screenshot

Request Screenshot

To be honest, only now do you understand how much this “stream of pure reason” is, after reading what came into an inflamed head at the time of communication.

However, ChatGPT did the trick. For the sake of experiment, I sent this text to the request in several “fresh” chats. In the worst case, on the third “regeneration” of the request, I received a response similar to the previous article.

Let me remind you that there I received a list of Bullet library functions in response to my request. And there is a certain possibility that this list is related to the stepSimulation work. The list contains the function calculateSimulationIslands, the description of which contains the word “group”. It looks like what we are looking for.

Line from ChatGPT response

Line from ChatGPT response

There is a new term “Simulation Islands”. A series of simple questions that broadly ask for information about related objects with the term leads to the following method.

Answer from ChatGPT

Answer from ChatGPT

The buildAndProcessIsland function directly specifies that it creates simulation islands and iterates over them by calling a special callback function. It seems that all we need is to pick up the data when it comes to the callback.

However, here I started to have a complete misunderstanding with ChatGPT. I asked him for the classes that inherit from this IslandCallback, including those related to HelloWorld, but he kept saying that btDiscreteDynamicWorld::IslandCallback exists, which doesn’t really exist. And InplaceSolverIslandCallback, which is found in a jiffy by a simple keyword search, refused to be found.

At some point, I gave up and just downloaded what I used at the beginning, now in InplaceSolverIslandCallback.

The result of the inserted function

The result of the inserted function

Link to timing video: Can ChatGPT help developer to create for using C++ libraries?

In such a complex way, you can come to something similar to what I’m trying to implement. After all, knowing the collision points, you can realize the original message, it remains only to realize the arrays of suffering cubes and determine the falling cube, then find the impact momentum and calculate the distance.

So ChatGPT proposes to determine whether the points belong to the falling body or not:

ChatGPT

ChatGPT

btCollisionObject * obj0 = manifold->getBody0();

So apply force:

ChatGPT

ChatGPT

body->applyForce(force, btVector3(0,0,0));

So take the momentum:

ChatGPT

ChatGPT

float impulse = point->m_appliedImpulse;

If we collect everything that was in one heap, then we get some solution to our problem.

Solution illustration

Solution illustration

Link to timing video: Can ChatGPT help developer to create for using C++ libraries?

Conclusion

This article discusses the practical application of using ChatGPT in solving problems.

Of the non-obvious problems voiced in the article, the following can be noted:

  1. I couldn’t “find” InplaceSolverIslandCallback using the chat. The cost of this problem is very low, as it is solved by a simple search.

  2. I was never able to get the chat to “suggest” the activate function, and without it, the suffering objects would not move. The cost of this problem is incredibly high, as even the documentation doesn’t explicitly mention it anywhere. The internal logic is such that only colliding objects are processed by the algorithms. In our case, the force is taken from “out of nowhere”, so the algorithm will simply ignore our addition of force. Here, some special approach is probably required.

  3. Didn’t notice that not all points were “tinted” at the first stage. Also, nothing can be said about the cost, because I simply lost sight of it. Perhaps I could find another solution to the problem.

In general, the article describes an interesting experience of jointly solving a problem with a language model, which means it can help someone and guide someone in the difficult path of learning new knowledge.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *