Dimitrios Christopoulos - Collision detection tutorial

Здесь есть возможность читать онлайн «Dimitrios Christopoulos - Collision detection tutorial» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Collision detection tutorial: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Collision detection tutorial»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

Collision detection tutorial — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Collision detection tutorial», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

The problem lies in determining if 2 MOVING spheres collide. Bellow is an example where 2 sphere move during a time step from on point to another. Their paths cross in-between but this is not enough to prove that an intersection occurred (they could pass at a different time) nor can be the collision point be determined.

Figure 1

The previous intersection methods were solving the equations of the objects to determine the intersection. When using complex shapes or when these equations are not available or can not be solved, a different method has to be used. The start points, endpoints, time step, velocity (direction of the sphere + speed) of the sphere and a method of how to compute intersections of static spheres is already known. To compute the intersection, the time step has to be sliced up into smaller pieces. Then we move each time the spheres according to that sliced time step using its velocity, and check for collisions. If at any point collision is found (which means the spheres have already penetrated each other) then we take the previous position as the intersection point (we could start interpolating between these points to find the exact intersection position, but that is mostly not required).

The smaller the time steps, the more slices we use the more accurate is the method. As an example lets say the time step is 1 and our slices are 3, then we would check the two balls for collision at time 0 , 0.33, 0.66, 1. Easy !!!! The code which performs this is

/*************************************************************************************/

/*************************************************************************************/

/*** Find if any of the current balls ****/

/*** intersect with each other in the current timestep ****/

/***Returns the index of the 2 intersecting balls, the point and time of intersection */

/*************************************************************************************/

/*************************************************************************************/

int FindBallCol(TVector& point, double& TimePoint, double Time2, int& BallNr1, int& BallNr2) {

TVector RelativeV;

TRay rays;

double MyTime=0.0, Add=Time2/150.0, Timedummy=10000, Timedummy2=-1;

TVector posi;

//Test all balls against each other in 150 small steps

for (int i=0; i < NrOfBalls - 1; i++) {

for (int j = i+1; j < NrOfBalls; j++) {

RelativeV = ArrayVel[i] - ArrayVel[j]; // Find distance

rays = TRay(OldPos[i], TVector::unit(RelativeV));

MyTime = 0.0;

if ( (rays.dist(ArrayPos[j])) > 40) continue; //If distance between centers bigger than 2*radius

//an intersection occurred

while (MyTime < Time2) //Loop to find the exact intersection point

{

MyTime += Add;

posi = OldPos[i] + RelativeV * MyTime;

if (posi.dist(OldPos[j]) <= 40) {

point = posi;

if (Timedummy > (MyTime - Add)) Timedummy = MyTime - Add;

BallNr1 = i;

BallNr2 = j;

break;

}

}

}

}

if (Timedummy != 10000) {

TimePoint = Timedummy;

return 1;

}

return 0;

}

How to use what we just learned

So now that we can determine the intersection point between a ray and a plane/cylinder we have to use it somehow to determine the collision between a sphere and one of these primitives. What we can do so far is determine the exact collision point between a particle and a plane/cylinder. The start position of the ray is the position of the particle and the direction of the ray its velocity (speed and direction). To make it usable for spheres is quite easy. Look at Figure 2a to see how this can be accomplished.

Figure 2a Figure 2b

Each sphere has a radius, take the center of the sphere as the particle and offset the surface along the normal of each plane/cylinder of interest. In Figure 2a these new primitives are represented with doted lines. Your actual primitives of interest are the ones represented with continuous lines but the collision testing is done with the offset primitives (represented with doted lines). In essence we perform the intersection test with an little offset plane and a larger in radius cylinder. Using this little trick the ball does not penetrate the surface if an intersection is determined with its center. Otherwise we get a situation as in Figure 2b, where be sphere penetrates the surface. This happens because we determine the intersection between its center and the primitives, which means we did not modify our original code!

Having determined where the collision takes place we have to determine if the intersection takes place in our current time step. Timestep is the time we move our sphere from its current point according to its velocity. Because we are testing with infinite rays there is always the possibility that the collision point is after the new position of the sphere. To determine this we move the sphere, calculate its new position and find the distance between the start and end point. From our collision detection procedure we get also the distance from the start point to its collision point. If this distance is less than the distance between start and end point then there is a collision. To calculate the exact time we solve this simple equation. Represent the distance between start – end point with Dst, the distance between start – collision point Dsc, and the time step as T. The time where the collision takes place (Tc) is:

Tc= Dsc * T / Dst

All this is performed of course if an intersection is determined. The returned time is a fraction of the whole time step, so if the time step was 1 sec, and we found an intersection exactly in the middle of the distance then the calculated collision time would be 0.5 sec. this can be interpreted like "0.5 sec after the start there is an intersection". Now the intersection point can be calculated by just multiplying Tc with the current velocity and adding it to the start point.

Collision point= Start + Velocity * Tc

This is the collision point on the offset primitive, to find the collision point on the real primitive we add to that point the reverse of the normal at that point (which is also returned by the intersection routines) by the radius of the sphere. Note that the cylinder intersection routine returns the intersection point if there is one so it does not need to be calculated.

Physically Based Modeling

Collision Response

To determine how to respond after hitting Static Objects like Planes, Cylinders is as important as finding the collision point itself. Using the algorithms and functions described the exact collision point, the normal at the collision point and the time within a time step in which the collision occurs can be found.

To determine how to respond to a collision, laws of physics have to be applied. When an object collides with the surface its direction changes i.e.. it bounces off. The angle of the of the new direction (or reflection vector) with the normal at the collision point is the same as does the original direction vector. Figure 3 shows a collision with a sphere.

Figure 3

R is the new direction vector

I is the old direction vector before the collision

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Collision detection tutorial»

Представляем Вашему вниманию похожие книги на «Collision detection tutorial» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Oskar Andreasson - Iptables Tutorial 1.1.19
Oskar Andreasson
Barrington Bayley - Collision with Chronos
Barrington Bayley
Zoë Archer - Collision Course
Zoë Archer
Jeff Abbott - Collision
Jeff Abbott
libcat.ru: книга без обложки
Неизвестный Автор
libcat.ru: книга без обложки
Неизвестный Автор
Борис Акунин - Квест. Tutorial
Борис Акунин
Сергей (Sergey) Зайцев - Brief public speaking tutorial
Сергей (Sergey) Зайцев
Отзывы о книге «Collision detection tutorial»

Обсуждение, отзывы о книге «Collision detection tutorial» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x