Fixed up lighting and color

actorid
Nicolay Korslund 15 years ago
parent 847ef6df5d
commit 415f9e31aa

@ -32,8 +32,10 @@ void insertObj(CellRender& cellRender, const ESMS::LiveCellRef<ESM::Light>& live
int color = liveRef.base->data.color;
cellRender.insertLight ((color >> 24) & 255, (color >> 16) & 255, (color >> 8) & 255,
liveRef.base->data.radius);
cellRender.insertLight(color & 255,
(color >> 8) & 255,
(color >> 16) & 255,
liveRef.base->data.radius);
cellRender.insertEnd();
}

@ -118,33 +118,28 @@ std::string InteriorCellRender::insertEnd()
void InteriorCellRender::configureAmbient()
{
ambientColor.setAsRGBA (cell.cell->ambi.ambient);
ambientColor.setAsABGR (cell.cell->ambi.ambient);
setAmbientMode();
if (cell.cell->data.flags & ESM::Cell::QuasiEx)
{
// Create a "sun" that shines light downwards. It doesn't look
// completely right, but leave it for now.
Ogre::Light *light = scene.getMgr()->createLight();
Ogre::ColourValue colour;
colour.setAsRGBA (cell.cell->ambi.sunlight);
light->setDiffuseColour (colour);
light->setType(Ogre::Light::LT_DIRECTIONAL);
light->setDirection(0,-1,0);
// TODO: update position on regular basis or attach to camera scene node
}
// Create a "sun" that shines light downwards. It doesn't look
// completely right, but leave it for now.
Ogre::Light *light = scene.getMgr()->createLight();
Ogre::ColourValue colour;
colour.setAsABGR (cell.cell->ambi.sunlight);
light->setDiffuseColour (colour);
light->setType(Ogre::Light::LT_DIRECTIONAL);
light->setDirection(0,-1,0);
}
// configure fog according to cell
void InteriorCellRender::configureFog()
{
Ogre::ColourValue color;
color.setAsRGBA (cell.cell->ambi.fog);
float high = 10000;
float low = 8000;
color.setAsABGR (cell.cell->ambi.fog);
float high = 4500 + 9000 * (1-cell.cell->ambi.fogDensity);
float low = 200;
scene.getMgr()->setFog (FOG_LINEAR, color, 0, low, high);
scene.getCamera()->setFarClipDistance (high + 10);
scene.getViewport()->setBackgroundColour (color);

@ -21,57 +21,6 @@
*/
//-----------------------------------------------------------------------
// E X P O R T E D V A R I A B L E S
//-----------------------------------------------------------------------
extern "C"
{
int lightConst;
float lightConstValue;
int lightLinear;
int lightLinearMethod;
float lightLinearValue;
float lightLinearRadiusMult;
int lightQuadratic;
int lightQuadraticMethod;
float lightQuadraticValue;
float lightQuadraticRadiusMult;
int lightOutQuadInLin;
}
//-----------------------------------------------------------------------
// E X P O R T E D F U N C T I O N S
//-----------------------------------------------------------------------
// Toggle ambient light
extern "C" void ogre_toggleLight()
{
if(g_lightOn == 0)
{
std::cout << "Turning the lights up\n";
ColourValue half = 0.7*g_ambient + 0.3*ColourValue(1,1,1);
mSceneMgr->setAmbientLight(half);
g_lightOn = 1;
}
else if(g_lightOn == 1)
{
std::cout << "Turning the lights to full\n";
g_lightOn = 2;
mSceneMgr->setAmbientLight(ColourValue(1,1,1));
}
else
{
std::cout << "Setting lights to normal\n";
g_lightOn = 0;
mSceneMgr->setAmbientLight(g_ambient);
}
}
extern "C" Light* ogre_attachLight(char *name, SceneNode* base,
float r, float g, float b,
float radius)
@ -115,12 +64,6 @@ extern "C" Light* ogre_attachLight(char *name, SceneNode* base,
return l;
}
// Toggle between fullscreen and windowed mode.
extern "C" void ogre_toggleFullscreen()
{
std::cout << "Not implemented yet\n";
}
extern "C" void ogre_setAmbient(float r, float g, float b, // Ambient light
float rs, float gs, float bs) // "Sunlight"
{
@ -175,26 +118,6 @@ void cloneNode(SceneNode *from, SceneNode *to, char* name)
}
}
// Convert a Morrowind rotation (3 floats) to a quaternion (4 floats)
extern "C" void ogre_mwToQuaternion(float *mw, float *quat)
{
// Rotate around X axis
Quaternion xr(Radian(-mw[0]), Vector3::UNIT_X);
// Rotate around Y axis
Quaternion yr(Radian(-mw[1]), Vector3::UNIT_Y);
// Rotate around Z axis
Quaternion zr(Radian(-mw[2]), Vector3::UNIT_Z);
// Rotates first around z, then y, then x
Quaternion res = xr*yr*zr;
// Copy result back to caller
for(int i=0; i<4; i++)
quat[i] = res[i];
}
// Supposed to insert a copy of the node, for now it just inserts the
// actual node.
extern "C" SceneNode *ogre_insertNode(SceneNode *base, char* name,

@ -1,70 +1,3 @@
/*
OpenMW - The completely unofficial reimplementation of Morrowind
Copyright (C) 2008-2009 Nicolay Korslund
Email: < korslund@gmail.com >
WWW: http://openmw.snaptoad.com/
This file (ogre.d) is part of the OpenMW package.
OpenMW is distributed as free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License
version 3, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
version 3 along with this program. If not, see
http://www.gnu.org/licenses/ .
*/
module ogre.ogre;
import core.resource;
import core.config;
import ogre.bindings;
import gui.bindings;
import mscripts.setup;
import bullet.bindings;
import util.uniquename;
import std.stdio;
import esm.defs;
extern(C) {
extern int lightConst;
extern float lightConstValue;
extern int lightLinear;
extern int lightLinearMethod;
extern float lightLinearValue;
extern float lightLinearRadiusMult;
extern int lightQuadratic;
extern int lightQuadraticMethod;
extern float lightQuadraticValue;
extern float lightQuadraticRadiusMult;
extern int lightOutQuadInLin;
}
class OgreException : Exception
{
this(char[] msg) {super("OgreException: " ~ msg);}
static void opCall(char[] msg)
{
throw new OgreException(msg);
}
}
// Place a mesh in the 3D scene graph, at the given
// location/scale. Returns a node pointer to the inserted object.
NodePtr placeObject(MeshIndex mesh, Placement *pos, float scale,
@ -97,46 +30,6 @@ NodePtr placeObject(MeshIndex mesh, Placement *pos, float scale,
return node;
}
NodePtr attachLight(NodePtr parent, Color c, float radius)
{
return ogre_attachLight(UniqueName("_light").ptr, parent,
c.red/255.0, c.green/255.0, c.blue/255.0,
radius);
}
// If 'true' then we must call ogre_cleanup() on exit.
bool ogreSetup = false;
// Make sure we clean up
static ~this()
{
cleanupOgre();
}
// Loads ogre configurations, creats the root, etc.
void setupOgre(bool debugOut)
{
char[] plugincfg;
version(Windows)
plugincfg = "plugins.cfg.win32";
else version(Posix)
plugincfg = "plugins.cfg.linux";
else
// Assume the user knows what to do
plugincfg = "plugins.cfg";
// Later we will send more config info from core.config along with
// this function
if(ogre_configure(config.finalOgreConfig, toStringz(plugincfg), debugOut))
OgreException("Configuration abort");
ogre_initWindow();
ogre_makeScene();
ogreSetup = true;
}
void setAmbient(Color amb, Color sun, Color fog, float density)
{
ogre_setAmbient(amb.red/255.0, amb.green/255.0, amb.blue/255.0,
@ -150,24 +43,6 @@ void setAmbient(Color amb, Color sun, Color fog, float density)
ogre_setFog(fog.red/255.0, fog.green/255.0, fog.blue/255.0, 200, fhigh);
}
// Jump into the OGRE rendering loop. Everything should be loaded and
// done before calling this.
void startRendering()
{
// Kick OGRE into gear
ogre_startRendering();
}
// Cleans up after OGRE. Resets things like screen resolution, mouse
// control and keyboard repeat rate.
void cleanupOgre()
{
if(ogreSetup)
ogre_cleanup();
ogreSetup = false;
}
// Gives the placement of an item in the scene (position and
// orientation). It must have this exact structure since we also use
// it when reading ES files.

Loading…
Cancel
Save