[go: up one dir, main page]

Skip to content

Commit

Permalink
Change SceneNode behavior
Browse files Browse the repository at this point in the history
Transform
~ rename Transform to TransformComponent

World, RenderEngine
- remove Ogre, this is offloaded to RenderEngine

CameraComponent
~ remove creation of Ogre camera, this is done in RenderEngine
  • Loading branch information
Ravbug committed Aug 10, 2020
1 parent 38b96bc commit 4600c6a
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 163 deletions.
4 changes: 2 additions & 2 deletions RavEngine_Test/PlayerActor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PlayerActor : public Entity {
decimalType sensitivity = 0.1;

//transform cache
Ref<Transform> trans;
Ref<TransformComponent> trans;


decimalType scaleMovement(decimalType f) {
Expand Down Expand Up @@ -53,7 +53,7 @@ class PlayerActor : public Entity {
auto cam = cameraEntity->AddComponent<CameraComponent>(new CameraComponent());

//set the active camera
cam->isActive = true;
cam->setActive(true);

trans = transform();
trans->AddChild(cameraEntity->transform());
Expand Down
61 changes: 34 additions & 27 deletions include/RavEngine/CameraComponent.hpp
Original file line number Diff line number Diff line change
@@ -1,54 +1,61 @@
#include "Component.hpp"
#include "Entity.hpp"
#include "GameplayStatics.hpp"
#include "OgreStatics.hpp"
#include <stduuid/uuid.h>

class CameraComponent : public Component {
protected:
Ogre::Camera* cam = nullptr;
Ogre::CompositorWorkspace* compositor = nullptr;
public:
CameraComponent(float inFOV = 60, float inNearClip = 0.1, float inFarClip = 100) : FOV(inFOV), nearClip(inNearClip), farClip(inFarClip), Component() {
auto const id = to_string(uuids::uuid_system_generator{}());
cam = GameplayStatics::ogreFactory.createCamera(id);
cam->setFOVy(Ogre::Radian(FOV));
cam->setNearClipDistance(nearClip);
cam->setFarClipDistance(farClip);
}
CameraComponent(float inFOV = 60, float inNearClip = 0.1, float inFarClip = 100);

virtual ~CameraComponent() {
cam->detachFromParent();
OGRE_DELETE cam;
}

/**
Get the backend camera directly. For internal use only. The engine will not be aware of changes made directly to this pointer.
@return a pointer to the camera
*/
Ogre::Camera* const getCamera() const {
return cam;
}

void AddHook(const WeakRef<Entity>& e) override{
//add the camera to the root
e.get()->transform()->getNode()->attachObject(cam);
}

void RegisterAllAlternateTypes() override{}
bool isActive = false;

//camera details
float FOV;
float nearClip;
float farClip;
/**
Enable / disable this camera
@param newState the new enabled state for this camera. The renderer will choose the first active camera as the camera to use when drawing.
*/
void setActive(bool newState);

/**
Using the camera's current state, set the view transform
@returns if this camera is active
*/
void SetViewTransform() {
Ref<Entity> entity = owner.get();
auto transform = entity->transform();
auto pos = transform->GetWorldPosition();
//calculate where to position the camera
float view[16];
transform->WorldMatrixToArray(view);
/*auto rot = transform->GetWorldRotation();
bx::mtxQuatTranslation(view, bx::Quaternion{(float)rot.x,(float)rot.y,(float)rot.z,(float)rot.w},bx::Vec3(pos.x,pos.y,pos.z));*/

float proj[16];
//bx::mtxProj(proj, FOV, GameplayStatics::width / GameplayStatics::height, nearClip, farClip, bgfx::getCaps()->homogeneousDepth);
//bgfx::setViewTransform(0, view, proj);
bool isActive() {
return active;
}

/**
For internal use
@return the compositor workspace for this camera.
*/
Ogre::CompositorWorkspace* const GetCompositor() {
return compositor;
}

protected:
bool active = false;

//camera details
float FOV;
float nearClip;
float farClip;
};
1 change: 0 additions & 1 deletion include/RavEngine/Component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
//forward declarations
class Entity;


class Component : public SharedObject{
protected:
WeakRef<Entity> owner; //non-owning pointer to the owning Entity of this component
Expand Down
2 changes: 1 addition & 1 deletion include/RavEngine/Entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class Entity : public SharedObject{
/**
@return a reference to the transform component, which all entities possess
*/
Ref<Transform> transform();
Ref<TransformComponent> transform();

/**
Tick logic on this Entity
Expand Down
7 changes: 4 additions & 3 deletions include/RavEngine/RenderEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@
#include "Entity.hpp"
#include <list>
#include "WeakRef.hpp"
#include "OgreStatics.hpp"

class RenderEngine : public SharedObject{
public:
virtual ~RenderEngine(){};
void Spawn(Ref<Entity> e);
void Destroy(Ref<Entity> e);
RenderEngine(const WeakRef<World>& w) : world(w) {};
RenderEngine(const WeakRef<World>& w);
void Draw();

static const std::string currentBackend();
WeakRef<World> world;

protected:
std::list<Ref<Entity>> entities;
protected:
Ogre::SceneManager* ogrescene = nullptr;
};
Loading

0 comments on commit 4600c6a

Please sign in to comment.