Difference between revisions of "GSDP:GAM100/CProcessing/worldToScreen()"

From Inside
Jump to: navigation, search
>Zachary.logsdon
>Zachary.logsdon
 
Line 6: Line 6:
  
 
===Parameters===
 
===Parameters===
worldToScreen(float* x, float* y)
+
worldToScreen(float xIn, float yIn, float* xOut, float* yOut)
  
* x - (float*) The x coordinate to convert, x result will be stored here as well.
+
* xIn - (float) The x coordinate to convert.
* y - (float*) The y coordinate to convert, y result will be stored here as well.
+
* yIn - (float) The y coordinate to convert.
 +
* xOut - (float*) The place to store the converted x coordinate.
 +
* yOut - (float*) The place to store the converted y coordinate.
  
 
== Example ==
 
== Example ==
Line 15: Line 17:
 
void init()
 
void init()
 
{
 
{
    // transform a random amount
 
    translate((float)randomRangeFloat(-100.0f, 100.0f), (float)randomRangeFloat(-100.0f, 100.0f));
 
    scale((float)randomRangeFloat(0.1f, 10.0f));
 
    rotate((float)randomRangeFloat(0.0f, 360.0f));
 
 
 
     // Variables to pass into the conversion functions
 
     // Variables to pass into the conversion functions
 
     float x = PI;
 
     float x = PI;
Line 27: Line 24:
 
     for (int i = 0; i < 100; ++i)
 
     for (int i = 0; i < 100; ++i)
 
     {
 
     {
         screenToWorld(&x, &y);
+
         screenToWorld(x, y, &x, &y);
         worldToScreen(&x, &y);
+
         worldToScreen(x, y, &x, &y);
 
     }
 
     }
  

Latest revision as of 11:17, 3 June 2019

worldToScreen()

Description

Takes an input coordinate in world space and transforms it to screen coordinates.

Parameters

worldToScreen(float xIn, float yIn, float* xOut, float* yOut)

  • xIn - (float) The x coordinate to convert.
  • yIn - (float) The y coordinate to convert.
  • xOut - (float*) The place to store the converted x coordinate.
  • yOut - (float*) The place to store the converted y coordinate.

Example

void init()
{
    // Variables to pass into the conversion functions
    float x = PI;
    float y = PI;

    // Run back and forth 100 times
    for (int i = 0; i < 100; ++i)
    {
        screenToWorld(x, y, &x, &y);
        worldToScreen(x, y, &x, &y);
    }

    // Should still be PI
    printf(" %9f\n(%9f,%9f)\n", PI, x, y);
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>