Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding Powercells that needs charging
#9
Quote:if (item.velocity.x != nan)
{
speed = abs(item.velocity.x);
speed += abs(item.velocity.y);
speed += abs(item.velocity.z);
} else speed = 0.0;

This code calculates linear speed of some object, although it's not a mathematically correct code. Properly, linear velocity is a square root of sum of squares of velocity components in all dimensions, so:

Code:
float vx = item.velocity.x;
float vy = item.velocity.y;
float vz = item.velocity.z;

float speed = sqrt(vx * vx + vy * vy + vz * vz);

Comparing a value for NaN is necessary because some objects have invalid velocity.

If you want linear velocity in horizontal plane, just skip third component Z.

return without value is used to return from void function, but it's not necessary to put it at the end of function because it doesn't do anything.
"After three days without programming, life becomes meaningless."
~The Tao of Programming


Messages In This Thread
Finding Powercells that needs charging - by Jono - 04-09-2015, 08:14 AM
RE: Finding Powercells that needs charging - by tomaszkax86 - 05-03-2016, 01:28 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)