How do you determine the hit of a rotated object?

Asked 1 years ago, Updated 1 years ago, 25 views

How can I determine the hit of the rotated object in rotation?

runstant sample http://goo.gl/4E2dYw

It seems to be judged that rotation is not reflected.
(Not available by any chance?)

If tmlib.js alone is not possible, please let me know how to judge normally.

javascript tmlib.js

2022-09-30 18:08

2 Answers

The tmlib.js side is not compatible.

The collision determination between OBB and OBB is complicated and the processing load is high
I'm planning to deal with it, but I think it's still a long way off!


2022-09-30 18:08

I answered somewhere else, so here too.

tmlib.js Document

return(rect0.left<rect1.right)&(rect0.right>rect1.left)&
       (rect0.top<rect1.bottom)&(rect0.bottom>rect1.top);

As it looks, tmlib.js does not correspond to rotated rectangles.
There are many solutions to this, and there is no common "this."
Therefore, it will be a subjective answer.

Consider the rectangle itself as a collection of vectors.

A rectangle has four sides, so it can be defined as four vectors: v1, v2, v3, v4.
At this time, if you define v1, v2, v3, and v4 in the right direction, the vertex of the other figure inside the rectangle appears to be on the right side by any vector.The left turn is the opposite.
↓ From v1 to v4, the inner point is on the right by any vector.

v1→
  ┏━━━┓
↑ · and vv2
v4 ↓ ↓
  ┗━━━┛
    ← v3

Find which side of a vector is left or right in terms of the outer product.

For example, let's say (v1x1, v1y1) start with v1.
And similarly, let's say the end point is (v1x2, v1y2).
Let's look at the results using the outer product when the vertex of the investigation is P(Px, Py).

(v1x2-v1x1)*(Py-v1y1)-(Px-v1x1)*(v1y2-v1y1)

As a result of the above, if the value is +, the vertex P is located to the left of v1.

If you think of it as a right-handed rectangle as above, you can say that the above calculation is performed for all vertices (both A and B), and that the result of the outer product + is non-collision, and that any - is collision.

In this way, the collision determination process itself becomes very inefficient.
If you want to know how to optimize it, you may want to look at other libraries that make collision decisions.


2022-09-30 18:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.