GSDP:GAM100/CProcessing/CP Vector Negate()

From Inside
Jump to: navigation, search

CP_Vector_Negate()

Description

Returns the inverse of an input CP_Vector as a new CP_Vector.

Parameters

CP_Vector_Negate(CP_Vector a)

  • a - (CP_Vector) - Vector to invert

Example

CP_Vector position;
CP_Vector speed;

void init()
{
  position = CP_Vector_Set(CP_System_GetWindowWidth() / 2, CP_System_GetWindowHeight() / 2);
  speed = CP_Vector_Set(50.0f, 0.0f);

  CP_Settings_EllipseMode(CP_POSITION_CENTER);
  CP_Settings_Fill(CP_Color_Create(255, 0, 0, 255));
}

void update()
{
  CP_Settings_Background(CP_Color_Create(255, 255, 255, 255));

  // Check if direction should be inverted
  if (position.x > CP_System_GetWindowWidth())
  {
    speed = CP_Vector_Negate(speed);
    position.x = CP_System_GetWindowWidth();
  }
  else if (position.x < 0)
  {
    speed = CP_Vector_Negate(speed);
    position.x = 0;
  }

  // Update position
  position = CP_Vector_Add(position, CP_Vector_Scale(speed, dt()));

  // Draw the circle
  CP_Graphics_DrawCircle(position.x, position.y, 40);
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>