SOL9 Sample: Vector4f

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * Vector4f.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */



#include <sol/Vector4f.h>
#include <sol/Vertex.h>

int main(int argc, char* argv[])
{
  try {
    Vector4f vec1(1.0f, 2.0f, 3.0f, 1.0f);
    printf("vec1: x=%lf y=%lf z=%lf w=%lf\n", vec1[0], vec1[1], vec1[2], vec1[3]);
    
    Vector4f vec2(vec1);
    vec2 *= 2.0f;
    printf("vec2(vec1*2.0f): x=%lf y=%lf z=%lf w=%lf\n", vec2[0], vec2[1], vec2[2], vec2[3]);
    
    float dot     = vec2.dotProduct(vec1);
    
    printf("dotProduct1(vec2.vec1): %f\n", dot);

    Vector4f vec3(10.0f, 6.0f, 2.0f, 0.0f);
    printf("vec3: x=%lf y=%lf z=%lf w=%lf\n", vec3[0], vec3[1], vec3[2], vec3[3]);

    float dot2 = vec3.dotProduct(vec1);
    printf("dotProduct2(vec3.vec1):  %f\n", dot2);

    vec3[0] = 111.123f;
    vec3[1] = 222.234f;
    vec3[2] = 333.345f;
    vec3[3] = 444.456f;
    
    printf("Substitution vec3: x=%.3lf, y=%.3lf, z=%.3lf w=%.3lf\n", 
      vec3[0], vec3[1], vec3[2], vec3[3]);

    Vertex<4> vertex = {1000.1f, 999.2f, 888.3f, 77.4f};
    Vector4f nvec(vertex);
    printf("nvect(vertex): x=%lf y=%lf z=%lf w=%lf\n", nvec[0], nvec[1], nvec[2], nvec[3]);
    
    vec3[5] = 555.456f; //Cause an exception, because the index 5 for vec3 is out of range of Vector4f.
    
  } catch (Exception& ex) {
    ex.display();
  }
  
  return 0;
}


Last modified: 17 Aug 2016

Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.