Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Camera now has function to load it's settings from file

  • Loading branch information...
commit bd42d4702441c64ac210637c405bdaa110d8c3ac 1 parent 2f90f57
Michael Heinrichs Phosfor authored
9 include/Engine.hpp
@@ -59,7 +59,7 @@ namespace Engine
59 59 return EntityManager::get_mutable_instance().GetLight(entityName);
60 60 }
61 61
62   - Camera *MakeCamera(const string &cameraName, bool attachViewport = false, Camera::CameraType camType = Camera::DONT_USE,
  62 + /*Camera *MakeCamera(const string &cameraName, bool attachViewport = false, Camera::CameraType camType = Camera::DONT_USE,
63 63 const float nearClip = 1, const float farClip = 1000,
64 64 bool autoAR = true, const float FOV = 90, vec3 pos = vec3(0, 1000, 1000), vec3 lookAt = vec3(0, 0, 0))
65 65 {
@@ -73,6 +73,13 @@ namespace Engine
73 73 localTemp->setCameraType(camType);
74 74
75 75 return localTemp;
  76 + }*/
  77 +
  78 + Camera *MakeCamera(const string &name, const string filename)
  79 + {
  80 + Camera *localTemp = EntityManager::get_mutable_instance().MakeCamera(name);
  81 + localTemp->loadFromFile(filename);
  82 + return localTemp;
76 83 }
77 84
78 85 Camera *GetCamera(const string &cameraName)
5 include/Managers/Entities/Camera.hpp
@@ -27,11 +27,14 @@ class Camera : public Entity
27 27 DONT_USE // If we don't want predefined stuff
28 28 } mCameraType;
29 29
30   - Camera(const string cameraName);
  30 + Camera(const string entityName);
31 31 void configure(const float nearClip = 1, const float farClip = 1000, bool autoAR = true, const float FOV = 90,
32 32 vec3 pos = vec3(0, 1000, 1000), vec3 lookAt = vec3(0, 0, 0));
33 33 Ogre::Camera *cameraHandle();
34 34 Ogre::SceneNode *getPitchNode();
  35 +
  36 + void loadFromFile(const string & filename, const string &res = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
  37 +
35 38 void setCameraType(CameraType type);
36 39
37 40 void setMoveStep(float step);
5 samples/pong-cpp/main.cpp
@@ -33,7 +33,10 @@ class GameState : public State
33 33 {
34 34 public:
35 35 void init() {
36   - World::MakeCamera("MenuCamera", true, Camera::FREE);
  36 + //World::MakeCamera("MenuCamera", true, Camera::FREE);
  37 + Camera *cam = World::MakeCamera("MainCamera", "MainCamera");
  38 + //GraphicSystem::get_mutable_instance().getViewport()->setCamera(cam->cameraHandle());
  39 + //cam->setCameraType(Camera::FREE);
37 40 //World::MakeLight("MainLight", Ogre::Light::LT_DIRECTIONAL)->lightHandle()->setDirection(vec3(0, 100, 0));
38 41
39 42 World::MakeLight("PointLight", Ogre::Light::LT_POINT,
48 src/Managers/Entities/Camera.cpp
... ... @@ -1,18 +1,56 @@
1 1 #include "Managers/Entities/Camera.hpp"
2 2
3   -Camera::Camera(const string cameraName)
  3 +Camera::Camera(const string entityName)
4 4 {
5 5 Ogre::SceneManager *sceneMgr = GraphicSystem::get_const_instance().getSceneMgr();
6 6
7   - mEntityName = cameraName;
8   - mCamera = sceneMgr->createCamera(cameraName);
  7 + mEntityName = entityName;
  8 +
  9 + mCamera = sceneMgr->createCamera(entityName);
9 10
10 11 mMove = 250;
11 12 mRotate = 0.13;
12 13
13   - mNode = sceneMgr->getRootSceneNode()->createChildSceneNode("Node:Camera_" + cameraName);
14   - mPitchNode = mNode->createChildSceneNode("Node:CameraPitch_" + cameraName);
  14 + mNode = sceneMgr->getRootSceneNode()->createChildSceneNode("Node:Camera_" + entityName);
  15 + mPitchNode = mNode->createChildSceneNode("Node:CameraPitch_" + entityName);
15 16 mPitchNode->attachObject(mCamera);
  17 +
  18 +}
  19 +
  20 +void Camera::loadFromFile(const string &filename, const string &res)
  21 +{
  22 + _declareEntityResources();
  23 +
  24 + if (Ogre::ResourceGroupManager::getSingletonPtr()->resourceExists(res, filename))
  25 + {
  26 + //Ogre::ResourceGroupManager::getSingleton().declareResource(entMesh, "Mesh", res);
  27 +
  28 + ptree tree_handle;
  29 + read_info(Utils::get_const_instance().getMediaPath() + "Entities/" + filename + "/init.info", tree_handle);
  30 +
  31 + float fov = tree_handle.get<float>("type_settings.fov", 90);
  32 + float nearClip = tree_handle.get<float>("type_settings.nearClip", 1);
  33 + float farClip = tree_handle.get<float>("type_settings.farClip", 1000);
  34 + bool autoAR = tree_handle.get<bool>("type_settings.autoAR", true);
  35 + configure(nearClip, farClip, autoAR, fov);
  36 + bool attachVP = tree_handle.get<bool>("type_settings.attachVP", true);
  37 + if(attachVP)
  38 + GraphicSystem::get_mutable_instance().getViewport()->setCamera(mCamera);
  39 + string type = tree_handle.get<string>("type_settings.cam_type", "DONT_USE");
  40 + if(type == "DONT_USE")
  41 + setCameraType(Camera::DONT_USE);
  42 + else if(type == "FREE")
  43 + setCameraType(Camera::FREE);
  44 + else if(type == "FIRST_PERSON")
  45 + setCameraType(Camera::FIRST_PERSON);
  46 + else if(type == "ATTACHED")
  47 + setCameraType(Camera::ATTACHED);
  48 + LOG("Loaded Camera from " + filename);
  49 + }
  50 +
  51 +
  52 + _defaultLoader(filename);
  53 +
16 54 }
17 55
18 56 void Camera::configure(const float nearClip, const float farClip, bool autoAR, const float FOV,

0 comments on commit bd42d47

Please sign in to comment.
Something went wrong with that request. Please try again.