载入中...
搜索中...
未找到
Vec2.h
浏览该文件的文档.
1#pragma once
2
3#include <cmath>
4
5namespace eve::math {
6
8class Vec2 {
9public:
10 Vec2() = default;
12 Vec2(float x, float y) : x_(x), y_(y) {}
13
15 float getX() const { return x_; }
16 float getY() const { return y_; }
17 void setX(float x) { x_ = x; }
18 void setY(float y) { y_ = y; }
20 void set(float x, float y) {
21 x_ = x;
22 y_ = y;
23 }
24
26 float length() const { return std::sqrt(x_ * x_ + y_ * y_); }
27 float lengthSquared() const { return x_ * x_ + y_ * y_; }
28
30 void normalize();
31 Vec2 *normalized() const;
32
34 float dot(const Vec2 *other) const;
35 float cross(const Vec2 *other) const;
36 float distanceTo(const Vec2 *other) const;
37 float angle() const;
38
40 Vec2 *add(const Vec2 *other) const;
41 Vec2 *sub(const Vec2 *other) const;
42 Vec2 *scale(float s) const;
44 Vec2 *lerpTo(const Vec2 *other, float t) const;
46 Vec2 *clone() const;
47
48private:
49 float x_ = 0.f;
50 float y_ = 0.f;
51};
52
53} // namespace eve::math
int y
Definition Grass.cpp:135
int x
Definition Grass.cpp:135
float scale
Definition TreeMesh.cpp:122
uint32_t s
Definition Weather.cpp:28
2D float vector (script-facing math module value).
Definition Vec2.h:8
Vec2 * sub(const Vec2 *other) const
Definition Vec2.cpp:47
Vec2 * normalized() const
Definition Vec2.cpp:17
float cross(const Vec2 *other) const
Definition Vec2.cpp:28
Vec2(float x, float y)
Creates a vector from components.
Definition Vec2.h:12
float dot(const Vec2 *other) const
Dot/cross product, distance, angle (radians).
Definition Vec2.cpp:23
float angle() const
Definition Vec2.cpp:40
float distanceTo(const Vec2 *other) const
Definition Vec2.cpp:33
void setX(float x)
Definition Vec2.h:17
float length() const
Magnitude (and squared magnitude).
Definition Vec2.h:26
void setY(float y)
Definition Vec2.h:18
float lengthSquared() const
Definition Vec2.h:27
Vec2()=default
float getY() const
Definition Vec2.h:16
float getX() const
Component accessors.
Definition Vec2.h:15
Vec2 * clone() const
Copies this vector.
Definition Vec2.cpp:59
void set(float x, float y)
Sets both components.
Definition Vec2.h:20
Vec2 * add(const Vec2 *other) const
Arithmetic helpers returning new (caller-owned) vectors.
Definition Vec2.cpp:42
void normalize()
Normalizes in place / returns a normalized copy.
Definition Vec2.cpp:9
Vec2 * lerpTo(const Vec2 *other, float t) const
Linear interpolation to other at t in [0,1].
Definition Vec2.cpp:54