Add class SDView - Now car can be selected for camera

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5103 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 831e402dc1266659e1cbed3c70f7f8520e3f0fe9
Former-commit-id: c65bb14b81057a2559db7647313067e977e91beb
This commit is contained in:
torcs-ng 2013-01-15 22:23:42 +00:00
parent b04c7544aa
commit 96b14311b4
9 changed files with 646 additions and 23 deletions

View file

@ -1,11 +1,14 @@
INCLUDE(../../../../cmake/macros.cmake)
SET(OSGGRAPH_HEADERS AccGeode.h AccException.h ReaderWriterACC.h
SET(OSGGRAPH_HEADERS OsgVectorArrayAdapter.h OsgColor.h
AccGeode.h AccException.h ReaderWriterACC.h
OsgLoader.h OsgScenery.h OsgRender.h OsgMath.h OsgMain.h
OsgView.h
OsgGraph.h OsgCar.h OsgWheel.h OsgBrake.h)
SET(OSGGRAPH_SOURCES AccGeode.cpp AccException.cpp ReaderWriterACC.cpp
OsgLoader.cpp OsgBackground.cpp OsgScenery.cpp OsgRender.cpp
OsgLoader.cpp OsgBackground.cpp OsgScenery.cpp
OsgView.cpp OsgRender.cpp
OsgMath.cpp OsgMain.cpp OsgGraph.cpp OsgCar.cpp OsgWheel.cpp
OsgBrake.cpp)

View file

@ -0,0 +1,76 @@
/***************************************************************************
file : OsgColor.h
created : Sat Jan 13 00:00:41 CEST 2013
copyright : (C) 2012 by Xavier Bertaux
email : bertauxx@yahoo.fr
version : $Id: OsgColor.h 4693 2013-01-12 03:12:09Z torcs-ng $
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef _OSGCOLORS_H
#define _OSGCOLORS_H 1
#include <math.h>
#if defined (sgi)
const float system_gamma = 2.0/1.7;
#else // others
const float system_gamma = 2.5;
#endif
// simple architecture independant gamma correction function.
inline void sd_gamma_correct_rgb(float *color,
float reff = 2.5, float system = system_gamma)
{
if (reff == system)
return;
float tmp = reff/system;
color[0] = pow(color[0], tmp);
color[1] = pow(color[1], tmp);
color[2] = pow(color[2], tmp);
};
inline void sd_gamma_correct_c(float *color,
float reff = 2.5, float system = system_gamma)
{
if (reff == system)
return;
*color = pow(*color, reff/system);
};
inline void sd_gamma_restore_rgb(float *color,
float reff = 2.5, float system = system_gamma)
{
if (reff == system)
return;
float tmp = system/reff;
color[0] = pow(color[0], tmp);
color[1] = pow(color[1], tmp);
color[2] = pow(color[2], tmp);
};
inline void sd_gamma_restore_c(float *color,
float reff = 2.5, float system = system_gamma)
{
if (reff == system)
return;
*color = pow(*color, system/reff);
};
#endif // _OSGCOLORS_H

View file

@ -29,6 +29,7 @@
#include "OsgCar.h"
#include "OsgScenery.h"
#include "OsgRender.h"
#include "OsgView.h"
#include "OsgMath.h"
@ -53,6 +54,7 @@
SDCars *cars = NULL;
SDScenery *scenery = NULL;
SDRender *render = NULL;
SDViewer *viewer = NULL;
static osg::ref_ptr<osg::Group> m_sceneroot;
static osg::ref_ptr<osg::Group> m_carroot;
@ -76,7 +78,7 @@ int grWinx, grWiny, grWinw, grWinh;
tdble grLodFactorValue = 1.0;
// Frame/FPS info.
static cGrFrameInfo frameInfo;
static SDFrameInfo frameInfo;
static double fFPSPrevInstTime; // Last "instant" FPS refresh time
static unsigned nFPSTotalSeconds; // Total duration since initView
double ratio = 0.0f;
@ -424,15 +426,15 @@ grSelectBoard(void *vp)
}*/
static void
grPrevCar(void * /* dummy */)
SDPrevCar(void * /* dummy */)
{
//return 0; //grGetCurrentScreen()->selectPrevCar();
viewer->selectPrevCar();
}
static void
grNextCar(void * /* dummy */)
SDNextCar(void * /* dummy */)
{
//return 0; //grGetCurrentScreen()->selectNextCar();
viewer->selectNextCar();
}
//static void*/
@ -445,6 +447,7 @@ int
initView(int x, int y, int width, int height, int /* flag */, void *screen)
{
render = new SDRender;
viewer = new SDViewer;
int i;
grWinx = x;
@ -475,7 +478,8 @@ initView(int x, int y, int width, int height, int /* flag */, void *screen)
m_sceneViewer->getCamera()->setProjectionMatrixAsPerspective(67.5f, static_cast<double>((float)grWinw / (float)grWinh), 0.1f, 12000.0f);
//m_sceneViewer->realize();
m_sceneViewer->setSceneData(m_sceneroot);
render->Init(m_sceneViewer);
/*// Create the screens and initialize each board.
for (i = 0; i < GR_NB_MAX_SCREEN; i++) {
@ -487,8 +491,8 @@ initView(int x, int y, int width, int height, int /* flag */, void *screen)
GfuiAddKey(screen, GFUIK_HOME, "Zoom Maximum", (void*)GR_ZOOM_MAX, grSetZoom, NULL);
GfuiAddKey(screen, '*', "Zoom Default", (void*)GR_ZOOM_DFLT, grSetZoom, NULL);*/
//GfuiAddKey( 0, GFUIK_PAGEUP, "Select Previous Car", (void*)0, grPrevCar, NULL);
//GfuiAddKey( 0, GFUIK_PAGEDOWN, "Select Next Car", (void*)0, grNextCar, NULL);
GfuiAddKey( screen, GFUIK_PAGEUP, "Select Previous Car", (void*)0, SDPrevCar, NULL);
GfuiAddKey( screen, GFUIK_PAGEDOWN, "Select Next Car", (void*)0, SDNextCar, NULL);
/*GfuiAddKey(screen, GFUIK_F2, "Driver Views", (void*)0, grSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F3, "Car Views", (void*)1, grSelectCamera, NULL);
@ -521,9 +525,6 @@ initView(int x, int y, int width, int height, int /* flag */, void *screen)
GfLogInfo("Current screen is #%d (out of %d)\n", nCurrentScreenIndex, grNbActiveScreens);
render->Init(m_sceneroot, m_sceneViewer);
m_sceneViewer->setSceneData(m_sceneroot);
//grLodFactorValue = GfParmGetNum(grHandle, GR_SCT_GRAPHIC, GR_ATT_LODFACTOR, NULL, 1.0);
return 0; // true;
@ -554,7 +555,8 @@ refresh(tSituation *s)
//int i;
int nb = s->_ncars;
tCarElt *car = s->cars[nb-1];
viewer->update(s, &frameInfo);
tCarElt *car = viewer->getCurrentCar();
cars->updateCars();
@ -831,10 +833,19 @@ initTrack(tTrack *track)
int initCars(tSituation *s)
{
char buf[256];
cars = new SDCars;
m_sceneroot->addChild(cars->loadCars(s));
GfOut("All cars loaded\n");
if (!grHandle)
{
sprintf(buf, "%s%s", GfLocalDir(), GR_PARAM_FILE);
grHandle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
}
viewer->Init(s);
return 0;
}

