many exports to scriptengine
This commit is contained in:
parent
2373b382f1
commit
491c09e235
@ -27,10 +27,10 @@ namespace BlueCore
|
||||
AABB transformed (const Transformation& transformation)
|
||||
{
|
||||
AABB aabb;
|
||||
|
||||
/*
|
||||
Vector3 new_max = transformation.transform (Max);
|
||||
Vector3 new_min = transformation.transform (Min);
|
||||
|
||||
*/
|
||||
return aabb;
|
||||
}
|
||||
};
|
||||
|
@ -9,6 +9,9 @@
|
||||
#include "ScriptSystem_Image.h"
|
||||
#include "ScriptSystem_Math.h"
|
||||
#include "ScriptSystem_RigidBody.h"
|
||||
#include "ScriptSystem_SceneGraph.h"
|
||||
#include "ScriptSystem_SceneNode.h"
|
||||
#include "ScriptSystem_Model.h"
|
||||
|
||||
namespace BlueCore
|
||||
{
|
||||
@ -70,6 +73,9 @@ bool Application::initialize()
|
||||
setupScriptSystem_Image(_ScriptSystem, _TextureManager, _Device);
|
||||
setupScriptSystem_Math(_ScriptSystem);
|
||||
setupScriptSystem_RigidBody(_ScriptSystem, _Simulation);
|
||||
setupScriptSystem_SceneGraph(_ScriptSystem);
|
||||
setupScriptSystem_SceneNode(_ScriptSystem);
|
||||
setupScriptSystem_Model(_ScriptSystem, _ModelManager);
|
||||
|
||||
if (_ScriptSystem->loadScript("main") == false)
|
||||
return false;
|
||||
@ -108,6 +114,21 @@ void Application::run()
|
||||
_Paused = false;
|
||||
_Running = true;
|
||||
|
||||
ref_ptr<Mesh> star_mesh = _MeshManager->loadMesh ("stars.3ds");
|
||||
ref_ptr<Texture> star_texture = _TextureManager->loadTexture ("stars.png", 0);
|
||||
|
||||
GLfloat lightAmbient[] = {0.0f, 0.0f, 0.0f, 1.0f} ;
|
||||
GLfloat lightDiffuse[] = {1.0f, 1.0f, 1.0f, 1.0f} ;
|
||||
GLfloat lightSpecular[] = {1.0f, 1.0f, 1.0f, 1.0f} ;
|
||||
GLfloat lightPosition[] = { 1.0, 0.0, 0.0, 0.0};
|
||||
|
||||
glLightfv ( GL_LIGHT0, GL_AMBIENT, lightAmbient ) ;
|
||||
glLightfv ( GL_LIGHT0, GL_DIFFUSE, lightDiffuse ) ;
|
||||
glLightfv ( GL_LIGHT0, GL_SPECULAR, lightSpecular ) ;
|
||||
glLightfv ( GL_LIGHT0, GL_POSITION, lightPosition );
|
||||
|
||||
glEnable ( GL_LIGHT0 ) ;
|
||||
|
||||
while (_Window->isOpen() && _Running)
|
||||
{
|
||||
double now = glfwGetTime();
|
||||
@ -122,15 +143,20 @@ void Application::run()
|
||||
//camera->setPosition(q.apply(Vector3(0.0, 0.0, _CameraRadius)));
|
||||
//camera->setRotation(q);
|
||||
//pos += 5 * _DeltaTime;
|
||||
_Device->setAmbientLight(1.0, 1.0, 1.0);
|
||||
|
||||
if (_SceneGraph.valid())
|
||||
{
|
||||
_RenderQueue->clear();
|
||||
_SceneGraph->update(delta);
|
||||
_SceneGraph->queue(_RenderQueue);
|
||||
_Device->begin3D(_SceneGraph->getCamera());
|
||||
_RenderQueue->render(_Device);
|
||||
_Device->end3D();
|
||||
}
|
||||
/*
|
||||
{
|
||||
_Device->begin3D(_Camera);
|
||||
_Device->setAmbientLight(1.0, 1.0, 1.0);
|
||||
_RenderQueue->clear();
|
||||
_RenderQueue->addOpaqueItem(model, Vector3(0.0, 0.0, 0.0),
|
||||
Quaternion());
|
||||
@ -139,41 +165,7 @@ void Application::run()
|
||||
}
|
||||
*/
|
||||
/*
|
||||
device->pushAbsoluteTransformation(Vector3(), camera->getRotation());
|
||||
|
||||
class RenderState
|
||||
{
|
||||
bool _Blending;
|
||||
GLint _BlendFuncSrc;
|
||||
GLint _BlendFuncDest;
|
||||
|
||||
bool _DepthTest;
|
||||
bool _DepthMask;
|
||||
|
||||
bool _Lighting;
|
||||
};
|
||||
GLfloat mat_specular[] =
|
||||
{ 1.0, 1.0, 1.0, 1.0 };
|
||||
GLfloat mat_shininess[] =
|
||||
{ 2.0 };
|
||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_specular);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_specular);
|
||||
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
||||
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
glDisable(GL_LIGHTING);
|
||||
glColor4d( 1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
device->setTexture(0, starTexture, true);
|
||||
starMesh->render();
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
device->popTransformation();
|
||||
*/
|
||||
*/
|
||||
// device->useShader (program);
|
||||
// device->setTexture (stage, name, texture)
|
||||
// device->clearTextures (stage+1);
|
||||
@ -197,6 +189,40 @@ void Application::run()
|
||||
}
|
||||
}
|
||||
|
||||
_Device->pushAbsoluteTransformation(Vector3(), _SceneGraph->getCamera()->getRotation());
|
||||
/*
|
||||
_Device->setShaderProgram (0);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
*/
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
_Device->setTexture(0, star_texture, true);
|
||||
glDisable(GL_LIGHTING);
|
||||
glColor4d( 1.0f, 1.0f, 1.0f, 1.0f);
|
||||
star_mesh->render();
|
||||
_Device->popTransformation();
|
||||
|
||||
/*
|
||||
class RenderState
|
||||
{
|
||||
bool _Blending;
|
||||
GLint _BlendFuncSrc;
|
||||
GLint _BlendFuncDest;
|
||||
|
||||
bool _DepthTest;
|
||||
bool _DepthMask;
|
||||
|
||||
bool _Lighting;
|
||||
};
|
||||
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
|
||||
GLfloat mat_shininess[] = { 2.0 };
|
||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_specular);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_specular);
|
||||
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
||||
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
|
||||
*/
|
||||
|
||||
_Device->begin2D();
|
||||
_ScriptSystem->callFunction("OnOverlay", delta, now - _StartTime);
|
||||
_Device->end2D();
|
||||
|
@ -1,57 +0,0 @@
|
||||
#include "Utilities/Referenced.h"
|
||||
|
||||
|
||||
class File : public Referenced
|
||||
{
|
||||
public:
|
||||
bool isOpen ();
|
||||
unsigned long read (char *buffer, unsigned long size);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class FileSystem : public Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
FileSystem();
|
||||
File *openBinary (const std::string& filename);
|
||||
|
||||
private:
|
||||
|
||||
static bool _PhysfsInialized;
|
||||
};
|
||||
|
||||
|
||||
|
||||
FileSystem::FileSystem()
|
||||
{
|
||||
PHYSFS_init (0);
|
||||
|
||||
std::string appdir = PHYSFS_getUserDir();
|
||||
appdir += ".bluecore";
|
||||
|
||||
if( !PHYSFS_setWriteDir(appdir.c_str()) )
|
||||
{
|
||||
if( (PHYSFS_setWriteDir(PHYSFS_getUserDir())) && (PHYSFS_mkdir(".bluecore")) )
|
||||
PHYSFS_setWriteDir( appdir.c_str() );
|
||||
}
|
||||
|
||||
PHYSFS_addToSearchPath( appdir.c_str(), 0 );
|
||||
PHYSFS_addToSearchPath( "data", 1 );
|
||||
|
||||
char **rc = PHYSFS_enumerateFiles ( "" );
|
||||
|
||||
for ( char **i = rc; *i != 0; i++ )
|
||||
{
|
||||
std::string filename ( *i );
|
||||
|
||||
if ( filename.substr ( filename.size() - 4, 4 ) == ".zip" )
|
||||
{
|
||||
PHYSFS_addToSearchPath ( ( "data/" + filename ).c_str(), 1 );
|
||||
BlueCore::log << ">>> Using addon: " << filename << endlog;
|
||||
}
|
||||
}
|
||||
|
||||
PHYSFS_freeList ( rc );
|
||||
}
|
@ -42,8 +42,10 @@ else
|
||||
endif
|
||||
|
||||
SRC = $(wildcard */*.cpp) $(wildcard *.cpp)
|
||||
INC = $(wildcard */*.h) $(wildcard *.h)
|
||||
OBJ = $(patsubst %.cpp,%.o,$(SRC) )
|
||||
DEP = $(patsubst %.cpp,%.d,$(SRC) )
|
||||
GCH = $(patsubst %.h,%.h.gch,$(INC) )
|
||||
|
||||
NAME = redcore$(EXT)
|
||||
|
||||
@ -67,3 +69,7 @@ clean:
|
||||
-@$(RM) $(NAME)
|
||||
|
||||
-include $(SRC:%.cpp=%.d)
|
||||
|
||||
%.h.gch: %.h
|
||||
@echo Compiling $@ ...
|
||||
@$(CXX) $(CXXFLAGS) -o $@ $<
|
||||
|
@ -7,8 +7,6 @@
|
||||
#ifndef BLUECORE_POINT_H
|
||||
#define BLUECORE_POINT_H
|
||||
|
||||
#include "rectangle.h"
|
||||
|
||||
namespace BlueCore
|
||||
{
|
||||
template<typename type>
|
||||
@ -27,29 +25,8 @@ namespace BlueCore
|
||||
{
|
||||
}
|
||||
|
||||
bool in( const Rectangle2DTemplate<type> &rect );
|
||||
};
|
||||
|
||||
#include "rectangle.h"
|
||||
|
||||
template<typename type>
|
||||
bool Point2DTemplate<type>::in( const Rectangle2DTemplate<type> &rect )
|
||||
{
|
||||
if( _x < rect._x )
|
||||
return false;
|
||||
|
||||
if( _x > (rect._x + rect._width) )
|
||||
return false;
|
||||
|
||||
if( _y < rect._y )
|
||||
return false;
|
||||
|
||||
if( _y > (rect._y + rect._height) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef Point2DTemplate<int> Point2D;
|
||||
|
||||
};
|
||||
|
@ -7,8 +7,8 @@
|
||||
#ifndef BLUECORE_RAY_H
|
||||
#define BLUECORE_RAY_H
|
||||
|
||||
#include "scalar.h"
|
||||
#include "vector.h"
|
||||
#include "Scalar.h"
|
||||
#include "Vector.h"
|
||||
|
||||
namespace BlueCore
|
||||
{
|
||||
@ -44,7 +44,7 @@ namespace BlueCore
|
||||
* set the point
|
||||
*/
|
||||
template <class S>
|
||||
inline setPoint( const Vector3Template<S> &point )
|
||||
inline void setPoint( const Vector3Template<S> &point )
|
||||
{
|
||||
this->point = point;
|
||||
}
|
||||
@ -54,7 +54,7 @@ namespace BlueCore
|
||||
* set the direction
|
||||
*/
|
||||
template <class S>
|
||||
inline setDirection( const Vector3Template<S> &direction )
|
||||
inline void setDirection( const Vector3Template<S> &direction )
|
||||
{
|
||||
this->direction = direction.normalized();
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
#ifndef BLUECORE_RECTANGLE_H
|
||||
#define BLUECORE_RECTANGLE_H
|
||||
|
||||
#include "point.h"
|
||||
#include "Point.h"
|
||||
|
||||
namespace BlueCore
|
||||
{
|
||||
|
@ -14,19 +14,16 @@ using namespace std;
|
||||
namespace BlueCore
|
||||
{
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Mesh::Mesh(RenderDevice* device) :
|
||||
_Device(device)
|
||||
{
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Mesh::~Mesh()
|
||||
{
|
||||
clog << ">>> Mesh destructed ..."<< endline;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void Mesh::render()
|
||||
{
|
||||
|
||||
@ -100,20 +97,17 @@ void Mesh::bind()
|
||||
}
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
MeshManager::MeshManager(RenderDevice* device) :
|
||||
_Device(device)
|
||||
{
|
||||
BlueCore::clog << ">>> MeshManager constructed..." << endlog;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
MeshManager::~MeshManager()
|
||||
{
|
||||
clog << ">>> MeshManager destructed ..." << endlog;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool loadTrimesh(const char* filename, Mesh *mesh)
|
||||
{
|
||||
PHYSFS_file* file = PHYSFS_openRead(filename);
|
||||
@ -193,13 +187,92 @@ bool loadTrimesh(const char* filename, Mesh *mesh)
|
||||
|
||||
PHYSFS_close(file);
|
||||
|
||||
// create normlas, tangents, and binomials
|
||||
clog << " create normlas..." << endline;
|
||||
|
||||
for (unsigned int i = 0; i < mesh->VertexBuffer.count(); i++)
|
||||
{
|
||||
mesh->VertexBuffer[i].normal.zero();
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < mesh->IndexBuffer.count(); i++)
|
||||
{
|
||||
const TriangleIndices& triangle = mesh->IndexBuffer[i];
|
||||
|
||||
Vector3Template<float> ab = mesh->VertexBuffer[ triangle.a ].point
|
||||
- mesh->VertexBuffer[ triangle.b ].point;
|
||||
Vector3Template<float> ac = mesh->VertexBuffer[ triangle.a ].point
|
||||
- mesh->VertexBuffer[ triangle.c ].point;
|
||||
Vector3Template<float> n = ab.cross(ac);
|
||||
|
||||
mesh->VertexBuffer[ triangle.a ].normal += n;
|
||||
mesh->VertexBuffer[ triangle.a ].normal += n;
|
||||
mesh->VertexBuffer[ triangle.a ].normal += n;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < mesh->VertexBuffer.count(); i ++)
|
||||
{
|
||||
mesh->VertexBuffer[i].normal.normalize();
|
||||
}
|
||||
|
||||
clog << " create tangents..." << endline;
|
||||
|
||||
mesh->TangentBuffer.create(mesh->VertexBuffer.count());
|
||||
mesh->BitangentBuffer.create(mesh->VertexBuffer.count());
|
||||
|
||||
for (unsigned int i = 0; i < mesh->TangentBuffer.count(); i ++)
|
||||
{
|
||||
mesh->TangentBuffer[i].zero();
|
||||
mesh->BitangentBuffer[i].zero();
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < mesh->IndexBuffer.count(); i ++)
|
||||
{
|
||||
const TriangleIndices& triangle = mesh->IndexBuffer[i];
|
||||
|
||||
const Vertex& v1 = mesh->VertexBuffer[triangle.a];
|
||||
const Vertex& v2 = mesh->VertexBuffer[triangle.b];
|
||||
const Vertex& v3 = mesh->VertexBuffer[triangle.c];
|
||||
|
||||
float x1 = v2.point.x - v1.point.x;
|
||||
float x2 = v3.point.x - v1.point.x;
|
||||
float y1 = v2.point.y - v1.point.y;
|
||||
float y2 = v3.point.y - v1.point.y;
|
||||
float z1 = v2.point.z - v1.point.z;
|
||||
float z2 = v3.point.z - v1.point.z;
|
||||
float s1 = v2.u - v1.u;
|
||||
float s2 = v3.u - v1.u;
|
||||
float t1 = v2.v - v1.v;
|
||||
float t2 = v3.v - v1.v;
|
||||
float r = 1.0f / (s1 * t2 - s2 * t1 );
|
||||
|
||||
Vector3Float sdir( (t2 * x1 - t1 * x2 ) * r, (t2 * y1 - t1 * y2 )
|
||||
* r, (t2 * z1 - t1 * z2 ) * r);
|
||||
|
||||
Vector3Float tdir( (s1 * x2 - s2 * x1 ) * r, (s1 * y2 - s2 * y1 )
|
||||
* r, (s1 * z2 - s2 * z1 ) * r);
|
||||
|
||||
mesh->TangentBuffer[triangle.a] += sdir;
|
||||
mesh->TangentBuffer[triangle.b] += sdir;
|
||||
mesh->TangentBuffer[triangle.c] += sdir;
|
||||
|
||||
mesh->BitangentBuffer[triangle.a] += tdir;
|
||||
mesh->BitangentBuffer[triangle.b] += tdir;
|
||||
mesh->BitangentBuffer[triangle.c] += tdir;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < mesh->TangentBuffer.count(); i ++)
|
||||
{
|
||||
mesh->TangentBuffer[i].normalize();
|
||||
mesh->BitangentBuffer[i].normalize();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Mesh *MeshManager::loadMesh(const string &filename)
|
||||
{
|
||||
// check if this mesh is already loaded
|
||||
@ -310,7 +383,6 @@ Mesh *MeshManager::loadMesh(const string &filename)
|
||||
return mesh;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool MeshManager::loadFromCache(Mesh *mesh, const std::string &name)
|
||||
{
|
||||
std::string filename = name + ".msc";
|
||||
@ -331,25 +403,28 @@ bool MeshManager::loadFromCache(Mesh *mesh, const std::string &name)
|
||||
PHYSFS_read(file, &size, sizeof (size ), 1);
|
||||
mesh->IndexBuffer.create(size);
|
||||
PHYSFS_read(file, mesh->IndexBuffer.data(), mesh->IndexBuffer.size(), 1);
|
||||
#if 0
|
||||
// read tangent buffer
|
||||
PHYSFS_read ( file, &size, sizeof ( size ), 1 );
|
||||
mesh->tangent_buffer.create ( size );
|
||||
PHYSFS_read ( file, mesh->tangent_buffer.data(), mesh->tangent_buffer.size(), 1 );
|
||||
|
||||
// read bitangent buffer
|
||||
PHYSFS_read ( file, &size, sizeof ( size ), 1 );
|
||||
mesh->bitangent_buffer.create ( size );
|
||||
PHYSFS_read ( file, mesh->bitangent_buffer.data(), mesh->bitangent_buffer.size(), 1 );
|
||||
|
||||
// read bounding sphere
|
||||
PHYSFS_read ( file, &mesh->bounding_sphere, sizeof ( mesh->bounding_sphere ), 1 );
|
||||
#endif
|
||||
|
||||
// read subsets
|
||||
PHYSFS_read(file, &size, sizeof (size ), 1);
|
||||
mesh->SubsetBuffer.create(size);
|
||||
PHYSFS_read(file, mesh->SubsetBuffer.data(), mesh->SubsetBuffer.size(), 1);
|
||||
|
||||
// read tangent buffer
|
||||
PHYSFS_read(file, &size, sizeof (size ), 1);
|
||||
mesh->TangentBuffer.create(size);
|
||||
PHYSFS_read(file, mesh->TangentBuffer.data(), mesh->TangentBuffer.size(), 1);
|
||||
|
||||
// read bitangent buffer
|
||||
PHYSFS_read(file, &size, sizeof (size ), 1);
|
||||
mesh->BitangentBuffer.create(size);
|
||||
PHYSFS_read(file, mesh->BitangentBuffer.data(),
|
||||
mesh->BitangentBuffer.size(), 1);
|
||||
|
||||
#if 0
|
||||
// read bounding sphere
|
||||
PHYSFS_read ( file, &mesh->bounding_sphere, sizeof ( mesh->bounding_sphere ), 1 );
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// read bitangent buffer
|
||||
PHYSFS_read ( file, &size, sizeof ( size ), 1 );
|
||||
@ -362,9 +437,7 @@ bool MeshManager::loadFromCache(Mesh *mesh, const std::string &name)
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool MeshManager::saveToCache(Mesh *mesh, const std::string &name)
|
||||
|
||||
{
|
||||
std::string filename = name + ".msc";
|
||||
|
||||
@ -391,17 +464,19 @@ bool MeshManager::saveToCache(Mesh *mesh, const std::string &name)
|
||||
PHYSFS_write(file, &size, sizeof (size ), 1);
|
||||
PHYSFS_write(file, mesh->SubsetBuffer.data(), mesh->SubsetBuffer.size(), 1);
|
||||
|
||||
#if 0
|
||||
// write tangent_buffer
|
||||
size = mesh->tangent_buffer.count();
|
||||
PHYSFS_write ( file, &size, sizeof ( size ), 1 );
|
||||
PHYSFS_write ( file, mesh->tangent_buffer.data(), mesh->tangent_buffer.size(), 1 );
|
||||
size = mesh->TangentBuffer.count();
|
||||
PHYSFS_write(file, &size, sizeof (size ), 1);
|
||||
PHYSFS_write(file, mesh->TangentBuffer.data(), mesh->TangentBuffer.size(),
|
||||
1);
|
||||
|
||||
// write bitangent_buffer
|
||||
size = mesh->bitangent_buffer.count();
|
||||
PHYSFS_write ( file, &size, sizeof ( size ), 1 );
|
||||
PHYSFS_write ( file, mesh->bitangent_buffer.data(), mesh->bitangent_buffer.size(), 1 );
|
||||
size = mesh->BitangentBuffer.count();
|
||||
PHYSFS_write(file, &size, sizeof (size ), 1);
|
||||
PHYSFS_write(file, mesh->BitangentBuffer.data(),
|
||||
mesh->BitangentBuffer.size(), 1);
|
||||
|
||||
#if 0
|
||||
// write bounding sphere
|
||||
PHYSFS_write ( file, &mesh->bounding_sphere, sizeof ( mesh->bounding_sphere ), 1 );
|
||||
|
||||
|
@ -49,8 +49,8 @@ public:
|
||||
Buffer<TriangleIndices> IndexBuffer;
|
||||
Buffer<Subset> SubsetBuffer;
|
||||
|
||||
Buffer<Vector3Float> tangents;
|
||||
Buffer<Vector3Float> bitangents;
|
||||
Buffer<Vector3Float> TangentBuffer;
|
||||
Buffer<Vector3Float> BitangentBuffer;
|
||||
Buffer<ShadowFace> shadowfaces;
|
||||
|
||||
public:
|
||||
|
@ -19,65 +19,57 @@ namespace BlueCore
|
||||
//------------------------------------------------------------------------------
|
||||
void Model::render(RenderDevice *device) const
|
||||
{
|
||||
ModelMesh->render();
|
||||
/*
|
||||
// ModelMesh->render();
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glDepthFunc ( GL_LEQUAL );
|
||||
glEnable ( GL_DEPTH_TEST );
|
||||
glDepthMask ( GL_TRUE );
|
||||
*/
|
||||
/*
|
||||
|
||||
glEnableClientState (GL_VERTEX_ARRAY );
|
||||
glEnableClientState (GL_TEXTURE_COORD_ARRAY );
|
||||
glEnableClientState (GL_NORMAL_ARRAY );
|
||||
|
||||
mesh->vertex_buffer.bind();
|
||||
mesh->index_buffer.bind();
|
||||
*/
|
||||
/*
|
||||
glMaterialfv (GL_FRONT, GL_SHININESS, &pass.Shininess);
|
||||
glMaterialfv (GL_FRONT, GL_SPECULAR, ( GLfloat * ) &pass.Specular );
|
||||
glMaterialfv (GL_FRONT, GL_SHININESS, &LitPass.Shininess);
|
||||
glMaterialfv (GL_FRONT, GL_SPECULAR, ( GLfloat * ) &LitPass.Specular );
|
||||
|
||||
// setup shader
|
||||
if (pass.Program && ShaderManager::getSingleton()->usingShaders() )
|
||||
if (LitPass.Program)
|
||||
{
|
||||
ShaderManager::getSingleton()->useShaderProgram(pass.Program);
|
||||
device->setShaderProgram(LitPass.Program);
|
||||
|
||||
int textureId = 0;
|
||||
std::vector<Model::TextureUnit>::iterator titer;
|
||||
int textureId = 0;
|
||||
|
||||
std::vector<Model::TextureUnit>::const_iterator titer;
|
||||
for (titer = LitPass.Textures.begin(); titer != LitPass.Textures.end(); titer++)
|
||||
{
|
||||
device->setTexture(textureId, ( *titer ).mTexture );
|
||||
device->setTexture(LitPass.Program, textureId, ( *titer ).mName);
|
||||
textureId++;
|
||||
}
|
||||
|
||||
if (LitPass.Tangents)
|
||||
{
|
||||
//device->setTangentBuffer(LitPass.Program, &ModelMesh->TangentBuffer, "tangent");
|
||||
//device->setTangentBuffer(LitPass.Program, &ModelMesh->BitangentBuffer, "bitangent");
|
||||
}
|
||||
|
||||
for (titer = pass.Textures.begin(); titer != pass.Textures.end(); titer++)
|
||||
{
|
||||
Renderer::getSingleton()->bindTexture(( *titer ).mTexture, textureId );
|
||||
ShaderManager::getSingleton()->useTexture(pass.Program, textureId, ( *titer ).mName);
|
||||
textureId++;
|
||||
}
|
||||
|
||||
if (pass.Tangents)
|
||||
{
|
||||
ShaderManager::getSingleton()->useTangentBuffer(pass.Program, &mesh->tangent_buffer, "tangent");
|
||||
ShaderManager::getSingleton()->useTangentBuffer(pass.Program, &mesh->bitangent_buffer,
|
||||
"bitangent");
|
||||
}
|
||||
}
|
||||
/*
|
||||
else
|
||||
{
|
||||
glActiveTextureARB (GL_TEXTURE2_ARB );
|
||||
glDisable (GL_TEXTURE_2D );
|
||||
glActiveTextureARB (GL_TEXTURE1_ARB );
|
||||
glDisable (GL_TEXTURE_2D );
|
||||
int textureId = 0;
|
||||
int textureId = 0;
|
||||
|
||||
std::vector<Model::TextureUnit>::iterator titer;
|
||||
for (titer = pass.Textures.begin(); titer != pass.Textures.end(); titer++)
|
||||
{
|
||||
Renderer::getSingleton()->bindTexture(( *titer ).mTexture, textureId );
|
||||
std::vector<Model::TextureUnit>::iterator titer;
|
||||
for (titer = pass.Textures.begin(); titer != pass.Textures.end(); titer++)
|
||||
{
|
||||
Renderer::getSingleton()->bindTexture(( *titer ).mTexture, textureId );
|
||||
ShaderManager::getSingleton()->useTexture(pass.Program, textureId, ( *titer ).mName);
|
||||
textureId++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// render subsets
|
||||
SubsetVector::iterator iter;
|
||||
for (iter = mesh->surface_subsets.begin(); iter
|
||||
@ -86,7 +78,20 @@ void Model::render(RenderDevice *device) const
|
||||
Subset subset = *iter;
|
||||
mesh->index_buffer.draw(subset.first, subset.count);
|
||||
}
|
||||
*/
|
||||
|
||||
ModelMesh->render();
|
||||
|
||||
device->setShaderProgram(0);
|
||||
|
||||
glActiveTextureARB (GL_TEXTURE2_ARB );
|
||||
glDisable (GL_TEXTURE_2D );
|
||||
glActiveTextureARB (GL_TEXTURE1_ARB );
|
||||
glDisable (GL_TEXTURE_2D );
|
||||
glActiveTextureARB (GL_TEXTURE0_ARB );
|
||||
glDisable (GL_TEXTURE_2D );
|
||||
|
||||
/*
|
||||
// cleanup
|
||||
if (pass.Program && ShaderManager::getSingleton()->usingShaders() )
|
||||
{
|
||||
@ -98,6 +103,7 @@ void Model::render(RenderDevice *device) const
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glActiveTextureARB (GL_TEXTURE2_ARB );
|
||||
@ -120,11 +126,13 @@ ModelManager::ModelManager(TextureManager *texturemanager,
|
||||
_TextureManager(texturemanager), _ShaderManager(shadermanager),
|
||||
_MeshManager(meshmanager)
|
||||
{
|
||||
clog << ">>> ModelManager constructed ..."<< endline;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
ModelManager::~ModelManager()
|
||||
{
|
||||
clog << ">>> ModelManager destructed ..."<< endline;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -1,26 +0,0 @@
|
||||
#ifndef NODE_H_
|
||||
#define NODE_H_
|
||||
|
||||
class Node
|
||||
{
|
||||
class UpdateListener
|
||||
{
|
||||
virtual void update() = 0;
|
||||
virtual ~UpdateListener() = 0;
|
||||
};
|
||||
typedef std::list<Node*> NodeContainer;
|
||||
typedef std::list<Node*> NodeContainer;
|
||||
|
||||
Node *parent;
|
||||
NodeContainer children;
|
||||
|
||||
Vector3 getRelativePosition;
|
||||
Vector3 getAbsolutePosition;
|
||||
/* ... */
|
||||
|
||||
bool _Updating;
|
||||
void update (double time);
|
||||
void render (Camera *camera, RenderDevice *device);
|
||||
};
|
||||
|
||||
#endif /*NODE_H_*/
|
@ -190,4 +190,51 @@ void RenderDevice::setTexture(unsigned int unit, Texture* texture, bool last)
|
||||
}
|
||||
}
|
||||
|
||||
void RenderDevice::setShaderProgram(ShaderProgram shader_program)
|
||||
{
|
||||
// if ( !_usingShaders)
|
||||
// return;
|
||||
|
||||
glUseProgramObjectARB(shader_program);
|
||||
}
|
||||
|
||||
void RenderDevice::setTexture(ShaderProgram shader_program,
|
||||
unsigned int texture, const std::string &name)
|
||||
{
|
||||
// if ( !_usingShaders)
|
||||
// return;
|
||||
|
||||
GLint location = glGetUniformLocationARB(shader_program, name.c_str() );
|
||||
|
||||
//if( location > 0 )
|
||||
glUniform1iARB(location, texture);
|
||||
}
|
||||
#if 0
|
||||
void RenderDevice::setTangentBuffer(ShaderProgram shader_program,
|
||||
const Buffer<Vector3Float>& tangent_buffer, const std::string &name)
|
||||
{
|
||||
// if ( !_usingShaders || !tangent_buffer)
|
||||
// return;
|
||||
|
||||
GLuint location = glGetAttribLocationARB(shader_program, name.c_str() );
|
||||
|
||||
glEnableVertexAttribArrayARB(location);
|
||||
|
||||
//tangent_buffer->bind();
|
||||
|
||||
glVertexAttribPointerARB(location, 3, GL_FLOAT, 0, 0, 0);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void ShaderManager::disableTangentBuffer(ShaderProgram shader_program,
|
||||
const std::string &name)
|
||||
{
|
||||
// if ( !_usingShaders)
|
||||
// return;
|
||||
|
||||
GLuint location = glGetAttribLocationARB(shader_program, name.c_str() );
|
||||
|
||||
glDisableVertexAttribArrayARB(location);
|
||||
}
|
||||
#endif
|
||||
} // namespace BlueCore
|
||||
|
@ -45,15 +45,18 @@ public:
|
||||
void setMaterial(Material *);
|
||||
|
||||
void setTexture(unsigned int unit, Texture* texture, bool last = false);
|
||||
void pushAbsoluteTransformation (const Vector3&, const Quaternion&);
|
||||
void pushTransformation (const Vector3&, const Quaternion&);
|
||||
void popTransformation ();
|
||||
void setShaderProgram(ShaderProgram shader_program);
|
||||
void setTexture(ShaderProgram shader_program, unsigned int texture,
|
||||
const std::string &name);
|
||||
|
||||
void pushAbsoluteTransformation(const Vector3&, const Quaternion&);
|
||||
void pushTransformation(const Vector3&, const Quaternion&);
|
||||
void popTransformation();
|
||||
void setupProjectionMatrix();
|
||||
void setupViewMatrix();
|
||||
|
||||
sigslot::signal0<> DeviceShutdownSignal;
|
||||
|
||||
|
||||
//Buffer<ShadowFace> &_ShadowFaces;
|
||||
};
|
||||
|
||||
|
@ -5,7 +5,7 @@ namespace BlueCore
|
||||
|
||||
SceneGraph::SceneGraph()
|
||||
{
|
||||
_RootNode = new SceneNode();
|
||||
_RootNode = new SceneNode("root node");
|
||||
}
|
||||
SceneGraph::~SceneGraph()
|
||||
{
|
||||
@ -22,6 +22,11 @@ void SceneGraph::setCamera(Camera *camera)
|
||||
_Camera = camera;
|
||||
}
|
||||
|
||||
Camera* SceneGraph::getCamera()const
|
||||
{
|
||||
return _Camera.pointer();
|
||||
}
|
||||
|
||||
void SceneGraph::update(Scalar time)
|
||||
{
|
||||
_RootNode->update (time);
|
||||
|
@ -18,6 +18,7 @@ public:
|
||||
SceneNode* getRootNode();
|
||||
|
||||
void setCamera(Camera *camera);
|
||||
Camera* getCamera() const;
|
||||
|
||||
void update(Scalar time);
|
||||
void queue (RenderQueue *queue);
|
||||
|
@ -107,8 +107,11 @@ void SceneNode::queue(RenderQueue *queue, Camera *camera)
|
||||
{
|
||||
if (isActive())
|
||||
{
|
||||
SceneNodeList::iterator i;
|
||||
if (_Model.valid())
|
||||
queue->addOpaqueItem(_Model, _AbsoluteTransformation.translation,
|
||||
_AbsoluteTransformation.rotation);
|
||||
|
||||
SceneNodeList::iterator i;
|
||||
for (i = _Children.begin(); i != _Children.end(); i++)
|
||||
{
|
||||
( *i )->queue(queue, camera);
|
||||
@ -138,13 +141,33 @@ void SceneNode::setRelativeRotation(const Quaternion &rotation)
|
||||
|
||||
void SceneNode::updateAbsoluteTransformation()
|
||||
{
|
||||
/*
|
||||
if (_Parent )
|
||||
_AbsoluteTranslation = _Parent->getAbsoluteTranslation()
|
||||
+_Parent->getAbsoluteRotation().inversed() * _RelativeTranslation;
|
||||
else
|
||||
_AbsoluteTranslation = _RelativeTranslation;
|
||||
*/
|
||||
if (_Parent)
|
||||
{
|
||||
_AbsoluteTransformation.translation = _Parent->getAbsoluteTransformation().translation
|
||||
+_Parent->getAbsoluteTransformation().rotation.inversed().apply(_RelativeTransformation.translation);
|
||||
}
|
||||
else
|
||||
_AbsoluteTransformation.translation = _RelativeTransformation.translation;
|
||||
}
|
||||
|
||||
void SceneNode::setRigidBody(RigidBody* body)
|
||||
{
|
||||
_RigidBody = body;
|
||||
}
|
||||
|
||||
RigidBody* SceneNode::getRigidBody()
|
||||
{
|
||||
return _RigidBody.pointer();
|
||||
}
|
||||
|
||||
void SceneNode::setModel(Model* model)
|
||||
{
|
||||
_Model = model;
|
||||
}
|
||||
|
||||
Model* SceneNode::getModel()
|
||||
{
|
||||
return _Model.pointer();
|
||||
}
|
||||
|
||||
} // namespace BlueCore
|
||||
|
@ -32,8 +32,8 @@ class SceneNode : public Referenced, public Named, public Activated
|
||||
Transformation _RelativeTransformation;
|
||||
Transformation _AbsoluteTransformation;
|
||||
|
||||
weak_ptr<RigidBody> _RigidBody;
|
||||
weak_ptr<Model> _Model;
|
||||
ref_ptr<RigidBody> _RigidBody;
|
||||
ref_ptr<Model> _Model;
|
||||
|
||||
public:
|
||||
|
||||
@ -44,6 +44,12 @@ class SceneNode : public Referenced, public Named, public Activated
|
||||
SceneNode *getParent() const;
|
||||
const SceneNodeList &getChildren() const;
|
||||
|
||||
void setRigidBody (RigidBody* body);
|
||||
RigidBody* getRigidBody ();
|
||||
|
||||
void setModel (Model* body);
|
||||
Model* getModel ();
|
||||
|
||||
void attach(SceneNode *node);
|
||||
void detach(SceneNode *node);
|
||||
void detachAll();
|
||||
|
@ -15,10 +15,9 @@ using namespace std;
|
||||
|
||||
namespace BlueCore
|
||||
{
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
static ScriptSystem* gScriptSystem = 0;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
void _sq_compiler_error_handler(HSQUIRRELVM vm, const SQChar *error,
|
||||
const SQChar *source, SQInteger line, SQInteger column)
|
||||
{
|
||||
@ -26,7 +25,6 @@ void _sq_compiler_error_handler(HSQUIRRELVM vm, const SQChar *error,
|
||||
<< error << endlog;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
static SQInteger _sq_runtime_error_handler(HSQUIRRELVM vm)
|
||||
{
|
||||
const SQChar *error = 0;
|
||||
@ -46,7 +44,6 @@ static SQInteger _sq_runtime_error_handler(HSQUIRRELVM vm)
|
||||
return 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
void _sq_print(HSQUIRRELVM vm, const SQChar* s, ...)
|
||||
{
|
||||
va_list vl;
|
||||
@ -55,7 +52,6 @@ void _sq_print(HSQUIRRELVM vm, const SQChar* s, ...)
|
||||
va_end ( vl );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
static SQInteger _sq_require(HSQUIRRELVM v)
|
||||
{
|
||||
const SQChar *scriptname = 0;
|
||||
@ -69,7 +65,6 @@ static SQInteger _sq_require(HSQUIRRELVM v)
|
||||
return 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
SQInteger _sq_file_reader(SQUserPointer file)
|
||||
{
|
||||
char c;
|
||||
@ -82,7 +77,6 @@ SQInteger _sq_file_reader(SQUserPointer file)
|
||||
return 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
ScriptSystem::ScriptSystem()
|
||||
{
|
||||
gScriptSystem = this;
|
||||
@ -103,20 +97,17 @@ ScriptSystem::ScriptSystem()
|
||||
clog << ">>> ScriptSystem constructed ..."<< endlog;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
ScriptSystem::~ScriptSystem()
|
||||
{
|
||||
sq_close(_VM);
|
||||
clog << ">>> ScriptSystem destructed ..."<< endlog;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
HSQUIRRELVM ScriptSystem::getVM()
|
||||
{
|
||||
return _VM;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
bool ScriptSystem::loadScript(const std::string &name)
|
||||
{
|
||||
for (unsigned int i = 0; i < _LoadedScripts.size(); i++)
|
||||
@ -136,7 +127,6 @@ bool ScriptSystem::loadScript(const std::string &name)
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
bool ScriptSystem::executeScript(const std::string &name)
|
||||
{
|
||||
string filename = name + ".nut";
|
||||
@ -172,7 +162,6 @@ bool ScriptSystem::executeScript(const std::string &name)
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
void ScriptSystem::callFunction(const std::string &name)
|
||||
{
|
||||
sq_pushroottable(_VM);
|
||||
@ -186,7 +175,6 @@ void ScriptSystem::callFunction(const std::string &name)
|
||||
sq_pop(_VM, 1);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
void ScriptSystem::callFunction(const std::string &name, double value)
|
||||
{
|
||||
sq_pushroottable(_VM);
|
||||
@ -201,7 +189,8 @@ void ScriptSystem::callFunction(const std::string &name, double value)
|
||||
sq_pop(_VM, 1);
|
||||
}
|
||||
|
||||
void ScriptSystem::callFunction(const std::string &name, double value1, double value2)
|
||||
void ScriptSystem::callFunction(const std::string &name, double value1,
|
||||
double value2)
|
||||
{
|
||||
sq_pushroottable(_VM);
|
||||
sq_pushstring(_VM, name.c_str(), -1);
|
||||
|
75
engine/ScriptSystem_Model.cpp
Normal file
75
engine/ScriptSystem_Model.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
#include "ScriptSystem_Model.h"
|
||||
|
||||
namespace BlueCore
|
||||
{
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static weak_ptr<ModelManager> gModelManager;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static SQInteger _model_releasehook(SQUserPointer p, SQInteger size)
|
||||
{
|
||||
Model *model = (Model *)p;
|
||||
|
||||
if (model)
|
||||
model->removeReference();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static SQInteger _model_constructor(HSQUIRRELVM vm)
|
||||
{
|
||||
SQInteger argc = sq_gettop(vm);
|
||||
|
||||
Model *model = 0;
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
const SQChar *name = 0;
|
||||
|
||||
sq_getstring(vm, 2, &name);
|
||||
|
||||
if (gModelManager.valid())
|
||||
{
|
||||
model = gModelManager->loadModel(name);
|
||||
if (model)
|
||||
model->addReference();
|
||||
}
|
||||
}
|
||||
|
||||
sq_setinstanceup(vm, 1, (void *)model );
|
||||
sq_setreleasehook(vm, 1, _model_releasehook);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void setupScriptSystem_Model(ScriptSystem* scriptsystem, ModelManager* modelmanager)
|
||||
{
|
||||
if (scriptsystem && modelmanager)
|
||||
{
|
||||
HSQUIRRELVM vm = scriptsystem->getVM();
|
||||
|
||||
gModelManager = modelmanager;
|
||||
|
||||
sq_pushroottable(vm);
|
||||
|
||||
// push class
|
||||
sq_pushstring(vm, "Model", -1);
|
||||
|
||||
if (SQ_SUCCEEDED(sq_newclass(vm, SQFalse) ) )
|
||||
{
|
||||
// register constructor
|
||||
sq_pushstring(vm, "constructor", -1);
|
||||
sq_newclosure(vm, _model_constructor, 0);
|
||||
sq_newslot(vm, -3, false);
|
||||
|
||||
// create class
|
||||
sq_newslot(vm, -3, false);
|
||||
}
|
||||
|
||||
sq_poptop(vm);
|
||||
}
|
||||
}
|
||||
}
|
14
engine/ScriptSystem_Model.h
Normal file
14
engine/ScriptSystem_Model.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef BLUECORE_SCRIPTING_MODEL_H
|
||||
#define BLUECORE_SCRIPTING_MODEL_H
|
||||
|
||||
#include "ModelManager.h"
|
||||
#include "ScriptSystem.h"
|
||||
|
||||
#include "squirrel.h"
|
||||
|
||||
namespace BlueCore
|
||||
{
|
||||
void setupScriptSystem_Model(ScriptSystem* scriptsystem, ModelManager* modelmanager);
|
||||
}
|
||||
|
||||
#endif
|
@ -48,6 +48,22 @@ static SQInteger _set_camera(HSQUIRRELVM v)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger _attach_node(HSQUIRRELVM v)
|
||||
{
|
||||
SceneGraph *scenegraph = 0;
|
||||
|
||||
sq_getinstanceup(v, 1, ( void ** ) &scenegraph, 0);
|
||||
|
||||
if (scenegraph)
|
||||
{
|
||||
SceneNode *node;
|
||||
sq_getinstanceup (v, 2, ( void ** ) &node, 0);
|
||||
scenegraph->getRootNode()->attach(node);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void setupScriptSystem_SceneGraph(ScriptSystem* scriptsystem)
|
||||
{
|
||||
if (scriptsystem == 0)
|
||||
@ -71,6 +87,10 @@ void setupScriptSystem_SceneGraph(ScriptSystem* scriptsystem)
|
||||
sq_newclosure(vm, _set_camera, 0);
|
||||
sq_newslot(vm, -3, false);
|
||||
|
||||
sq_pushstring(vm, "attachNode", -1);
|
||||
sq_newclosure(vm, _attach_node, 0);
|
||||
sq_newslot(vm, -3, false);
|
||||
|
||||
// create class
|
||||
sq_newslot(vm, -3, false);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef BLUECORE_SCRIPTING_CAMERA_H
|
||||
#define BLUECORE_SCRIPTING_CAMERA_H
|
||||
#ifndef BLUECORE_SCRIPTING_SCENEGRAPH_H
|
||||
#define BLUECORE_SCRIPTING_SCENEGRAPH_H
|
||||
|
||||
#include "ScriptSystem.h"
|
||||
|
||||
|
119
engine/ScriptSystem_SceneNode.cpp
Normal file
119
engine/ScriptSystem_SceneNode.cpp
Normal file
@ -0,0 +1,119 @@
|
||||
#include "ScriptSystem_SceneNode.h"
|
||||
#include "ScriptSystem_Math.h"
|
||||
|
||||
#include "SceneNode.h"
|
||||
|
||||
namespace BlueCore
|
||||
{
|
||||
|
||||
static SQInteger _scenenode_releasehook(SQUserPointer p, SQInteger size)
|
||||
{
|
||||
SceneNode *node = (SceneNode *)p;
|
||||
|
||||
if (node)
|
||||
node->removeReference();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger _scenenode_constructor(HSQUIRRELVM vm)
|
||||
{
|
||||
SQInteger argc = sq_gettop(vm);
|
||||
|
||||
SceneNode *node = 0;
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
const SQChar *name = 0;
|
||||
|
||||
sq_getstring(vm, 2, &name);
|
||||
|
||||
node = new SceneNode (name);
|
||||
if (node)
|
||||
node->addReference();
|
||||
}
|
||||
|
||||
sq_setinstanceup(vm, 1, (void *)node );
|
||||
sq_setreleasehook(vm, 1, _scenenode_releasehook);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger _set_model(HSQUIRRELVM v)
|
||||
{
|
||||
SceneNode *node = 0;
|
||||
|
||||
sq_getinstanceup(v, 1, ( void ** ) &node, 0);
|
||||
|
||||
if (node)
|
||||
{
|
||||
Model *model;
|
||||
sq_getinstanceup(v, 2, ( void ** ) &model, 0);
|
||||
node->setModel(model);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger _set_position(HSQUIRRELVM v)
|
||||
{
|
||||
SceneNode *node = 0;
|
||||
|
||||
sq_getinstanceup(v, 1, ( void ** ) &node, 0);
|
||||
|
||||
if (node)
|
||||
{
|
||||
Vector3 position;
|
||||
int argc = sq_gettop(v);
|
||||
|
||||
if (argc == 2)
|
||||
{
|
||||
_getvectorvalues(v, 2, position.x, position.y, position.z);
|
||||
}
|
||||
else if (argc == 4)
|
||||
{
|
||||
sq_getfloat(v, 2, &position.x);
|
||||
sq_getfloat(v, 3, &position.y);
|
||||
sq_getfloat(v, 4, &position.z);
|
||||
}
|
||||
|
||||
node->setRelativeTranslation(position);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void setupScriptSystem_SceneNode(ScriptSystem* scriptsystem)
|
||||
{
|
||||
if (scriptsystem)
|
||||
{
|
||||
HSQUIRRELVM vm = scriptsystem->getVM();
|
||||
|
||||
sq_pushroottable(vm);
|
||||
|
||||
// push class
|
||||
sq_pushstring(vm, "SceneNode", -1);
|
||||
|
||||
if (SQ_SUCCEEDED(sq_newclass(vm, SQFalse) ) )
|
||||
{
|
||||
// register constructor
|
||||
sq_pushstring(vm, "constructor", -1);
|
||||
sq_newclosure(vm, _scenenode_constructor, 0);
|
||||
sq_newslot(vm, -3, false);
|
||||
|
||||
sq_pushstring(vm, "setModel", -1);
|
||||
sq_newclosure(vm, _set_model, 0);
|
||||
sq_newslot(vm, -3, false);
|
||||
|
||||
sq_pushstring(vm, "setPosition", -1);
|
||||
sq_newclosure(vm, _set_position, 0);
|
||||
sq_newslot(vm, -3, false);
|
||||
|
||||
// create class
|
||||
sq_newslot(vm, -3, false);
|
||||
}
|
||||
|
||||
sq_poptop(vm);
|
||||
}
|
||||
}
|
||||
}
|
13
engine/ScriptSystem_SceneNode.h
Normal file
13
engine/ScriptSystem_SceneNode.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef BLUECORE_SCRIPTING_SCENE_NODE_H
|
||||
#define BLUECORE_SCRIPTING_SCENE_NODE_H
|
||||
|
||||
#include "ScriptSystem.h"
|
||||
|
||||
#include "squirrel.h"
|
||||
|
||||
namespace BlueCore
|
||||
{
|
||||
void setupScriptSystem_SceneNode(ScriptSystem* scriptsystem);
|
||||
}
|
||||
|
||||
#endif
|
@ -14,7 +14,7 @@ using namespace std;
|
||||
|
||||
namespace BlueCore
|
||||
{
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ShaderManager::ShaderManager(RenderWindow* renderwindow) :
|
||||
_usingShaders(true), _RenderWindow(renderwindow)
|
||||
{
|
||||
@ -33,13 +33,11 @@ ShaderManager::ShaderManager(RenderWindow* renderwindow) :
|
||||
clog << " shaders not supported!"<< endlog;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
ShaderManager::~ShaderManager()
|
||||
{
|
||||
clog << ">>> ShaderManager destructed ..."<< endlog;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void ShaderManager::shutdown()
|
||||
{
|
||||
clog << ">>> ShaderManager shutting down ..."<< endlog;
|
||||
@ -66,19 +64,16 @@ void ShaderManager::shutdown()
|
||||
fragment_shader.clear();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void ShaderManager::WindowCloseSlot()
|
||||
{
|
||||
shutdown();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool ShaderManager::usingShaders()
|
||||
{
|
||||
return _usingShaders;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void printInfoLog(GLhandleARB obj)
|
||||
{
|
||||
int infologLength = 0;
|
||||
@ -100,7 +95,6 @@ void printInfoLog(GLhandleARB obj)
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
VertexShader ShaderManager::loadVertexShader(const string &name)
|
||||
{
|
||||
if ( !_usingShaders)
|
||||
@ -116,9 +110,9 @@ VertexShader ShaderManager::loadVertexShader(const string &name)
|
||||
return result->second;
|
||||
}
|
||||
|
||||
string filename = name + ".vert";
|
||||
//string filename = name + ".vert";
|
||||
|
||||
PHYSFS_file *file = PHYSFS_openRead(filename.c_str() );
|
||||
PHYSFS_file *file = PHYSFS_openRead(name.c_str() );
|
||||
|
||||
if ( !file)
|
||||
{
|
||||
@ -148,7 +142,6 @@ VertexShader ShaderManager::loadVertexShader(const string &name)
|
||||
return shader;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
FragmentShader ShaderManager::loadFragmentShader(const string &name)
|
||||
{
|
||||
if ( !_usingShaders)
|
||||
@ -164,9 +157,9 @@ FragmentShader ShaderManager::loadFragmentShader(const string &name)
|
||||
return result->second;
|
||||
}
|
||||
|
||||
string filename = name + ".frag";
|
||||
//string filename = name + ".frag";
|
||||
|
||||
PHYSFS_file *file = PHYSFS_openRead(filename.c_str() );
|
||||
PHYSFS_file *file = PHYSFS_openRead(name.c_str() );
|
||||
|
||||
if ( !file)
|
||||
{
|
||||
@ -198,7 +191,6 @@ FragmentShader ShaderManager::loadFragmentShader(const string &name)
|
||||
return shader;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
ShaderProgram ShaderManager::loadShaderProgram(const std::string &name)
|
||||
{
|
||||
if ( !_usingShaders)
|
||||
@ -276,7 +268,6 @@ ShaderProgram ShaderManager::loadShaderProgram(const std::string &name)
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void ShaderManager::useShaderProgram(ShaderProgram shader_program)
|
||||
{
|
||||
if ( !_usingShaders)
|
||||
@ -285,7 +276,6 @@ void ShaderManager::useShaderProgram(ShaderProgram shader_program)
|
||||
glUseProgramObjectARB(shader_program);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void ShaderManager::useTexture(ShaderProgram shader_program,
|
||||
unsigned int texture, const std::string &name)
|
||||
{
|
||||
@ -298,7 +288,7 @@ void ShaderManager::useTexture(ShaderProgram shader_program,
|
||||
glUniform1iARB(location, texture);
|
||||
}
|
||||
/*
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void ShaderManager::useTangentBuffer (
|
||||
ShaderProgram shader_program,
|
||||
TangentBuffer *tangent_buffer,
|
||||
@ -316,7 +306,7 @@ void ShaderManager::useTexture(ShaderProgram shader_program,
|
||||
glVertexAttribPointerARB ( location, 3, GL_FLOAT, 0, 0, 0 );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void ShaderManager::disableTangentBuffer (
|
||||
ShaderProgram shader_program,
|
||||
const std::string &name )
|
||||
|
@ -1,11 +0,0 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
class IniParser
|
||||
{
|
||||
std::map<std::string, std::string> _Pairs;
|
||||
|
||||
void parse (const std::string &text)
|
||||
{
|
||||
}
|
||||
}
|
@ -81,8 +81,15 @@ function Initialize()
|
||||
::body = RigidBody();
|
||||
::camera = Camera();
|
||||
::mainSceneGraph = SceneGraph();
|
||||
::camera.lookAt (0.0, 0.0, 0.0);
|
||||
// ::camera.lookAt (0.0, 0.0, 0.0);
|
||||
::mainSceneGraph.setCamera (::camera);
|
||||
setSceneGraph(::mainSceneGraph);
|
||||
local model = Model ("combat");
|
||||
local node = SceneNode("test");
|
||||
node.setModel (model);
|
||||
node.setPosition (0.0, 0.0, -50.0);
|
||||
::mainSceneGraph.attachNode (node);
|
||||
|
||||
}
|
||||
|
||||
function OnFrame (delta, total)
|
||||
@ -101,10 +108,11 @@ function OnOverlay (delta, total)
|
||||
::frameCount = 0;
|
||||
::lastFPS -= 0.1;
|
||||
}
|
||||
|
||||
/*
|
||||
if (total < 2.0)
|
||||
::logo.draw (0.5, 0.5);
|
||||
else
|
||||
*/
|
||||
{
|
||||
v <- ::body.getPosition();
|
||||
::font.print(10, 40, "Position: " + v.x + ", " + v.y + ", " + v.z, 1, 1 );
|
||||
@ -125,7 +133,7 @@ function OnOverlay (delta, total)
|
||||
|
||||
function OnStep (delta, total)
|
||||
{
|
||||
::body.applyLocalForce( Vector(1.0, 0.0, 1.0) );
|
||||
::body.applyLocalForce( Vector(0.0, 0.0, 1.0) );
|
||||
}
|
||||
|
||||
function Shutdown()
|
||||
|
@ -17,6 +17,8 @@ SceneGraph
|
||||
* make ShaderProgram a class
|
||||
* create RenderSet AND/OR RenderQueue
|
||||
* RenderQueueVisitor
|
||||
* reimport input class
|
||||
* use vbos for meshes and tangents
|
||||
|
||||
#if 0
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user