cangine
Loading...
Searching...
No Matches
transform_component.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "component.hpp"
4#include "../gameobjects/game_object.hpp"
5
6#include "../../types/types.hpp"
7
8namespace cangine {
17 class Transform : public IComponent {
21
22 public:
23 ~Transform() override;
24 void firstFrame() override;
25
30 void setPosition(Vector3 positionIn);
35 Vector3 getPosition() const;
36
41 void setRotation(Vector3 rotationIn);
46 Vector3 getRotation() const;
47
52 void setScale(Vector3 scaleIn);
57 Vector3 getScale() const;
58
64 static Transform* from(GameObject* go) {
65 return go->getComponent<Transform>();
66 }
67
74 return go->getComponent<Transform>()->getPosition();
75 }
76
83 return go->getComponent<Transform>()->getRotation();
84 }
85
92 return go->getComponent<Transform>()->getScale();
93 }
94
100 static void posFor(GameObject* go, Vector3 pos) {
102 }
103
109 static void rotFor(GameObject* go, Vector3 rot) {
111 }
112
118 static void scaleFor(GameObject* go, Vector3 scale) {
120 }
121 };
122}
123
Base class for everything that lives in the scene.
Definition game_object.hpp:20
T * getComponent()
Returns the first attached component of a type.
Definition game_object.hpp:93
Base interface for all components attached to a GameObject.
Definition component.hpp:17
Component holding an object's position, rotation and scale.
Definition transform_component.hpp:17
static void rotFor(GameObject *go, Vector3 rot)
Sets the rotation on a game object's Transform.
Definition transform_component.hpp:109
static Vector3 posFrom(GameObject *go)
Reads the position of a game object's Transform.
Definition transform_component.hpp:73
static Vector3 scaleFrom(GameObject *go)
Reads the scale of a game object's Transform.
Definition transform_component.hpp:91
static Transform * from(GameObject *go)
Fetches the Transform component of a game object.
Definition transform_component.hpp:64
static void scaleFor(GameObject *go, Vector3 scale)
Sets the scale on a game object's Transform.
Definition transform_component.hpp:118
Vector3 rotation
Rotation in degrees (per axis).
Definition transform_component.hpp:19
void setRotation(Vector3 rotationIn)
Sets the rotation.
Definition transform_component.cpp:22
void setScale(Vector3 scaleIn)
Sets the scale.
Definition transform_component.cpp:30
Vector3 getPosition() const
Returns the position.
Definition transform_component.cpp:18
Vector3 getScale() const
Returns the scale.
Definition transform_component.cpp:34
~Transform() override
Vector3 position
World position.
Definition transform_component.hpp:18
Vector3 getRotation() const
Returns the rotation.
Definition transform_component.cpp:26
static void posFor(GameObject *go, Vector3 pos)
Sets the position on a game object's Transform.
Definition transform_component.hpp:100
void setPosition(Vector3 positionIn)
Sets the position.
Definition transform_component.cpp:14
Vector3 scale
Scale factor per axis.
Definition transform_component.hpp:20
void firstFrame() override
Called once before the first frame update.
Definition transform_component.cpp:8
static Vector3 rotFrom(GameObject *go)
Reads the rotation of a game object's Transform.
Definition transform_component.hpp:82
Definition audiomanager.cpp:4
Three-component floating-point vector.
Definition vector3.hpp:13