Skip to main content
added 226 characters in body
Source Link
Ian Young
  • 2.7k
  • 15
  • 23

The key to any optimisation, is identifying where the bulk of the work is being done.

A simple analysis of your problem reveals the following:

  1. A cuboid shape has 8 vertices, three perpendicular axes, and a position.
  2. The same cuboid can be rotated around any of these axes.

At the moment, your algorithm is transforming the vertices, then presumably computing resultant axes from the vertices, to perform SAT computations.

You are correct in surmising that there is a computationally less expensive way to do it.

In your cuboid data structure, you only require 3 floats, called half extents. Each value is the distance from the centre of the cuboid, to the edge of it, along one of it's principle axes.

You take the three principle axes, x (1,0,0), y(0,1,0), and z(0,0,1), and rotate them by the objects' transform. (3 vector rotations instead of 8)

Then, you compute the vertices, using the rotated axes and half extents. this is mostly vector addition multiplication, which is inexpensive. This will result in the vertices being rotated, but not translated yet.

Finally, you add the position of the object to each vertex (again, cheap) to get your final translated vertices, in world space.

There are other optimisations that can be done, but this is a good start for you.

The key to any optimisation, is identifying where the bulk of the work is being done.

A simple analysis of your problem reveals the following:

  1. A cuboid shape has 8 vertices, three perpendicular axes, and a position.
  2. The same cuboid can be rotated around any of these axes.

At the moment, your algorithm is transforming the vertices, then presumably computing resultant axes from the vertices, to perform SAT computations.

You are correct in surmising that there is a computationally less expensive way to do it.

In your cuboid data structure, you only require 3 floats, called half extents. Each value is the distance from the centre of the cuboid, to the edge of it, along one of it's principle axes.

You take the three principle axes, x (1,0,0), y(0,1,0), and z(0,0,1), and rotate them by the objects' transform. (3 vector rotations instead of 8)

Then, you compute the vertices this is mostly vector addition multiplication, which is inexpensive.

Finally, you add the position of the object to each vertex (again, cheap) to get your final vertices.

The key to any optimisation, is identifying where the bulk of the work is being done.

A simple analysis of your problem reveals the following:

  1. A cuboid shape has 8 vertices, three perpendicular axes, and a position.
  2. The same cuboid can be rotated around any of these axes.

At the moment, your algorithm is transforming the vertices, then presumably computing resultant axes from the vertices, to perform SAT computations.

You are correct in surmising that there is a computationally less expensive way to do it.

In your cuboid data structure, you only require 3 floats, called half extents. Each value is the distance from the centre of the cuboid, to the edge of it, along one of it's principle axes.

You take the three principle axes, x (1,0,0), y(0,1,0), and z(0,0,1), and rotate them by the objects' transform. (3 vector rotations instead of 8)

Then, you compute the vertices, using the rotated axes and half extents. this is mostly vector addition multiplication, which is inexpensive. This will result in the vertices being rotated, but not translated yet.

Finally, you add the position of the object to each vertex (again, cheap) to get your final translated vertices, in world space.

There are other optimisations that can be done, but this is a good start for you.

Source Link
Ian Young
  • 2.7k
  • 15
  • 23

The key to any optimisation, is identifying where the bulk of the work is being done.

A simple analysis of your problem reveals the following:

  1. A cuboid shape has 8 vertices, three perpendicular axes, and a position.
  2. The same cuboid can be rotated around any of these axes.

At the moment, your algorithm is transforming the vertices, then presumably computing resultant axes from the vertices, to perform SAT computations.

You are correct in surmising that there is a computationally less expensive way to do it.

In your cuboid data structure, you only require 3 floats, called half extents. Each value is the distance from the centre of the cuboid, to the edge of it, along one of it's principle axes.

You take the three principle axes, x (1,0,0), y(0,1,0), and z(0,0,1), and rotate them by the objects' transform. (3 vector rotations instead of 8)

Then, you compute the vertices this is mostly vector addition multiplication, which is inexpensive.

Finally, you add the position of the object to each vertex (again, cheap) to get your final vertices.