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