1
0
Fork 0

Merge branch 'kln89' into next

This commit is contained in:
Dave Luff 2010-11-22 22:44:21 +00:00
commit a39fa6ca1e
31 changed files with 1356 additions and 1299 deletions

View file

@ -7,7 +7,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as
@ -775,10 +775,10 @@ void KLN89::DrawMap(bool draw_avs) {
GPSWaypoint* wp1 = _activeFP->waypoints[i]; GPSWaypoint* wp1 = _activeFP->waypoints[i];
SGVec3d p0 = mapProj.ConvertToLocal(SGGeod::fromRad(wp0->lon, wp0->lat)); SGVec3d p0 = mapProj.ConvertToLocal(SGGeod::fromRad(wp0->lon, wp0->lat));
SGVec3d p1 = mapProj.ConvertToLocal(SGGeod::fromRad(wp1->lon, wp1->lat)); SGVec3d p1 = mapProj.ConvertToLocal(SGGeod::fromRad(wp1->lon, wp1->lat));
int mx0 = int(p0.x() / meter_per_pix) + 56; int mx0 = int(p0.x() / meter_per_pix + 0.5) + 56;
int my0 = int(p0.y() / meter_per_pix) + (_mapOrientation == 0 ? 19 : 10); int my0 = int(p0.y() / meter_per_pix + 0.5) + (_mapOrientation == 0 ? 19 : 10);
int mx1 = int(p1.x() / meter_per_pix) + 56; int mx1 = int(p1.x() / meter_per_pix + 0.5) + 56;
int my1 = int(p1.y() / meter_per_pix) + (_mapOrientation == 0 ? 19 : 10); int my1 = int(p1.y() / meter_per_pix + 0.5) + (_mapOrientation == 0 ? 19 : 10);
if(i == 1) { if(i == 1) {
xvec.push_back(mx0); xvec.push_back(mx0);
yvec.push_back(my0); yvec.push_back(my0);

View file

@ -7,7 +7,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as
@ -251,15 +251,24 @@ void KLN89NavPage::Update(double dt) {
_kln89->DrawText("-:--", 2, 11, 0); _kln89->DrawText("-:--", 2, 11, 0);
} }
} else { // if(3 == _subPage) } else { // if(3 == _subPage)
//
// Switch the cursor off if scan-pull is out on this page. // Switch the cursor off if scan-pull is out on this page.
//
if(fgGetBool("/instrumentation/kln89/scan-pull")) { _kln89->_mode = KLN89_MODE_DISP; } if(fgGetBool("/instrumentation/kln89/scan-pull")) { _kln89->_mode = KLN89_MODE_DISP; }
// The moving map page the core KLN89 class draws this.
//
// Draw the moving map if valid.
// We call the core KLN89 class to do this.
//
if(_kln89->_mapOrientation == 2 && _kln89->_groundSpeed_kts < 2) { if(_kln89->_mapOrientation == 2 && _kln89->_groundSpeed_kts < 2) {
// Don't draw it if in track up mode and groundspeed < 2kts, as per real-life unit. // Don't draw it if in track up mode and groundspeed < 2kts, as per real-life unit.
} else { } else {
_kln89->DrawMap(!_suspendAVS); _kln89->DrawMap(!_suspendAVS);
} }
// Now draw any annotation over it.
//
// Now that the map has been drawn, add the annotation (scale, etc).
//
int scale = KLN89MapScales[_kln89->_mapScaleUnits][_kln89->_mapScaleIndex]; int scale = KLN89MapScales[_kln89->_mapScaleUnits][_kln89->_mapScaleIndex];
string scle_str = GPSitoa(scale); string scle_str = GPSitoa(scale);
if(crsr) { if(crsr) {
@ -325,7 +334,10 @@ void KLN89NavPage::Update(double dt) {
} }
} }
} }
// And do part of the field 1 update, since NAV 4 is a special case for the last line.
//
// Do part of the field 1 update, since NAV 4 is a special case for the last line.
//
_kln89->DrawChar('>', 1, 0, 0); _kln89->DrawChar('>', 1, 0, 0);
if(crsr && _uLinePos == 1) _kln89->Underline(1, 1, 0, 5); if(crsr && _uLinePos == 1) _kln89->Underline(1, 1, 0, 5);
if(!(crsr && _uLinePos == 1 && _kln89->_blink)) { if(!(crsr && _uLinePos == 1 && _kln89->_blink)) {

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as

View file

@ -232,7 +232,7 @@ DCLGPS::~DCLGPS() {
} }
void DCLGPS::draw(osg::State& state) { void DCLGPS::draw(osg::State& state) {
_instrument->draw(state); _instrument->Draw(state);
} }
void DCLGPS::init() { void DCLGPS::init() {

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as
@ -29,313 +29,361 @@
#include "render_area_2d.hxx" #include "render_area_2d.hxx"
RA2DPrimitive::RA2DPrimitive() { RA2DPrimitive::RA2DPrimitive() {
invert = false; invert = false;
debug = false; debug = false;
} }
RenderArea2D::RenderArea2D(int logx, int logy, int sizex, int sizey, int posx, int posy) { RenderArea2D::RenderArea2D(int logx, int logy, int sizex, int sizey, int posx, int posy) {
_logx = logx; _logx = logx;
_logy = logy; _logy = logy;
_sizex = sizex; _sizex = sizex;
_sizey = sizey; _sizey = sizey;
_posx = posx; _posx = posx;
_posy = posy; _posy = posy;
_clipx1 = 0; _clipx1 = 0;
_clipx2 = _logx - 1; _clipx2 = _logx - 1;
_clipy1 = 0; _clipy1 = 0;
_clipy2 = _logy - 1; _clipy2 = _logy - 1;
_backgroundColor[0] = 0.0; _backgroundColor[0] = 0.0;
_backgroundColor[1] = 0.0; _backgroundColor[1] = 0.0;
_backgroundColor[2] = 0.0; _backgroundColor[2] = 0.0;
_backgroundColor[3] = 1.0; _backgroundColor[3] = 1.0;
_pixelColor[0] = 1.0; _pixelColor[0] = 1.0;
_pixelColor[1] = 0.0; _pixelColor[1] = 0.0;
_pixelColor[2] = 0.0; _pixelColor[2] = 0.0;
_pixelColor[3] = 1.0; _pixelColor[3] = 1.0;
_ra2d_debug = false; _ra2d_debug = false;
} }
void RenderArea2D::draw(osg::State& state) { void RenderArea2D::Draw(osg::State& state) {
static osg::ref_ptr<osg::StateSet> renderArea2DStateSet; static osg::ref_ptr<osg::StateSet> renderArea2DStateSet;
if(!renderArea2DStateSet.valid()) { if(!renderArea2DStateSet.valid()) {
renderArea2DStateSet = new osg::StateSet; renderArea2DStateSet = new osg::StateSet;
renderArea2DStateSet->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::OFF); renderArea2DStateSet->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::OFF);
renderArea2DStateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); renderArea2DStateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
} }
state.pushStateSet(renderArea2DStateSet.get()); state.pushStateSet(renderArea2DStateSet.get());
state.apply(); state.apply();
state.setActiveTextureUnit(0); state.setActiveTextureUnit(0);
state.setClientActiveTextureUnit(0); state.setClientActiveTextureUnit(0);
// DCL - the 2 lines below are copied verbatim from the hotspot drawing code. // DCL - the 2 lines below are copied verbatim from the hotspot drawing code.
// I am not sure if they are needed here or not. // I am not sure if they are needed here or not.
glPushAttrib(GL_ENABLE_BIT); glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_COLOR_MATERIAL); glDisable(GL_COLOR_MATERIAL);
// FIXME - disabling all clip planes causes bleed-through through the splash screen. // FIXME - disabling all clip planes causes bleed-through through the splash screen.
glDisable(GL_CLIP_PLANE0); glDisable(GL_CLIP_PLANE0);
glDisable(GL_CLIP_PLANE1); glDisable(GL_CLIP_PLANE1);
glDisable(GL_CLIP_PLANE2); glDisable(GL_CLIP_PLANE2);
glDisable(GL_CLIP_PLANE3); glDisable(GL_CLIP_PLANE3);
oldDrawBackground(); DoDrawBackground();
for(unsigned int i = 0; i < drawing_list.size(); ++i) { for(unsigned int i = 0; i < drawing_list.size(); ++i) {
RA2DPrimitive prim = drawing_list[i]; RA2DPrimitive prim = drawing_list[i];
switch(prim.type) { switch(prim.type) {
case RA2D_LINE: case RA2D_LINE:
oldDrawLine(prim.x1, prim.y1, prim.x2, prim.y2); DoDrawLine(prim.x1, prim.y1, prim.x2, prim.y2);
break; break;
case RA2D_QUAD: case RA2D_QUAD:
if(prim.debug) { if(prim.debug) {
//cout << "Clipping = " << _clipx1 << ", " << _clipy1 << " to " << _clipx2 << ", " << _clipy2 << '\n'; //cout << "Clipping = " << _clipx1 << ", " << _clipy1 << " to " << _clipx2 << ", " << _clipy2 << '\n';
//cout << "Drawing quad " << prim.x1 << ", " << prim.y1 << " to " << prim.x2 << ", " << prim.y2 << '\n'; //cout << "Drawing quad " << prim.x1 << ", " << prim.y1 << " to " << prim.x2 << ", " << prim.y2 << '\n';
} }
oldDrawQuad(prim.x1, prim.y1, prim.x2, prim.y2, prim.invert); DoDrawQuad(prim.x1, prim.y1, prim.x2, prim.y2, prim.invert);
break; break;
case RA2D_PIXEL: case RA2D_PIXEL:
oldDrawPixel(prim.x1, prim.y1, prim.invert); DoDrawPixel(prim.x1, prim.y1, prim.invert);
break; break;
} }
} }
glPopAttrib(); drawing_list.clear();
state.popStateSet(); glPopAttrib();
state.apply();
state.setActiveTextureUnit(0); state.popStateSet();
state.setClientActiveTextureUnit(0); state.apply();
state.setActiveTextureUnit(0);
state.setClientActiveTextureUnit(0);
}
void RenderArea2D::Flush() {
drawing_list.clear();
} }
// Set clipping region in logical units // Set clipping region in logical units
void RenderArea2D::SetClipRegion(int x1, int y1, int x2, int y2) { void RenderArea2D::SetClipRegion(int x1, int y1, int x2, int y2) {
_clipx1 = x1; _clipx1 = x1;
_clipx2 = x2; _clipx2 = x2;
_clipy1 = y1; _clipy1 = y1;
_clipy2 = y2; _clipy2 = y2;
//cout << "Set clip region, clip region = " << _clipx1 << ", " << _clipy1 << " to " << _clipx2 << ", " << _clipy2 << '\n'; //cout << "Set clip region, clip region = " << _clipx1 << ", " << _clipy1 << " to " << _clipx2 << ", " << _clipy2 << '\n';
} }
// Set clip region to be the same as the rendered area (default) // Set clip region to be the same as the rendered area (default)
void RenderArea2D::ResetClipRegion() { void RenderArea2D::ResetClipRegion() {
_clipx1 = 0; _clipx1 = 0;
_clipx2 = _logx - 1; _clipx2 = _logx - 1;
_clipy1 = 0; _clipy1 = 0;
_clipy2 = _logy - 1; _clipy2 = _logy - 1;
//cout << "Reset clip region, clip region = " << _clipx1 << ", " << _clipy1 << " to " << _clipx2 << ", " << _clipy2 << '\n'; //cout << "Reset clip region, clip region = " << _clipx1 << ", " << _clipy1 << " to " << _clipx2 << ", " << _clipy2 << '\n';
} }
void RenderArea2D::SetPosition(int posx, int posy) { void RenderArea2D::SetPosition(int posx, int posy) {
_posx = posx; _posx = posx;
_posy = posy; _posy = posy;
} }
void RenderArea2D::SetLogicalSize(int logx, int logy) { void RenderArea2D::SetLogicalSize(int logx, int logy) {
_logx = logx; _logx = logx;
_logy = logy; _logy = logy;
} }
void RenderArea2D::SetActualSize(int sizex, int sizey) { void RenderArea2D::SetActualSize(int sizex, int sizey) {
_sizex = sizex; _sizex = sizex;
_sizey = sizey; _sizey = sizey;
} }
void RenderArea2D::DrawPixel(int x, int y, bool invert) { void RenderArea2D::DrawPixel(int x, int y, bool invert) {
// Clipping is currently performed in oldDrawPixel - could clip here instead though. // Clip
if(x < _clipx1 || x > _clipx2 || y < _clipy1 || y > _clipy2) return;
RA2DPrimitive prim; RA2DPrimitive prim;
prim.x1 = x; prim.x1 = x;
prim.y1 = y; prim.y1 = y;
prim.x2 = 0; prim.x2 = 0;
prim.y2 = 0; prim.y2 = 0;
prim.type = RA2D_PIXEL; prim.type = RA2D_PIXEL;
prim.invert = invert; prim.invert = invert;
drawing_list.push_back(prim); drawing_list.push_back(prim);
} }
void RenderArea2D::oldDrawPixel(int x, int y, bool invert) { void RenderArea2D::DoDrawPixel(int x, int y, bool invert) {
// Clip // Clip. In theory this shouldn't be necessary, since all input is clipped before adding
if(x < _clipx1 || x > _clipx2 || y < _clipy1 || y > _clipy2) return; // to the drawing list, but it ensures that any errors in clipping lines etc will only
// spill over the clip area within the instrument, and still be clipped from straying
// Scale to position within background // outside the instrument.
float fx1 = (float)x, fy1 = (float)y; if(x < _clipx1 || x > _clipx2 || y < _clipy1 || y > _clipy2) return;
float rx = (float)_sizex / (float)_logx;
float ry = (float)_sizey / (float)_logy; // Scale to position within background
fx1 *= rx; float fx1 = (float)x, fy1 = (float)y;
fy1 *= ry; float rx = (float)_sizex / (float)_logx;
float fx2 = fx1 + rx; float ry = (float)_sizey / (float)_logy;
float fy2 = fy1 + ry; fx1 *= rx;
fy1 *= ry;
// Translate to final position float fx2 = fx1 + rx;
fx1 += (float)_posx; float fy2 = fy1 + ry;
fx2 += (float)_posx;
fy1 += (float)_posy; // Translate to final position
fy2 += (float)_posy; fx1 += (float)_posx;
fx2 += (float)_posx;
//cout << "DP: " << fx1 << ", " << fy1 << " ... " << fx2 << ", " << fy2 << '\n'; fy1 += (float)_posy;
fy2 += (float)_posy;
doSetColor(invert ? _backgroundColor : _pixelColor);
SGVec2f corners[4] = { //cout << "DP: " << fx1 << ", " << fy1 << " ... " << fx2 << ", " << fy2 << '\n';
SGVec2f(fx1, fy1),
SGVec2f(fx2, fy1), SetRenderColor(invert ? _backgroundColor : _pixelColor);
SGVec2f(fx2, fy2), SGVec2f corners[4] = {
SGVec2f(fx1, fy2) SGVec2f(fx1, fy1),
}; SGVec2f(fx2, fy1),
doDrawQuad(corners); SGVec2f(fx2, fy2),
SGVec2f(fx1, fy2)
};
RenderQuad(corners);
} }
void RenderArea2D::DrawLine(int x1, int y1, int x2, int y2) { void RenderArea2D::DrawLine(int x1, int y1, int x2, int y2) {
RA2DPrimitive prim; // We need to clip the line to the current region before storing it in the drawing
prim.x1 = x1; // list, since when we come to actually draw it the clip region may have changed.
prim.y1 = y1;
prim.x2 = x2; // Liang-Barsky clipping algorithm
prim.y2 = y2; int p[4], q[4];
prim.type = RA2D_LINE; float u1 = 0.0f, u2 = 1.0f;
prim.invert = false; p[0] = -(x2 - x1); q[0] = (x1 - _clipx1);
drawing_list.push_back(prim); p[1] = (x2 - x1); q[1] = (_clipx2 - x1);
p[2] = -(y2 - y1); q[2] = (y1 - _clipy1);
p[3] = (y2 - y1); q[3] = (_clipy2 - y1);
for(int i=0; i<4; ++i) {
if(p[i] == 0) {
if(q[i] < 0) {
// Then we have a trivial rejection of a line parallel to a clip plane
// completely outside the clip region.
return;
}
} else if(p[i] < 0) {
float r = (float)q[i]/(float)p[i];
u1 = (u1 > r ? u1 : r);
} else { // p[i] > 0
float r = (float)q[i]/(float)p[i];
u2 = (u2 < r ? u2 : r);
}
if(u1 > u2) {
// Then the line is completely outside the clip area.
return;
}
}
float fx1 = x1 + u1 * (float)(x2 - x1);
float fy1 = y1 + u1 * (float)(y2 - y1);
float fx2 = x1 + u2 * (float)(x2 - x1);
float fy2 = y1 + u2 * (float)(y2 - y1);
x1 = (int)(fx1 + 0.5);
y1 = (int)(fy1 + 0.5);
x2 = (int)(fx2 + 0.5);
y2 = (int)(fy2 + 0.5);
RA2DPrimitive prim;
prim.x1 = x1;
prim.y1 = y1;
prim.x2 = x2;
prim.y2 = y2;
prim.type = RA2D_LINE;
prim.invert = false;
drawing_list.push_back(prim);
} }
void RenderArea2D::oldDrawLine(int x1, int y1, int x2, int y2) { void RenderArea2D::DoDrawLine(int x1, int y1, int x2, int y2) {
// Crude implementation of Bresenham line drawing algorithm. // Crude implementation of Bresenham line drawing algorithm.
// Our lines are non directional, so first order the points x-direction-wise to leave only 4 octants to consider. // Our lines are non directional, so first order the points x-direction-wise to leave only 4 octants to consider.
if(x2 < x1) { if(x2 < x1) {
int tmp_x = x1; int tmp_x = x1;
int tmp_y = y1; int tmp_y = y1;
x1 = x2; x1 = x2;
y1 = y2; y1 = y2;
x2 = tmp_x; x2 = tmp_x;
y2 = tmp_y; y2 = tmp_y;
} }
bool flip_y = (y1 > y2 ? true : false); bool flip_y = (y1 > y2 ? true : false);
int dx = x2 - x1; int dx = x2 - x1;
int dy = (flip_y ? y1 - y2 : y2 - y1); int dy = (flip_y ? y1 - y2 : y2 - y1);
if(dx > dy) { if(dx > dy) {
// push the x dir // push the x dir
int y = y1; int y = y1;
int yn = dx/2; int yn = dx/2;
for(int x=x1; x<=x2; ++x) { for(int x=x1; x<=x2; ++x) {
DrawPixel(x, y); DoDrawPixel(x, y);
yn += dy; yn += dy;
if(yn >= dx) { if(yn >= dx) {
yn -= dx; yn -= dx;
y = (flip_y ? y - 1 : y + 1); y = (flip_y ? y - 1 : y + 1);
} }
} }
} else { } else {
// push the y dir // push the y dir
int x = x1; int x = x1;
int xn = dy/2; int xn = dy/2;
// Must be a more elegant way to roll the next two cases into one! // Must be a more elegant way to roll the next two cases into one!
if(flip_y) { if(flip_y) {
for(int y=y1; y>=y2; --y) { for(int y=y1; y>=y2; --y) {
DrawPixel(x, y); DoDrawPixel(x, y);
xn += dx; xn += dx;
if(xn >= dy) { if(xn >= dy) {
xn -= dy; xn -= dy;
x++; x++;
} }
} }
} else { } else {
for(int y=y1; y<=y2; ++y) { for(int y=y1; y<=y2; ++y) {
DrawPixel(x, y); DoDrawPixel(x, y);
xn += dx; xn += dx;
if(xn >= dy) { if(xn >= dy) {
xn -= dy; xn -= dy;
x++; x++;
} }
} }
} }
} }
} }
void RenderArea2D::DrawQuad(int x1, int y1, int x2, int y2, bool invert) { void RenderArea2D::DrawQuad(int x1, int y1, int x2, int y2, bool invert) {
// Clip and sanity-check. // Force the input to be ordered with x1 < x2 and y1 < y2.
if(x1 > x2) { if(x1 > x2) {
int x = x2; int x = x2;
x2 = x1; x2 = x1;
x1 = x; x1 = x;
} }
if(y1 > y2) { if(y1 > y2) {
int y = y2; int y = y2;
y2 = y1; y2 = y1;
y1 = y; y1 = y;
} }
x1 = x1 < _clipx1 ? _clipx1 : x1;
if(x1 > _clipx2) { return; } // Clip the input to the current drawing region.
x2 = x2 > _clipx2 ? _clipx2 : x2; x1 = x1 < _clipx1 ? _clipx1 : x1;
if(x2 < _clipx1) { return; } if(x1 > _clipx2) { return; }
y1 = y1 < _clipy1 ? _clipy1 : y1; x2 = x2 > _clipx2 ? _clipx2 : x2;
if(y1 > _clipy2) { return; } if(x2 < _clipx1) { return; }
y2 = y2 > _clipy2 ? _clipy2 : y2; y1 = y1 < _clipy1 ? _clipy1 : y1;
if(y2 < _clipy1) { return; } if(y1 > _clipy2) { return; }
y2 = y2 > _clipy2 ? _clipy2 : y2;
RA2DPrimitive prim; if(y2 < _clipy1) { return; }
prim.x1 = x1;
prim.y1 = y1; RA2DPrimitive prim;
prim.x2 = x2; prim.x1 = x1;
prim.y2 = y2; prim.y1 = y1;
prim.type = RA2D_QUAD; prim.x2 = x2;
prim.invert = invert; prim.y2 = y2;
if(_ra2d_debug) prim.debug = true; prim.type = RA2D_QUAD;
drawing_list.push_back(prim); prim.invert = invert;
if(_ra2d_debug) prim.debug = true;
drawing_list.push_back(prim);
} }
void RenderArea2D::oldDrawQuad(int x1, int y1, int x2, int y2, bool invert) { void RenderArea2D::DoDrawQuad(int x1, int y1, int x2, int y2, bool invert) {
// Scale to position within background // Scale to position within background
float fx1 = (float)x1, fy1 = (float)y1; float fx1 = (float)x1, fy1 = (float)y1;
float fx2 = (float)x2, fy2 = (float)y2; float fx2 = (float)x2, fy2 = (float)y2;
float rx = (float)_sizex / (float)_logx; float rx = (float)_sizex / (float)_logx;
float ry = (float)_sizey / (float)_logy; float ry = (float)_sizey / (float)_logy;
fx1 *= rx; fx1 *= rx;
fy1 *= ry; fy1 *= ry;
fx2 *= rx; fx2 *= rx;
fy2 *= ry; fy2 *= ry;
fx2 += rx; fx2 += rx;
fy2 += ry; fy2 += ry;
// Translate to final position // Translate to final position
fx1 += (float)_posx; fx1 += (float)_posx;
fx2 += (float)_posx; fx2 += (float)_posx;
fy1 += (float)_posy; fy1 += (float)_posy;
fy2 += (float)_posy; fy2 += (float)_posy;
//cout << "DP: " << fx1 << ", " << fy1 << " ... " << fx2 << ", " << fy2 << '\n'; //cout << "DP: " << fx1 << ", " << fy1 << " ... " << fx2 << ", " << fy2 << '\n';
doSetColor(invert ? _backgroundColor : _pixelColor); SetRenderColor(invert ? _backgroundColor : _pixelColor);
SGVec2f corners[4] = { SGVec2f corners[4] = {
SGVec2f(fx1, fy1), SGVec2f(fx1, fy1),
SGVec2f(fx2, fy1), SGVec2f(fx2, fy1),
SGVec2f(fx2, fy2), SGVec2f(fx2, fy2),
SGVec2f(fx1, fy2) SGVec2f(fx1, fy2)
}; };
doDrawQuad(corners); RenderQuad(corners);
} }
void RenderArea2D::DrawBackground() { void RenderArea2D::DrawBackground() {
// TODO // Currently a NO-OP
} }
void RenderArea2D::oldDrawBackground() { void RenderArea2D::DoDrawBackground() {
doSetColor(_backgroundColor); SetRenderColor(_backgroundColor);
SGVec2f corners[4] = { SGVec2f corners[4] = {
SGVec2f(_posx, _posy), SGVec2f(_posx, _posy),
SGVec2f(_posx + _sizex, _posy), SGVec2f(_posx + _sizex, _posy),
SGVec2f(_posx + _sizex, _posy + _sizey), SGVec2f(_posx + _sizex, _posy + _sizey),
SGVec2f(_posx, _posy + _sizey) SGVec2f(_posx, _posy + _sizey)
}; };
doDrawQuad(corners); RenderQuad(corners);
}
void RenderArea2D::Flush() {
drawing_list.clear();
} }
// ----------------------------------------- // -----------------------------------------
@ -344,28 +392,27 @@ void RenderArea2D::Flush() {
// //
// ----------------------------------------- // -----------------------------------------
void RenderArea2D::doSetColor( const float *rgba ) { void RenderArea2D::SetRenderColor( const float *rgba ) {
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, rgba); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, rgba);
glColor4fv( rgba ); glColor4fv( rgba );
} }
void RenderArea2D::doDrawQuad( const SGVec2f *p) { void RenderArea2D::RenderQuad( const SGVec2f *p) {
glBegin(GL_QUADS); glBegin(GL_QUADS);
glNormal3f(0.0f, 0.0f, 0.0f); glNormal3f(0.0f, 0.0f, 0.0f);
glVertex2fv( p[0].data() ); glVertex2fv( p[0].data() );
glVertex2fv( p[1].data() ); glVertex2fv( p[1].data() );
glVertex2fv( p[2].data() ); glVertex2fv( p[2].data() );
glVertex2fv( p[3].data() ); glVertex2fv( p[3].data() );
glEnd(); glEnd();
} }
void RenderArea2D::doDrawQuad( const SGVec2f *p, const SGVec4f *color ) { void RenderArea2D::RenderQuad( const SGVec2f *p, const SGVec4f *color ) {
glBegin(GL_QUADS);
glBegin(GL_QUADS); glNormal3f(0.0f, 0.0f, 0.0f);
glNormal3f(0.0f, 0.0f, 0.0f); glColor4fv( color[0].data() ); glVertex2fv( p[0].data() );
glColor4fv( color[0].data() ); glVertex2fv( p[0].data() ); glColor4fv( color[1].data() ); glVertex2fv( p[1].data() );
glColor4fv( color[1].data() ); glVertex2fv( p[1].data() ); glColor4fv( color[2].data() ); glVertex2fv( p[2].data() );
glColor4fv( color[2].data() ); glVertex2fv( p[2].data() ); glColor4fv( color[3].data() ); glVertex2fv( p[3].data() );
glColor4fv( color[3].data() ); glVertex2fv( p[3].data() ); glEnd();
glEnd();
} }

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // Written by David Luff, started 2005.
// //
// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as
@ -60,8 +60,6 @@ public:
RenderArea2D(int logx, int logy, int sizex, int sizey, int posx, int posy); RenderArea2D(int logx, int logy, int sizex, int sizey, int posx, int posy);
~RenderArea2D(); ~RenderArea2D();
void draw(osg::State& state);
void SetPixelColor(const float* rgba); void SetPixelColor(const float* rgba);
void SetBackgroundColor(const float* rgba); void SetBackgroundColor(const float* rgba);
void SetPosition(int posx, int posy); void SetPosition(int posx, int posy);
@ -73,23 +71,17 @@ public:
// Set clip region to be the same as the rendered area (default) // Set clip region to be the same as the rendered area (default)
void ResetClipRegion(); void ResetClipRegion();
// Drawing specified in logical units // The DrawXXX functions place the shapes in the buffer, specified
// in logical units, and clipped to the current clip region.
void DrawPixel(int x, int y, bool invert = false);
void DrawLine(int x1, int y1, int x2, int y2); void DrawLine(int x1, int y1, int x2, int y2);
void DrawQuad(int x1, int y1, int x2, int y2, bool invert = false); void DrawQuad(int x1, int y1, int x2, int y2, bool invert = false);
void DrawBackground(); void DrawBackground();
// Draw a pixel specified by *logical* position
void DrawPixel(int x, int y, bool invert = false);
// The old drawing functions have been renamed in order to buffer the drawing for FG // Call Draw to have the buffer contents drawn and then cleared.
// void Draw(osg::State& state);
// Drawing specified in logical units
void oldDrawLine(int x1, int y1, int x2, int y2);
void oldDrawQuad(int x1, int y1, int x2, int y2, bool invert = false);
void oldDrawBackground();
// Draw a pixel specified by *logical* position
void oldDrawPixel(int x, int y, bool invert = false);
// Flush the buffer pipeline // Clear the buffer contents
void Flush(); void Flush();
// Turn debugging on or off. // Turn debugging on or off.
@ -104,10 +96,16 @@ private:
float _backgroundColor[4]; float _backgroundColor[4];
float _pixelColor[4]; float _pixelColor[4];
// Actual drawing routines copied from Atlas // Drawing specified in logical units
void doSetColor( const float *rgb ); void DoDrawPixel(int x, int y, bool invert = false);
void doDrawQuad( const SGVec2f *p); void DoDrawLine(int x1, int y1, int x2, int y2);
void doDrawQuad( const SGVec2f *p, const SGVec4f *color ); void DoDrawQuad(int x1, int y1, int x2, int y2, bool invert = false);
void DoDrawBackground();
// Actual rendering routines copied from Atlas
void SetRenderColor( const float *rgb );
void RenderQuad( const SGVec2f *p);
void RenderQuad( const SGVec2f *p, const SGVec4f *color );
vector<RA2DPrimitive> drawing_list; vector<RA2DPrimitive> drawing_list;