View file

@ -20,9 +20,9 @@
#ifndef _OSGMAIN_H_
#define _OSGMAIN_H_
#include <osg/Group>
#include <osgViewer/Viewer>
#include <osg/Camera>
//#include <osg/Group>
//#include <osgViewer/Viewer>
//#include <osg/Camera>
#include <graphic.h>
#include <raceman.h> //tSituation
@ -65,6 +65,7 @@ extern int grNbActiveScreens;
class SDScenery;
class SDCars;
class SDRender;
class SDViewer;
//static
@ -79,7 +80,7 @@ class SDRender;
extern tdble grLodFactorValue;
class cGrFrameInfo
class SDFrameInfo
{
public:
double fInstFps; // "Instant" frame rate (average along a 1 second shifting window).

View file

@ -25,7 +25,7 @@
#include <osg/Light>
#include <osg/LightSource>
#include <osg/Camera>
#include <osgViewer/Viewer>
#include "OsgMain.h"
#include "OsgRender.h"
@ -44,6 +44,8 @@
#define SCARCE_CLOUD 5
#define COVERAGE_CLOUD 8
static osg::ref_ptr<osg::Group> RealRoot = new osg::Group;
SDRender::SDRender(void)
{
}
@ -58,18 +60,193 @@ SDRender::~SDRender(void)
*
* @return 0 if OK, -1 if something failed
*/
void SDRender::Init(osg::ref_ptr<osg::Group> scene, osg::ref_ptr<osgViewer::Viewer> viewer)
void SDRender::Init(osg::ref_ptr<osgViewer::Viewer> viewer)
{
RealRoot = dynamic_cast<osg::Group*>(viewer->getSceneData());
osg::StateSet* rootStateSet = new osg::StateSet;
RealRoot->setStateSet(rootStateSet);
osg::Group* lightGroup = new osg::Group;
osg::Light* myLight2 = new osg::Light;
myLight2->setLightNum(1);
myLight2->setPosition(osg::Vec4(900.0f, -3220.0f, 1543.0f,1.0f));
myLight2->setPosition(osg::Vec4(100.0f, -3220.0f, 300.0f, 1.0f));
myLight2->setAmbient(osg::Vec4(0.2f, 0.2f, 0.2f, 1.0f));
myLight2->setDiffuse(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
myLight2->setSpecular(osg::Vec4(0.5f, 0.5f, 0.5f, 1.0f));
myLight2->setConstantAttenuation(1.0f);
myLight2->setConstantAttenuation(1.0f);
osg::LightSource* lightS1 = new osg::LightSource;
lightS1->setLight(myLight2);
lightS1->setLocalStateSetModes(osg::StateAttribute::ON);
lightS1->setStateSetModes(*rootStateSet, osg::StateAttribute::ON);
lightGroup->addChild(lightS1);
RealRoot->addChild(lightGroup);
GfOut("LE POINTEUR %d\n",m_carroot.get());
//return 0;
}//SDRender::Init
/*void grUpdateLight( void )
{
const float sol_angle = (float)TheSky->getSA();
const float moon_angle = (float)TheSky->getMA();
float sky_brightness = (float)(1.0 + cos(sol_angle)) / 2.0f;
if (grTrack->local.rain > 0) // TODO: Different values for each rain strength value ?
{
BaseFogColor[0] = 0.42f;
BaseFogColor[1] = 0.44f;
BaseFogColor[2] = 0.50f;
sky_brightness = (float)pow(sky_brightness, 0.5f);
}
else
{
BaseFogColor[0] = 0.84f;
BaseFogColor[1] = 0.84f;
BaseFogColor[2] = 1.00f;
}
SkyColor[0] = BaseSkyColor[0] * sky_brightness;
SkyColor[1] = BaseSkyColor[1] * sky_brightness;
SkyColor[2] = BaseSkyColor[2] * sky_brightness;
SkyColor[3] = BaseSkyColor[3];
grUpdateFogColor(sol_angle);
sd_gamma_correct_rgb( SkyColor );
// 3a)cloud and fog color
CloudsColor[0] = FogColor[0] = BaseFogColor[0] * sky_brightness;
CloudsColor[1] = FogColor[1] = BaseFogColor[1] * sky_brightness;
CloudsColor[2] = FogColor[2] = BaseFogColor[2] * sky_brightness;
CloudsColor[3] = FogColor[3] = BaseFogColor[3];
//grUpdateFogColor(sol_angle);
sd_gamma_correct_rgb( CloudsColor );
float *sun_color = TheSky->get_sun_color();
if (sol_angle > 1.0)
{
if (grVisibility > 1000 && cloudsTextureIndex < 8)
{
CloudsColor[0] = CloudsColor[0] * sun_color[0];
CloudsColor[1] = CloudsColor[1] * sun_color[1];
CloudsColor[2] = CloudsColor[2] * sun_color[2];
}
else
{
CloudsColor[0] = CloudsColor[0] * sun_color[0];
CloudsColor[1] = CloudsColor[1] * sun_color[0];
CloudsColor[2] = CloudsColor[2] * sun_color[0];
}
}
sd_gamma_correct_rgb( CloudsColor );
// 3b) repaint the sky (simply update geometrical, color, ... state, no actual redraw)
TheSky->repaint(SkyColor, FogColor, CloudsColor, sol_angle, moon_angle,
NPlanets, APlanetsData, NStars, AStarsData);
// 3c) update the main light position (it's at the sun position !)
sgCoord solpos;
TheSky->getSunPos(&solpos);
ssgGetLight(0)-> setPosition(solpos.xyz);
// 3c) update scene colors.
if (SDVisibility > 1000 && cloudsTextureIndex < 8)
{
SceneAmbiant[0] = (sun_color[0]*0.25f + CloudsColor[0]*0.75f) * sky_brightness;
SceneAmbiant[1] = (sun_color[1]*0.25f + CloudsColor[1]*0.75f) * sky_brightness;
SceneAmbiant[2] = (sun_color[2]*0.25f + CloudsColor[2]*0.75f) * sky_brightness;
SceneAmbiant[3] = 1.0;
SceneDiffuse[0] = (sun_color[0]*0.25f + FogColor[0]*0.75f) * sky_brightness;
SceneDiffuse[1] = (sun_color[1]*0.25f + FogColor[1]*0.75f) * sky_brightness;
SceneDiffuse[2] = (sun_color[2]*0.25f + FogColor[2]*0.75f) * sky_brightness;
SceneDiffuse[3] = 1.0;
SceneSpecular[0] = sun_color[0] * sky_brightness;
SceneSpecular[1] = sun_color[1] * sky_brightness;
SceneSpecular[2] = sun_color[2] * sky_brightness;
SceneSpecular[3] = 1.0;
}
else
{
SceneAmbiant[0] = (sun_color[0]*0.25f + CloudsColor[0]*0.75f) * sky_brightness;
SceneAmbiant[1] = (sun_color[0]*0.25f + CloudsColor[1]*0.75f) * sky_brightness;
SceneAmbiant[2] = (sun_color[0]*0.25f + CloudsColor[2]*0.75f) * sky_brightness;
SceneAmbiant[3] = 1.0;
SceneDiffuse[0] = (sun_color[0]*0.25f + FogColor[0]*0.75f) * sky_brightness;
SceneDiffuse[1] = (sun_color[0]*0.25f + FogColor[1]*0.75f) * sky_brightness;
SceneDiffuse[2] = (sun_color[0]*0.25f + FogColor[2]*0.75f) * sky_brightness;
SceneDiffuse[3] = 1.0;
SceneSpecular[0] = sun_color[0] * sky_brightness;
SceneSpecular[1] = sun_color[0] * sky_brightness;
SceneSpecular[2] = sun_color[0] * sky_brightness;
SceneSpecular[3] = 1.0;
}
}//grUpdateLight
void grUpdateFogColor(double sol_angle)
{
double rotation;
// first determine the difference between our view angle and local
// direction to the sun
rotation = -(TheSky->getSR() + SGD_PI);
while ( rotation < 0 )
{
rotation += SD_2PI;
}
while ( rotation > SD_2PI )
{
rotation -= SD_2PI;
}
// revert to unmodified values before usign them.
//
float *sun_color = TheSky->get_sun_color();
sd_gamma_correct_rgb( BaseFogColor );
// Calculate the fog color in the direction of the sun for
// sunrise/sunset effects.
//
float s_red = (BaseFogColor[0] + 2 * sun_color[0] * sun_color[0]) / 3;
float s_green = (BaseFogColor[1] + 2 * sun_color[1] * sun_color[1]) / 3;
float s_blue = (BaseFogColor[2] + 2 * sun_color[2] * sun_color[2]) / 3;
// interpolate beween the sunrise/sunset color and the color
// at the opposite direction of this effect. Take in account
// the current visibility.
//
float av = TheSky->getVisibility();
if (av > 45000)
av = 45000;
float avf = 0.87 - (45000 - av) / 83333.33;
float sif = 0.5 - cos( sol_angle * 2)/2;
if (sif < 1e-4)
sif = 1e-4;
float rf1 = fabs((rotation - SD_PI) / SD_PI); // 0.0 .. 1.0
float rf2 = avf * pow(rf1 * rf1, 1 /sif);
float rf3 = 0.94 - rf2;
FogColor[0] = rf3 * BaseFogColor[0] + rf2 * s_red;
FogColor[1] = rf3 * BaseFogColor[1] + rf2 * s_green;
FogColor[2] = rf3 * BaseFogColor[2] + rf2 * s_blue;
sd_gamma_correct_rgb( FogColor );
// make sure the colors have their original value before they are being
// used by the rest of the program.
//
sd_gamma_correct_rgb( BaseFogColor );
}*/

View file

@ -35,9 +35,10 @@ public:
SDRender(void);
~SDRender(void);
void Init(osg::ref_ptr<osg::Group> root, osg::ref_ptr<osgViewer::Viewer> view);
void Init(osg::ref_ptr<osgViewer::Viewer> view);
void Update(float speedcar, tSituation *s);
void UpdateTime(tSituation *s);
void UpdateLight(void);
};
#endif //_OSGRENDER_H_

View file

@ -0,0 +1,53 @@
/***************************************************************************
file : OsgVectorArrayAdapter.h
created : Mon Aug 21 18:24:02 CEST 2012
copyright : (C) 2012 by Xavier Bertaux
email : bertauxx@yahoo.fr
version : $Id$
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef OSGVECTORARRAYADAPTERH
#define OSGVECTORARRAYADAPTERH 1
namespace osggraph
{
template <typename Vector>
class VectorArrayAdapter
{
public:
VectorArrayAdapter(Vector& v, int rowStride, int baseOffset = 0,
int rowOffset = 0):
_v(v), _rowStride(rowStride), _baseOffset(baseOffset),
_rowOffset(rowOffset)
{
}
typename Vector::value_type& operator() (int i, int j)
{
return _v[_baseOffset + i * _rowStride + _rowOffset + j];
}
const typename Vector::value_type& operator() (int i, int j) const
{
return _v[_baseOffset + i * _rowStride + _rowOffset + j];
}
private:
Vector& _v;
const int _rowStride;
const int _baseOffset;
const int _rowOffset;
};
}
#endif

View file

@ -0,0 +1,197 @@
/***************************************************************************
file : OsgViewer.cpp
created : Sun Jan 13 22:11:03 CEST 2013
copyright : (C) 2013 by Xavier Bertaux
email : bertauxx@yahoo.fr
version : $Id$
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <tgfclient.h>
#include "OsgMain.h"
#include "OsgView.h"
//#include "OsgCar.h"
static char buf[1024];
static char path[1024];
static char path2[1024];
SDViewer::SDViewer()
{
id = 0;
curCar = NULL;
//curCam = NULL;
//mirrorCam = NULL;
//dispCam = NULL;
//boardCam = NULL;
//bgCam = NULL;
//board = NULL;
curCamHead = 0;
drawCurrent = 0;
active = false;
selectNextFlag = false;
selectPrevFlag = false;
mirrorFlag = 1;
//memset(cams, 0, sizeof(cams));
//viewRatio = 1.33;
cars = 0;
scrx = 0;
scry = 0;
scrw = 800;
scrh = 600;
}
SDViewer::~SDViewer()
{
//int i;
FREEZ(cars);
}
void SDViewer::switchMirror(void)
{
mirrorFlag = 1 - mirrorFlag;
sprintf(path, "%s/%d", GR_SCT_DISPMODE, id);
GfParmSetNum(grHandle, path, GR_ATT_MIRROR, NULL, (tdble)mirrorFlag);
if (curCar->_driverType == RM_DRV_HUMAN)
{
sprintf(path2, "%s/%s", GR_SCT_DISPMODE, curCar->_name);
GfParmSetNum(grHandle, path2, GR_ATT_MIRROR, NULL, (tdble)mirrorFlag);
}
GfParmWriteFile(NULL, grHandle, "Graph");
}
void SDViewer::Init(tSituation *s)
{
loadParams(s);
}
void SDViewer::camDraw(tSituation *s)
{
GfProfStartProfile("dispCam->beforeDraw*");
//dispCam->beforeDraw();
GfProfStopProfile("dispCam->beforeDraw*");
//glDisable(GL_COLOR_MATERIAL);
GfProfStartProfile("dispCam->update*");
//dispCam->update(curCar, s);
GfProfStopProfile("dispCam->update*");
}
/* Update screen display */
void SDViewer::update(tSituation *s, const SDFrameInfo* frameInfo)
{
/*if (!active)
{
return;
}*/
int carChanged = 0;
if (selectNextFlag)
{
for (int i = 0; i < (s->_ncars - 1); i++)
{
if (curCar == s->cars[i])
{
curCar = s->cars[i + 1];
carChanged = 1;
GfOut("Car Next\n");
break;
}
}
selectNextFlag = false;
}
if (selectPrevFlag)
{
for (int i = 1; i < s->_ncars; i++)
{
if (curCar == s->cars[i])
{
curCar = s->cars[i - 1];
carChanged = 1;
GfOut("Car Previous\n");
break;
}
}
selectPrevFlag = false;
}
if (carChanged)
{
sprintf(path, "%s/%d", GR_SCT_DISPMODE, id);
GfParmSetStr(grHandle, path, GR_ATT_CUR_DRV, curCar->_name);
loadParams (s);
//board->setWidth(fakeWidth);
GfParmWriteFile(NULL, grHandle, "Graph");
//curCam->onSelect(curCar, s);
}
}
void SDViewer::loadParams(tSituation *s)
{
int camNum;
int i;
//class cGrCamera *cam;
const char *carName;
// Initialize the screen "current car" if not already done.
sprintf(path, "%s/%d", GR_SCT_DISPMODE, id);
if (!curCar)
{
// Load the name of the "current driver", and search it in the race competitors.
carName = GfParmGetStr(grHandle, path, GR_ATT_CUR_DRV, "");
for (i = 0; i < s->_ncars; i++)
{
if (!strcmp(s->cars[i]->_name, carName))
{
break;
}
}
// Found : this is the "current driver".
if (i < s->_ncars)
{
curCar = s->cars[i];
} else if (id < s->_ncars)
{
curCar = s->cars[id];
} else
{
curCar = s->cars[0];
}
GfLogTrace("Screen #%d : Assigned to %s\n", id, curCar->_name);
}
// Load "current camera" settings (attached to the "current car").
sprintf(path2, "%s/%s", GR_SCT_DISPMODE, curCar->_name);
GfOut("Driver Name Camera = %s\n", curCar->_name);
curCamHead = (int)GfParmGetNum(grHandle, path, GR_ATT_CAM_HEAD, NULL, 9);
camNum = (int)GfParmGetNum(grHandle, path, GR_ATT_CAM, NULL, 0);
mirrorFlag = (int)GfParmGetNum(grHandle, path, GR_ATT_MIRROR, NULL, (tdble)mirrorFlag);
curCamHead = (int)GfParmGetNum(grHandle, path2, GR_ATT_CAM_HEAD, NULL, (tdble)curCamHead);
camNum = (int)GfParmGetNum(grHandle, path2, GR_ATT_CAM, NULL, (tdble)camNum);
mirrorFlag = (int)GfParmGetNum(grHandle, path2, GR_ATT_MIRROR, NULL, (tdble)mirrorFlag);
}

View file

@ -0,0 +1,104 @@
/***************************************************************************
file : OsgViewer.h
created : Sat Jan 2013 22:11:19 CEST 2013
copyright : (C) 2013 by Xavier Bertaux
email : bertauxx@yahoo.fr
version : $Id$
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef _OSGVIEWER_H_
#define _OSGVIEWER_H_
#include <raceman.h> //tSituation
#include <car.h> //tCarElt
//#include "grcam.h" //Cameras
//class cGrBoard;
class SDFrameInfo;
class SDViewer
{
protected:
int id;
tCarElt *curCar; // Current car viewed.
tCarElt **cars; // List of cars.
int curCamHead; // The current camera list.
//tGrCamHead cams[10]; // From F2 to F11.
//class cGrPerspCamera *curCam; // The current camera.
//class cGrCarCamMirror *mirrorCam; // The mirror camera.
//class cGrPerspCamera *dispCam; // The display camera.
//class cGrOrthoCamera *boardCam; // The board camera.
//class cGrBackgroundCam *bgCam; // The background camera.
//class cGrBoard *board; // The board.
int drawCurrent; // Should the current car be drawn.
int scrx, scry, scrw, scrh;
float viewOffset;
float viewRatio;
int fakeWidth;
int boardWidth;
bool active; // Is the screen activated.
bool selectNextFlag;
bool selectPrevFlag;
int mirrorFlag;
void loadParams(tSituation *s); // Load from parameters files.
public:
SDViewer();
~SDViewer();
void Init(tSituation *s);
void activate(int x, int y, int w, int h, float v);
inline void deactivate(void) { active = false; }
//inline void setZoom(const long zoom) { curCam->setZoom(zoom); }
//int isInScreen(int x, int y);
void update(tSituation *s, const SDFrameInfo* frameInfo);
void camDraw(tSituation *s);
void updateCurrent(tSituation *s);
//void selectCamera(long cam);
//void selectBoard(const long brd);
//void selectTrackMap();
inline void setCurrentCar(tCarElt *newCurCar) { curCar = newCurCar; }
void initCams(tSituation *s);
//void initBoard(void);
inline void selectNextCar(void) { selectNextFlag = true; }
inline void selectPrevCar(void) { selectPrevFlag = true; }
//void selectNextCar(void) { selectNextFlag = true; }
//void selectPrevCar(void) { selectPrevFlag = true; }
void switchMirror(void);
inline tCarElt *getCurrentCar(void) { return curCar; }
//inline cGrCamera* getCurCamera(void) { return curCam; }
//inline float getViewRatio(void) { return viewRatio; }
//inline int getCurCamHead(void) { return curCamHead; }
//inline bool isActive(void) { return active; }
//inline int getId(void) { return id; }
inline int getScrX (void) { return scrx; }
inline int getScrY (void) { return scry; }
inline int getScrW (void) { return scrw; }
inline int getScrH (void) { return scrh; }
//inline int getBoardWidth(void) { return boardWidth; }
};
#endif //_OSGVIEWER_H_