GSDP:GAM100/CProcessing/vec2 cross()

From Inside
Jump to: navigation, search

vec2_cross()

Description

Returns the magnitude(length) of the cross product of two Vec2s as a float.

Parameters

vec2_cross(Vec2 a, Vec2 b)

  • a - (Vec2) First vector in calculation.
  • b - (Vec2) Second vector in calculation.

Example

Vec2 vector1;
Vec2 vector2;
float cross1;
float cross2;

void init()
{
  vector1 = vec2_set(randomRangeFloat(0.0f, 50.0f), randomRangeFloat(0.0f, 50.0f));
  vector2 = vec2_set(randomRangeFloat(0.0f, 50.0f), randomRangeFloat(0.0f, 50.0f));

  cross1 = vec2_cross(vector1, vector2);
  cross2 = vec2_cross(vector2, vector1);

  textFont(defaultFont, 30);
  fill(color(0, 0, 0, 255));
}

void update()
{
  // Print out the randomly generated vectors
  char vec_text[128] = { 0 };
  sprintf_s(vec_text, 128, "1st Vector: [%.2f, %.2f]", vector1.x, vector1.y);
  text(vec_text, 0, 50);
  sprintf_s(vec_text, 128, "2st Vector: [%.2f, %.2f]", vector2.x, vector2.y);
  text(vec_text, 0, 100);

  // Print out the first cross product
  sprintf_s(vec_text, 128, "Cross 1x2: %.2f", cross1);
  text(vec_text, 0, 150);

  // Print out the second cross product
  sprintf_s(vec_text, 128, "Cross 2x1: %.2f", cross2);
  text(vec_text, 0, 200);
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>