00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045
00046 #include <OSGConfig.h>
00047
00048 #include <OSGViewport.h>
00049 #include <OSGMaterial.h>
00050 #include <OSGCamera.h>
00051 #include <OSGTileCameraDecorator.h>
00052
00053 #include "OSGPolygonForeground.h"
00054
00055 OSG_USING_NAMESPACE
00056
00057
00058
00059
00060
00074
00075
00076
00077
00078
00079
00080
00081
00082 void PolygonForeground::initMethod (void)
00083 {
00084 }
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 PolygonForeground::PolygonForeground(void) :
00098 Inherited()
00099 {
00100 }
00101
00102 PolygonForeground::PolygonForeground(const PolygonForeground &source) :
00103 Inherited(source)
00104 {
00105 }
00106
00107 PolygonForeground::~PolygonForeground(void)
00108 {
00109 }
00110
00111
00112
00113 void PolygonForeground::changed(BitVector whichField, UInt32 origin)
00114 {
00115 Inherited::changed(whichField, origin);
00116 }
00117
00118 void PolygonForeground::dump( UInt32 ,
00119 const BitVector ) const
00120 {
00121 SLOG << "Dump PolygonForeground NI" << std::endl;
00122 }
00123
00124 Real32 PolygonForeground::mapCoordinate(Real32 val, Real32 max, bool norm)
00125 {
00126 if(val >= 0)
00127 {
00128 if (norm)
00129 val *= max;
00130 }
00131 else
00132 {
00133 val += 1;
00134
00135 if (norm)
00136 val *= max;
00137
00138 val = max + val;
00139 }
00140
00141 return val;
00142 }
00143
00144 void PolygonForeground::draw(DrawActionBase *act, Viewport *port)
00145 {
00146 if(getActive() == false)
00147 return;
00148
00149 if(getPositions().getSize() == 0)
00150 return;
00151
00152 if(port->getPixelWidth() == 0 ||
00153 port->getPixelHeight() == 0 )
00154 return;
00155
00156 if(getPositions().getSize() != getTexCoords().getSize())
00157 {
00158 FWARNING(("PolygonForeground::draw: positions and texcoords have "
00159 "different sizes (%d vs. %d)!\n",
00160 getPositions().getSize(), getTexCoords().getSize()));
00161 return;
00162 }
00163
00164 glPushAttrib(GL_ALL_ATTRIB_BITS);
00165
00166 Real32 aspectX = 1.0f, aspectY = 1.0f;
00167
00168 if (getAspectHeight() && getAspectWidth())
00169 {
00170 aspectX = ((Real32)port->getPixelHeight()/getAspectHeight()) /
00171 ((Real32)port->getPixelWidth() / getAspectWidth());
00172 }
00173
00174 glMatrixMode(GL_MODELVIEW);
00175 glPushMatrix();
00176 glLoadIdentity();
00177
00178 glMatrixMode(GL_PROJECTION);
00179 glPushMatrix();
00180 glLoadIdentity();
00181
00182 Real32 sFac = getScale() > 0 ? getScale() : 1.0f;
00183
00184 UInt32 width = port->getPixelWidth(),
00185 height = port->getPixelHeight();
00186
00187 Camera *cP = act->getCamera();
00188 TileCameraDecorator *cdP = dynamic_cast<TileCameraDecorator*>(cP);
00189
00190 while (cdP != NULL)
00191 {
00192 width = cdP->getFullWidth() ? cdP->getFullWidth() : width;
00193 height = cdP->getFullHeight() ? cdP->getFullHeight() : height;
00194
00195 cP = cdP->getDecoratee().getCPtr();
00196 cdP = dynamic_cast<TileCameraDecorator*>(cP);
00197 }
00198
00199 cP = act->getCamera();
00200 cdP = dynamic_cast<TileCameraDecorator*>(cP);
00201
00202 if (cdP && !getTile())
00203 {
00204 Real32 t = 0,
00205 left = cdP->getLeft(),
00206 right = cdP->getRight(),
00207 top = cdP->getTop(),
00208 bottom = cdP->getBottom();
00209
00210 if (getAspectHeight() && getAspectWidth() &&
00211 height != 0 && width != 0)
00212 {
00213 aspectX = ((Real32)height/getAspectHeight()) /
00214 ((Real32)width / getAspectWidth());
00215 t = (Real32)width * (1 - aspectX) * 0.5f;
00216 t *= (Real32)port->getPixelWidth() / width;
00217 }
00218
00219 Matrix sm;
00220 cP->getDecoration(sm, width, height);
00221
00222 glLoadMatrixf(sm.getValues());
00223 glOrtho(0, port->getPixelWidth(), 0, port->getPixelHeight(), 0, 1);
00224
00225 glTranslatef(t, 0, 0);
00226 glScalef(aspectX, aspectY, 1);
00227
00228 float t1 = (1 - sFac) * 0.5f * (Real32)port->getPixelWidth();
00229 float t2 = (1 - sFac) * 0.5f * (Real32)port->getPixelHeight();
00230 glTranslatef(t1, t2, 0);
00231 glScalef(sFac,sFac,1);
00232 }
00233 else
00234 {
00235 glScalef(sFac,sFac,1);
00236
00237 glScalef(aspectX, aspectY, 1);
00238 glOrtho(0, port->getPixelWidth(), 0, port->getPixelHeight(), 0, 1);
00239 }
00240
00241 getMaterial()->getState()->activate(act);
00242
00243 Vec3f *tc = &getTexCoords()[0];
00244 Pnt2f *pos = &getPositions()[0];
00245
00246 glBegin(GL_POLYGON);
00247
00248 for (UInt16 i = 0; i < getPositions().size(); i++)
00249 {
00250 glTexCoord3fv( tc[i].getValues() );
00251 glVertex2f( mapCoordinate(pos[i][0], Real32(port->getPixelWidth()),
00252 getNormalizedX()),
00253 mapCoordinate(pos[i][1], Real32(port->getPixelHeight()),
00254 getNormalizedY()) );
00255 }
00256
00257 glEnd();
00258
00259 getMaterial()->getState()->deactivate(act);
00260
00261 glScalef(1, 1, 1);
00262
00263 glPopMatrix();
00264 glMatrixMode(GL_MODELVIEW);
00265 glPopMatrix();
00266
00267 glPopAttrib();
00268 }
00269
00270
00271
00272
00273 #ifdef OSG_SGI_CC
00274 #pragma set woff 1174
00275 #endif
00276
00277 #ifdef OSG_LINUX_ICC
00278 #pragma warning( disable : 177 )
00279 #endif
00280
00281 namespace
00282 {
00283 static Char8 cvsid_cpp [] = "@(#)$Id: OSGPolygonForeground.cpp,v 1.5 2007/03/09 16:59:50 yjung Exp $";
00284 static Char8 cvsid_hpp [] = OSGPOLYGONFOREGROUNDBASE_HEADER_CVSID;
00285 static Char8 cvsid_inl [] = OSGPOLYGONFOREGROUNDBASE_INLINE_CVSID;
00286
00287 static Char8 cvsid_fields_hpp[] = OSGPOLYGONFOREGROUNDFIELDS_HEADER_CVSID;
00288 }
00289
00290 #ifdef __sgi
00291 #pragma reset woff 1174
00292 #endif
00293