载入中...
搜索中...
未找到
Vec2.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include <cmath>
6
7namespace eve::math {
8
11public:
12 Vec2() = default;
14 Vec2(float x, float y) : x_(x), y_(y) {}
15
17 float getX() const { return x_; }
19 float getY() const { return y_; }
21 void setX(float x) { x_ = x; }
23 void setY(float y) { y_ = y; }
25 void set(float x, float y) {
26 x_ = x;
27 y_ = y;
28 }
29
31 float length() const { return std::sqrt(x_ * x_ + y_ * y_); }
33 float lengthSquared() const { return x_ * x_ + y_ * y_; }
34
36 void normalize();
37 Vec2 *normalized() const;
38
41 float dot(const Vec2 *other) const;
43 float cross(const Vec2 *other) const;
45 float distanceTo(const Vec2 *other) const;
47 float angle() const;
48
50 Vec2 *add(const Vec2 *other) const;
51 Vec2 *sub(const Vec2 *other) const;
52 Vec2 *scale(float s) const;
54 Vec2 *lerpTo(const Vec2 *other, float t) const;
56 Vec2 *clone() const;
57
58private:
59 float x_ = 0.f;
60 float y_ = 0.f;
61};
62
63} // namespace eve::math
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
const std::string & s
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
std::array< float, 3 > scale
float t
float angle
2D float vector (script-facing math module value).
Definition Vec2.h:10
Vec2(float x, float y)
Creates a vector from components.
Definition Vec2.h:14
void setX(float x)
Sets the X component.
Definition Vec2.h:21
float length() const
Magnitude (and squared magnitude).
Definition Vec2.h:31
void setY(float y)
Sets the Y component.
Definition Vec2.h:23
float lengthSquared() const
Squared Euclidean magnitude.
Definition Vec2.h:33
Vec2()=default
float getY() const
Y component.
Definition Vec2.h:19
float getX() const
Component accessors.
Definition Vec2.h:17
void set(float x, float y)
Sets both components.
Definition Vec2.h:25