casting - C++ Cast float* to glm::vec3 -


How do I insert a float array from form float * to glm: : Vec3 ? I thought I had done this before, but I lost my HDD. I tried some c-style and static_cast s but I did not seem to be doing this work.

tells you how to vec3 to float *

  #include & lt; Glm / glm.hpp & gt; # Include & lt; Glm / gtc / type_ptr.hpp & gt; Glm :: vec3 aVector (3); Glm :: mat4 some matrix (1.0); GlUniform3fv (Uniform Lock, 1, Glam :: :: value_ptr (aVector)); GlUniformMatrix4fv (uniformmatics lock, 1, GL_FALSE, glm :: value_ptr (some matrix));  

You use glm :: value_ptr .

The documentation does not say clearly, although it seems that glm intends to be 'layout compatible' with arrays so that they can be used directly with OpenGL functions . If so, you can use vec3 from an array using the following artists:

  float arr [] = {1.f, 0.f, 0.f}; Vec3 & lt; Float & gt; * V = reinterpret_cast & lt; Vec3 & lt; Float & gt; * & Gt; (a R);  

You should wrap it up in your own utility functions because you do not want to separate such artists in your codebase.


Comments