2011-10-25 05:03:10 +00:00
|
|
|
//
|
|
|
|
|
// KRScene.h
|
|
|
|
|
// KREngine
|
|
|
|
|
//
|
2012-03-15 20:09:01 +00:00
|
|
|
// Copyright 2012 Kearwood Gilbert. All rights reserved.
|
2017-10-30 20:58:14 -07:00
|
|
|
//
|
2011-10-25 06:16:47 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
|
// permitted provided that the following conditions are met:
|
2017-10-30 20:58:14 -07:00
|
|
|
//
|
2011-10-25 06:16:47 +00:00
|
|
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
|
// conditions and the following disclaimer.
|
2017-10-30 20:58:14 -07:00
|
|
|
//
|
2011-10-25 06:16:47 +00:00
|
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
|
// of conditions and the following disclaimer in the documentation and/or other materials
|
|
|
|
|
// provided with the distribution.
|
2017-10-30 20:58:14 -07:00
|
|
|
//
|
2011-10-25 06:16:47 +00:00
|
|
|
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
|
|
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
|
|
|
|
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
|
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
|
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2017-10-30 20:58:14 -07:00
|
|
|
//
|
2011-10-25 06:16:47 +00:00
|
|
|
// The views and conclusions contained in the software and documentation are those of the
|
|
|
|
|
// authors and should not be interpreted as representing official policies, either expressed
|
|
|
|
|
// or implied, of Kearwood Gilbert.
|
2011-10-25 05:03:10 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#ifndef KRSCENE_H
|
|
|
|
|
#define KRSCENE_H
|
|
|
|
|
|
2013-01-11 03:21:19 +00:00
|
|
|
#include "KREngine-common.h"
|
2012-03-15 23:58:37 +00:00
|
|
|
|
2013-01-11 03:21:19 +00:00
|
|
|
#include "KRModel.h"
|
|
|
|
|
#include "KRMesh.h"
|
|
|
|
|
#include "KRCamera.h"
|
|
|
|
|
#include "KRMeshManager.h"
|
|
|
|
|
#include "KRNode.h"
|
2013-12-05 18:20:01 -08:00
|
|
|
#include "KRLocator.h"
|
2013-02-28 19:09:27 -08:00
|
|
|
#include "KRAmbientZone.h"
|
|
|
|
|
#include "KRReverbZone.h"
|
2013-01-11 03:21:19 +00:00
|
|
|
#include "KROctree.h"
|
2013-01-09 22:37:23 +00:00
|
|
|
class KRModel;
|
2012-11-16 02:58:23 +00:00
|
|
|
class KRLight;
|
2011-10-25 05:03:10 +00:00
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
2012-04-12 00:43:53 +00:00
|
|
|
class KRScene : public KRResource {
|
2011-10-25 05:03:10 +00:00
|
|
|
public:
|
2012-08-17 01:04:49 +00:00
|
|
|
KRScene(KRContext &context, std::string name);
|
2012-08-17 01:06:27 +00:00
|
|
|
virtual ~KRScene();
|
2017-10-30 20:58:14 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-04-12 00:43:53 +00:00
|
|
|
virtual std::string getExtension();
|
2012-12-20 01:23:57 +00:00
|
|
|
virtual bool save(KRDataBlock &data);
|
2017-10-30 20:58:14 -07:00
|
|
|
|
2012-09-11 03:06:35 +00:00
|
|
|
static KRScene *Load(KRContext &context, const std::string &name, KRDataBlock *data);
|
2017-10-30 20:58:14 -07:00
|
|
|
|
2012-04-12 00:43:53 +00:00
|
|
|
KRNode *getRootNode();
|
2012-11-16 02:58:23 +00:00
|
|
|
KRLight *getFirstLight();
|
2017-10-30 20:58:14 -07:00
|
|
|
|
2014-04-11 01:15:40 -07:00
|
|
|
kraken_stream_level getStreamLevel();
|
2017-10-30 20:58:14 -07:00
|
|
|
|
|
|
|
|
bool lineCast(const Vector3 &v0, const Vector3 &v1, HitInfo &hitinfo, unsigned int layer_mask);
|
|
|
|
|
bool rayCast(const Vector3 &v0, const Vector3 &dir, HitInfo &hitinfo, unsigned int layer_mask);
|
|
|
|
|
bool sphereCast(const Vector3 &v0, const Vector3 &v1, float radius, HitInfo &hitinfo, unsigned int layer_mask);
|
|
|
|
|
|
2017-04-28 00:22:35 -07:00
|
|
|
void renderFrame(GLint defaultFBO, float deltaTime, int width, int height);
|
2017-07-29 19:23:21 -07:00
|
|
|
void render(KRCamera *pCamera, unordered_map<AABB, int> &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame);
|
2017-10-30 20:58:14 -07:00
|
|
|
|
2017-07-29 19:23:21 -07:00
|
|
|
void render(KROctreeNode *pOctreeNode, unordered_map<AABB, int> &visibleBounds, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass, std::vector<KROctreeNode *> &remainingOctrees, std::vector<KROctreeNode *> &remainingOctreesTestResults, std::vector<KROctreeNode *> &remainingOctreesTestResultsOnly, bool bOcclusionResultsPass, bool bOcclusionTestResultsOnly);
|
2017-10-30 20:58:14 -07:00
|
|
|
|
2013-04-04 12:50:53 -07:00
|
|
|
void updateOctree(const KRViewport &viewport);
|
2014-03-19 13:52:52 -07:00
|
|
|
void buildOctreeForTheFirstTime();
|
2017-10-30 20:58:14 -07:00
|
|
|
|
2012-08-29 21:43:11 +00:00
|
|
|
void notify_sceneGraphCreate(KRNode *pNode);
|
|
|
|
|
void notify_sceneGraphDelete(KRNode *pNode);
|
|
|
|
|
void notify_sceneGraphModify(KRNode *pNode);
|
2017-10-30 20:58:14 -07:00
|
|
|
|
2012-11-09 09:18:38 +00:00
|
|
|
void physicsUpdate(float deltaTime);
|
2012-11-16 02:58:23 +00:00
|
|
|
void addDefaultLights();
|
2017-10-30 20:58:14 -07:00
|
|
|
|
2017-07-29 19:23:21 -07:00
|
|
|
AABB getRootOctreeBounds();
|
2017-10-30 20:58:14 -07:00
|
|
|
|
2013-02-28 19:09:27 -08:00
|
|
|
std::set<KRAmbientZone *> &getAmbientZones();
|
|
|
|
|
std::set<KRReverbZone *> &getReverbZones();
|
2013-12-05 18:20:01 -08:00
|
|
|
std::set<KRLocator *> &getLocators();
|
2014-03-10 22:32:49 -07:00
|
|
|
std::set<KRLight *> &getLights();
|
2017-10-30 20:58:14 -07:00
|
|
|
|
2011-10-25 05:03:10 +00:00
|
|
|
private:
|
2012-12-20 22:08:41 +00:00
|
|
|
|
2012-04-12 00:43:53 +00:00
|
|
|
KRNode *m_pRootNode;
|
2012-11-16 02:58:23 +00:00
|
|
|
KRLight *m_pFirstLight;
|
2017-10-30 20:58:14 -07:00
|
|
|
|
2012-08-29 21:43:11 +00:00
|
|
|
std::set<KRNode *> m_newNodes;
|
|
|
|
|
std::set<KRNode *> m_modifiedNodes;
|
2017-10-30 20:58:14 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-11-09 09:18:38 +00:00
|
|
|
std::set<KRNode *> m_physicsNodes;
|
2013-02-28 19:09:27 -08:00
|
|
|
std::set<KRAmbientZone *> m_ambientZoneNodes;
|
|
|
|
|
std::set<KRReverbZone *> m_reverbZoneNodes;
|
2013-12-05 18:20:01 -08:00
|
|
|
std::set<KRLocator *> m_locatorNodes;
|
2014-03-10 22:32:49 -07:00
|
|
|
std::set<KRLight *> m_lights;
|
2017-10-30 20:58:14 -07:00
|
|
|
|
2012-08-29 21:43:11 +00:00
|
|
|
KROctree m_nodeTree;
|
2017-10-30 20:58:14 -07:00
|
|
|
|
2012-12-20 22:08:41 +00:00
|
|
|
public:
|
2017-10-30 20:58:14 -07:00
|
|
|
|
2012-12-20 22:08:41 +00:00
|
|
|
template <class T> T *find()
|
|
|
|
|
{
|
|
|
|
|
if(m_pRootNode) return m_pRootNode->find<T>();
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2017-10-30 20:58:14 -07:00
|
|
|
|
2012-12-20 22:08:41 +00:00
|
|
|
template <class T> T *find(const std::string &name)
|
|
|
|
|
{
|
|
|
|
|
if(m_pRootNode) return m_pRootNode->find<T>(name);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2011-10-25 05:03:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|