JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
Vec2 Class Reference

Two-dimensional vector. More...

#include <jngl/Vec2.hpp>

Public Member Functions

 Vec2 ()
 Null vector.
 
 Vec2 (double x, double y)
 Creates a vector {x, y}.
 
bool isNull () const
 returns true if both x and y are exactly 0
 
void rotate (float angle)
 rotates the vector clock-wise by angle (radian)
 
template<class Archive >
void serialize (Archive &ar, const unsigned int)
 Helper function to use with cereal or Boost.Serialization.
 

Public Attributes

double x = 0
 x component
 
double y = 0
 y component
 

Detailed Description

Two-dimensional vector.

JNGL doesn't provide any linear algebra functions itself but relies on the excellent Boost.QVM:

#include <jngl/Vec2.hpp>
jngl::Vec2 v(3, 4);
double length = boost::qvm::mag(v);
assert(length == 5);
Contains jngl::Vec2 class.
Two-dimensional vector.
Definition Vec2.hpp:36

Common math operators are overloaded:

jngl::Vec2 v(3, 4);
v *= 2.0;
assert(std::lround(v.x) == 6);
T lround(T... args)

Definition at line 36 of file Vec2.hpp.

Member Function Documentation

◆ serialize()

template<class Archive >
void serialize ( Archive & ar,
const unsigned int  )
inline

Helper function to use with cereal or Boost.Serialization.

Definition at line 57 of file Vec2.hpp.

Member Data Documentation

◆ x

double x = 0

x component

Definition at line 45 of file Vec2.hpp.

◆ y

double y = 0

y component

Definition at line 48 of file Vec2.hpp.


The documentation for this class was generated from the following file: