llglsandbox.cpp

Go to the documentation of this file.
00001 
00037 #include "llviewerprecompiledheaders.h"
00038 
00039 #include "llviewercontrol.h"
00040 
00041 #include "llgl.h"
00042 #include "llglimmediate.h"
00043 #include "llglheaders.h"
00044 #include "llparcel.h"
00045 #include "llui.h"
00046 
00047 #include "lldrawable.h"
00048 #include "lltextureentry.h"
00049 #include "llviewercamera.h"
00050 
00051 #include "llvoavatar.h"
00052 #include "llagent.h"
00053 #include "lltoolmgr.h"
00054 #include "llselectmgr.h"
00055 #include "llhudmanager.h"
00056 #include "llrendersphere.h"
00057 #include "llviewerobjectlist.h"
00058 #include "lltoolselectrect.h"
00059 #include "llviewerwindow.h"
00060 #include "llcompass.h"
00061 #include "llsurface.h"
00062 #include "llwind.h"
00063 #include "llworld.h"
00064 #include "llviewerparcelmgr.h"
00065 #include "llviewerregion.h"
00066 #include "llpreviewtexture.h"
00067 #include "llresmgr.h"
00068 #include "pipeline.h"
00069 #include "llspatialpartition.h"
00070  
00071 BOOL LLAgent::setLookAt(ELookAtType target_type, LLViewerObject *object, LLVector3 position)
00072 {
00073         if(object && object->isAttachment())
00074         {
00075                 LLViewerObject* parent = object;
00076                 while(parent)
00077                 {
00078                         if (parent == mAvatarObject)
00079                         {
00080                                 // looking at an attachment on ourselves, which we don't want to do
00081                                 object = mAvatarObject;
00082                                 position.clearVec();
00083                         }
00084                         parent = (LLViewerObject*)parent->getParent();
00085                 }
00086         }
00087         if(!mLookAt || mLookAt->isDead())
00088         {
00089                 mLookAt = (LLHUDEffectLookAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_LOOKAT);
00090                 mLookAt->setSourceObject(mAvatarObject);
00091         }
00092 
00093         return mLookAt->setLookAt(target_type, object, position);
00094 }
00095 
00096 BOOL LLAgent::setPointAt(EPointAtType target_type, LLViewerObject *object, LLVector3 position)
00097 {
00098         // disallow pointing at attachments and avatars
00099         if (object && (object->isAttachment() || object->isAvatar()))
00100         {
00101                 return FALSE;
00102         }
00103 
00104         if(!mPointAt || mPointAt->isDead())
00105         {
00106                 mPointAt = (LLHUDEffectPointAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINTAT);
00107                 mPointAt->setSourceObject(mAvatarObject);
00108         }
00109 
00110         return mPointAt->setPointAt(target_type, object, position);
00111 }
00112 
00113 ELookAtType LLAgent::getLookAtType()
00114 { 
00115         if (mLookAt) 
00116         {
00117                 return mLookAt->getLookAtType();
00118         }
00119 
00120         return LOOKAT_TARGET_NONE;
00121 }
00122 
00123 EPointAtType LLAgent::getPointAtType()
00124 { 
00125         if (mPointAt) 
00126         {
00127                 return mPointAt->getPointAtType();
00128         }
00129 
00130         return POINTAT_TARGET_NONE;
00131 }
00132 
00133 // Draw a representation of current autopilot target
00134 void LLAgent::renderAutoPilotTarget()
00135 {
00136         if (mAutoPilot)
00137         {
00138                 F32 height_meters;
00139                 LLVector3d target_global;
00140 
00141                 glMatrixMode(GL_MODELVIEW);
00142                 gGL.pushMatrix();
00143 
00144                 // not textured
00145                 LLGLSNoTexture no_texture;
00146 
00147                 // lovely green
00148                 glColor4f(0.f, 1.f, 1.f, 1.f);
00149 
00150                 target_global = mAutoPilotTargetGlobal;
00151 
00152                 gGL.translatef((F32)(target_global.mdV[VX]), (F32)(target_global.mdV[VY]), (F32)(target_global.mdV[VZ]));
00153 
00154                 height_meters = 1.f;
00155 
00156                 glScalef(height_meters, height_meters, height_meters);
00157 
00158                 gSphere.render(1500.f);
00159 
00160                 gGL.popMatrix();
00161         }
00162 }
00163 
00164 extern BOOL gDebugSelect;
00165 
00166 // Returns true if you got at least one object
00167 void LLToolSelectRect::handleRectangleSelection(S32 x, S32 y, MASK mask)
00168 {
00169         LLVector3 av_pos = gAgent.getPositionAgent();
00170         F32 select_dist_squared = gSavedSettings.getF32("MaxSelectDistance");
00171         select_dist_squared = select_dist_squared * select_dist_squared;
00172 
00173         BOOL deselect = (mask == MASK_CONTROL);
00174         S32 left =      llmin(x, mDragStartX);
00175         S32 right =     llmax(x, mDragStartX);
00176         S32 top =       llmax(y, mDragStartY);
00177         S32 bottom =llmin(y, mDragStartY);
00178 
00179         left = llround((F32) left * LLUI::sGLScaleFactor.mV[VX]);
00180         right = llround((F32) right * LLUI::sGLScaleFactor.mV[VX]);
00181         top = llround((F32) top * LLUI::sGLScaleFactor.mV[VY]);
00182         bottom = llround((F32) bottom * LLUI::sGLScaleFactor.mV[VY]);
00183 
00184         F32 old_far_plane = LLViewerCamera::getInstance()->getFar();
00185         F32 old_near_plane = LLViewerCamera::getInstance()->getNear();
00186 
00187         S32 width = right - left + 1;
00188         S32 height = top - bottom + 1;
00189 
00190         BOOL grow_selection = FALSE;
00191         BOOL shrink_selection = FALSE;
00192 
00193         if (height > mDragLastHeight || width > mDragLastWidth)
00194         {
00195                 grow_selection = TRUE;
00196         }
00197         if (height < mDragLastHeight || width < mDragLastWidth)
00198         {
00199                 shrink_selection = TRUE;
00200         }
00201 
00202         if (!grow_selection && !shrink_selection)
00203         {
00204                 // nothing to do
00205                 return;
00206         }
00207 
00208         mDragLastHeight = height;
00209         mDragLastWidth = width;
00210 
00211         S32 center_x = (left + right) / 2;
00212         S32 center_y = (top + bottom) / 2;
00213 
00214         // save drawing mode
00215         glMatrixMode(GL_PROJECTION);
00216         gGL.pushMatrix();
00217 
00218         BOOL limit_select_distance = gSavedSettings.getBOOL("LimitSelectDistance");
00219         if (limit_select_distance)
00220         {
00221                 // ...select distance from control
00222                 LLVector3 relative_av_pos = av_pos;
00223                 relative_av_pos -= LLViewerCamera::getInstance()->getOrigin();
00224 
00225                 F32 new_far = relative_av_pos * LLViewerCamera::getInstance()->getAtAxis() + gSavedSettings.getF32("MaxSelectDistance");
00226                 F32 new_near = relative_av_pos * LLViewerCamera::getInstance()->getAtAxis() - gSavedSettings.getF32("MaxSelectDistance");
00227 
00228                 new_near = llmax(new_near, 0.1f);
00229 
00230                 LLViewerCamera::getInstance()->setFar(new_far);
00231                 LLViewerCamera::getInstance()->setNear(new_near);
00232         }
00233         LLViewerCamera::getInstance()->setPerspective(FOR_SELECTION, 
00234                                                         center_x-width/2, center_y-height/2, width, height, 
00235                                                         limit_select_distance);
00236 
00237         if (shrink_selection)
00238         {
00239                 struct f : public LLSelectedObjectFunctor
00240                 {
00241                         virtual bool apply(LLViewerObject* vobjp)
00242                         {
00243                                 LLDrawable* drawable = vobjp->mDrawable;
00244                                 if (!drawable || vobjp->getPCode() != LL_PCODE_VOLUME || vobjp->isAttachment())
00245                                 {
00246                                         return true;
00247                                 }
00248                                 S32 result = LLViewerCamera::getInstance()->sphereInFrustum(drawable->getPositionAgent(), drawable->getRadius());
00249                                 switch (result)
00250                                 {
00251                                   case 0:
00252                                         LLSelectMgr::getInstance()->unhighlightObjectOnly(vobjp);
00253                                         break;
00254                                   case 1:
00255                                         // check vertices
00256                                         if (!LLViewerCamera::getInstance()->areVertsVisible(vobjp, LLSelectMgr::sRectSelectInclusive))
00257                                         {
00258                                                 LLSelectMgr::getInstance()->unhighlightObjectOnly(vobjp);
00259                                         }
00260                                         break;
00261                                   default:
00262                                         break;
00263                                 }
00264                                 return true;
00265                         }
00266                 } func;
00267                 LLSelectMgr::getInstance()->getHighlightedObjects()->applyToObjects(&func);
00268         }
00269 
00270         if (grow_selection)
00271         {
00272                 std::vector<LLDrawable*> potentials;
00273                                 
00274                 for (LLWorld::region_list_t::iterator iter = LLWorld::getInstance()->getRegionList().begin(); 
00275                         iter != LLWorld::getInstance()->getRegionList().end(); ++iter)
00276                 {
00277                         LLViewerRegion* region = *iter;
00278                         for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++)
00279                         {
00280                                 LLSpatialPartition* part = region->getSpatialPartition(i);
00281                                 if (part)
00282                                 {       
00283                                         part->cull(*LLViewerCamera::getInstance(), &potentials, TRUE);
00284                                 }
00285                         }
00286                 }
00287                 
00288                 for (std::vector<LLDrawable*>::iterator iter = potentials.begin();
00289                          iter != potentials.end(); iter++)
00290                 {
00291                         LLDrawable* drawable = *iter;
00292                         LLViewerObject* vobjp = drawable->getVObj();
00293 
00294                         if (!drawable || !vobjp ||
00295                                 vobjp->getPCode() != LL_PCODE_VOLUME || 
00296                                 vobjp->isAttachment() ||
00297                                 (deselect && !vobjp->isSelected()))
00298                         {
00299                                 continue;
00300                         }
00301 
00302                         if (limit_select_distance && dist_vec_squared(drawable->getWorldPosition(), av_pos) > select_dist_squared)
00303                         {
00304                                 continue;
00305                         }
00306 
00307                         S32 result = LLViewerCamera::getInstance()->sphereInFrustum(drawable->getPositionAgent(), drawable->getRadius());
00308                         if (result)
00309                         {
00310                                 switch (result)
00311                                 {
00312                                 case 1:
00313                                         // check vertices
00314                                         if (LLViewerCamera::getInstance()->areVertsVisible(vobjp, LLSelectMgr::sRectSelectInclusive))
00315                                         {
00316                                                 LLSelectMgr::getInstance()->highlightObjectOnly(vobjp);
00317                                         }
00318                                         break;
00319                                 case 2:
00320                                         LLSelectMgr::getInstance()->highlightObjectOnly(vobjp);
00321                                         break;
00322                                 default:
00323                                         break;
00324                                 }
00325                         }
00326                 }
00327         }
00328 
00329         // restore drawing mode
00330         glMatrixMode(GL_PROJECTION);
00331         gGL.popMatrix();
00332         glMatrixMode(GL_MODELVIEW);
00333 
00334         // restore camera
00335         LLViewerCamera::getInstance()->setFar(old_far_plane);
00336         LLViewerCamera::getInstance()->setNear(old_near_plane);
00337         gViewerWindow->setup3DRender();
00338 }
00339 
00340 
00341 const F32 COMPASS_SIZE = 64;
00342 static const F32 COMPASS_RANGE = 0.33f;
00343 
00344 void LLCompass::draw()
00345 {
00346         glMatrixMode(GL_MODELVIEW);
00347         gGL.pushMatrix();
00348 
00349         S32 width = 32;
00350         S32 height = 32;
00351 
00352         LLGLSUIDefault gls_ui;
00353 
00354         gGL.translatef( COMPASS_SIZE/2.f, COMPASS_SIZE/2.f, 0.f);
00355 
00356         if (mBkgndTexture)
00357         {
00358                 mBkgndTexture->bind();
00359                 gGL.color4f(1.0f, 1.0f, 1.0f, 1.0f);
00360                 
00361                 gGL.begin(LLVertexBuffer::QUADS);
00362                 
00363                 gGL.texCoord2f(1.f, 1.f);
00364                 gGL.vertex2i(width, height);
00365                 
00366                 gGL.texCoord2f(0.f, 1.f);
00367                 gGL.vertex2i(-width, height);
00368                 
00369                 gGL.texCoord2f(0.f, 0.f);
00370                 gGL.vertex2i(-width, -height);
00371                 
00372                 gGL.texCoord2f(1.f, 0.f);
00373                 gGL.vertex2i(width, -height);
00374                 
00375                 gGL.end();
00376         }
00377 
00378         // rotate subsequent draws to agent rotation
00379         F32 rotation = atan2( gAgent.getFrameAgent().getAtAxis().mV[VX], gAgent.getFrameAgent().getAtAxis().mV[VY] );
00380         glRotatef( - rotation * RAD_TO_DEG, 0.f, 0.f, -1.f);
00381         
00382         if (mTexture)
00383         {
00384                 mTexture->bind();
00385                 gGL.color4f(1.0f, 1.0f, 1.0f, 1.0f);
00386                 
00387                 gGL.begin(LLVertexBuffer::QUADS);
00388                 
00389                 gGL.texCoord2f(1.f, 1.f);
00390                 gGL.vertex2i(width, height);
00391                 
00392                 gGL.texCoord2f(0.f, 1.f);
00393                 gGL.vertex2i(-width, height);
00394                 
00395                 gGL.texCoord2f(0.f, 0.f);
00396                 gGL.vertex2i(-width, -height);
00397                 
00398                 gGL.texCoord2f(1.f, 0.f);
00399                 gGL.vertex2i(width, -height);
00400                 
00401                 gGL.end();
00402         }
00403 
00404         gGL.popMatrix();
00405 
00406 }
00407 
00408 
00409 
00410 void LLHorizontalCompass::draw()
00411 {
00412         LLGLSUIDefault gls_ui;
00413         
00414         S32 width = getRect().getWidth();
00415         S32 height = getRect().getHeight();
00416         S32 half_width = width / 2;
00417 
00418         if( mTexture )
00419         {
00420                 const LLVector3& at_axis = LLViewerCamera::getInstance()->getAtAxis();
00421                 F32 center = atan2( at_axis.mV[VX], at_axis.mV[VY] );
00422 
00423                 center += F_PI;
00424                 center = llclamp( center, 0.0f, F_TWO_PI ); // probably not necessary...
00425                 center /= F_TWO_PI;
00426                 F32 left = center - COMPASS_RANGE;
00427                 F32 right = center + COMPASS_RANGE;
00428 
00429                 mTexture->bind();
00430                 gGL.color4f(1.0f, 1.0f, 1.0f, 1.0f );
00431                 gGL.begin( LLVertexBuffer::QUADS );
00432 
00433                 gGL.texCoord2f(right, 1.f);
00434                 gGL.vertex2i(width, height);
00435 
00436                 gGL.texCoord2f(left, 1.f);
00437                 gGL.vertex2i(0, height);
00438 
00439                 gGL.texCoord2f(left, 0.f);
00440                 gGL.vertex2i(0, 0);
00441 
00442                 gGL.texCoord2f(right, 0.f);
00443                 gGL.vertex2i(width, 0);
00444 
00445                 gGL.end();
00446         }
00447 
00448         // Draw the focus line
00449         {
00450                 LLGLSNoTexture gls_no_texture;
00451                 gGL.color4fv( mFocusColor.mV );
00452                 gl_line_2d( half_width, 0, half_width, height );
00453         }
00454 }
00455 
00456 
00457 const F32 WIND_ALTITUDE                 = 180.f;
00458 
00459 
00460 void LLWind::renderVectors()
00461 {
00462         // Renders the wind as vectors (used for debug)
00463         S32 i,j;
00464         F32 x,y;
00465 
00466         F32 region_width_meters = LLWorld::getInstance()->getRegionWidthInMeters();
00467 
00468         LLGLSNoTexture gls_no_texture;
00469         gGL.pushMatrix();
00470         LLVector3 origin_agent;
00471         origin_agent = gAgent.getPosAgentFromGlobal(mOriginGlobal);
00472         gGL.translatef(origin_agent.mV[VX], origin_agent.mV[VY], WIND_ALTITUDE);
00473         for (j = 0; j < mSize; j++)
00474         {
00475                 for (i = 0; i < mSize; i++)
00476                 {
00477                         x = mCloudVelX[i + j*mSize] * WIND_SCALE_HACK;
00478                         y = mCloudVelY[i + j*mSize] * WIND_SCALE_HACK;
00479                         gGL.pushMatrix();
00480                         gGL.translatef((F32)i * region_width_meters/mSize, (F32)j * region_width_meters/mSize, 0.0);
00481                         gGL.color3f(0,1,0);
00482                         gGL.begin(LLVertexBuffer::POINTS);
00483                                 gGL.vertex3f(0,0,0);
00484                         gGL.end();
00485                         gGL.color3f(1,0,0);
00486                         gGL.begin(LLVertexBuffer::LINES);
00487                                 gGL.vertex3f(x * 0.1f, y * 0.1f ,0.f);
00488                                 gGL.vertex3f(x, y, 0.f);
00489                         gGL.end();
00490                         gGL.popMatrix();
00491                 }
00492         }
00493         gGL.popMatrix();
00494 }
00495 
00496 
00497 
00498 
00499 // Used by lltoolselectland
00500 void LLViewerParcelMgr::renderRect(const LLVector3d &west_south_bottom_global, 
00501                                                                    const LLVector3d &east_north_top_global )
00502 {
00503         LLGLSUIDefault gls_ui;
00504         LLGLSNoTexture gls_no_texture;
00505         LLGLDepthTest gls_depth(GL_TRUE);
00506 
00507         LLVector3 west_south_bottom_agent = gAgent.getPosAgentFromGlobal(west_south_bottom_global);
00508         F32 west        = west_south_bottom_agent.mV[VX];
00509         F32 south       = west_south_bottom_agent.mV[VY];
00510 //      F32 bottom      = west_south_bottom_agent.mV[VZ] - 1.f;
00511 
00512         LLVector3 east_north_top_agent = gAgent.getPosAgentFromGlobal(east_north_top_global);
00513         F32 east        = east_north_top_agent.mV[VX];
00514         F32 north       = east_north_top_agent.mV[VY];
00515 //      F32 top         = east_north_top_agent.mV[VZ] + 1.f;
00516 
00517         // HACK: At edge of last region of world, we need to make sure the region
00518         // resolves correctly so we can get a height value.
00519         const F32 FUDGE = 0.01f;
00520 
00521         F32 sw_bottom = LLWorld::getInstance()->resolveLandHeightAgent( LLVector3( west, south, 0.f ) );
00522         F32 se_bottom = LLWorld::getInstance()->resolveLandHeightAgent( LLVector3( east-FUDGE, south, 0.f ) );
00523         F32 ne_bottom = LLWorld::getInstance()->resolveLandHeightAgent( LLVector3( east-FUDGE, north-FUDGE, 0.f ) );
00524         F32 nw_bottom = LLWorld::getInstance()->resolveLandHeightAgent( LLVector3( west, north-FUDGE, 0.f ) );
00525 
00526         F32 sw_top = sw_bottom + PARCEL_POST_HEIGHT;
00527         F32 se_top = se_bottom + PARCEL_POST_HEIGHT;
00528         F32 ne_top = ne_bottom + PARCEL_POST_HEIGHT;
00529         F32 nw_top = nw_bottom + PARCEL_POST_HEIGHT;
00530 
00531         LLUI::setLineWidth(2.f);
00532         gGL.color4f(1.f, 1.f, 0.f, 1.f);
00533 
00534         // Cheat and give this the same pick-name as land
00535         gGL.begin(LLVertexBuffer::LINES);
00536 
00537         gGL.vertex3f(west, north, nw_bottom);
00538         gGL.vertex3f(west, north, nw_top);
00539 
00540         gGL.vertex3f(east, north, ne_bottom);
00541         gGL.vertex3f(east, north, ne_top);
00542 
00543         gGL.vertex3f(east, south, se_bottom);
00544         gGL.vertex3f(east, south, se_top);
00545 
00546         gGL.vertex3f(west, south, sw_bottom);
00547         gGL.vertex3f(west, south, sw_top);
00548 
00549         gGL.end();
00550 
00551         gGL.color4f(1.f, 1.f, 0.f, 0.2f);
00552         gGL.begin(LLVertexBuffer::QUADS);
00553 
00554         gGL.vertex3f(west, north, nw_bottom);
00555         gGL.vertex3f(west, north, nw_top);
00556         gGL.vertex3f(east, north, ne_top);
00557         gGL.vertex3f(east, north, ne_bottom);
00558 
00559         gGL.vertex3f(east, north, ne_bottom);
00560         gGL.vertex3f(east, north, ne_top);
00561         gGL.vertex3f(east, south, se_top);
00562         gGL.vertex3f(east, south, se_bottom);
00563 
00564         gGL.vertex3f(east, south, se_bottom);
00565         gGL.vertex3f(east, south, se_top);
00566         gGL.vertex3f(west, south, sw_top);
00567         gGL.vertex3f(west, south, sw_bottom);
00568 
00569         gGL.vertex3f(west, south, sw_bottom);
00570         gGL.vertex3f(west, south, sw_top);
00571         gGL.vertex3f(west, north, nw_top);
00572         gGL.vertex3f(west, north, nw_bottom);
00573 
00574         gGL.end();
00575 
00576         LLUI::setLineWidth(1.f);
00577 }
00578 
00579 /*
00580 void LLViewerParcelMgr::renderParcel(LLParcel* parcel )
00581 {
00582         S32 i;
00583         S32 count = parcel->getBoxCount();
00584         for (i = 0; i < count; i++)
00585         {
00586                 const LLParcelBox& box = parcel->getBox(i);
00587 
00588                 F32 west = box.mMin.mV[VX];
00589                 F32 south = box.mMin.mV[VY];
00590 
00591                 F32 east = box.mMax.mV[VX];
00592                 F32 north = box.mMax.mV[VY];
00593 
00594                 // HACK: At edge of last region of world, we need to make sure the region
00595                 // resolves correctly so we can get a height value.
00596                 const F32 FUDGE = 0.01f;
00597 
00598                 F32 sw_bottom = LLWorld::getInstance()->resolveLandHeightAgent( LLVector3( west, south, 0.f ) );
00599                 F32 se_bottom = LLWorld::getInstance()->resolveLandHeightAgent( LLVector3( east-FUDGE, south, 0.f ) );
00600                 F32 ne_bottom = LLWorld::getInstance()->resolveLandHeightAgent( LLVector3( east-FUDGE, north-FUDGE, 0.f ) );
00601                 F32 nw_bottom = LLWorld::getInstance()->resolveLandHeightAgent( LLVector3( west, north-FUDGE, 0.f ) );
00602 
00603                 // little hack to make nearby lines not Z-fight
00604                 east -= 0.1f;
00605                 north -= 0.1f;
00606 
00607                 F32 sw_top = sw_bottom + POST_HEIGHT;
00608                 F32 se_top = se_bottom + POST_HEIGHT;
00609                 F32 ne_top = ne_bottom + POST_HEIGHT;
00610                 F32 nw_top = nw_bottom + POST_HEIGHT;
00611 
00612                 LLGLSNoTexture gls_no_texture;
00613                 LLGLDepthTest gls_depth(GL_TRUE);
00614 
00615                 LLUI::setLineWidth(2.f);
00616                 gGL.color4f(0.f, 1.f, 1.f, 1.f);
00617 
00618                 // Cheat and give this the same pick-name as land
00619                 gGL.begin(LLVertexBuffer::LINES);
00620 
00621                 gGL.vertex3f(west, north, nw_bottom);
00622                 gGL.vertex3f(west, north, nw_top);
00623 
00624                 gGL.vertex3f(east, north, ne_bottom);
00625                 gGL.vertex3f(east, north, ne_top);
00626 
00627                 gGL.vertex3f(east, south, se_bottom);
00628                 gGL.vertex3f(east, south, se_top);
00629 
00630                 gGL.vertex3f(west, south, sw_bottom);
00631                 gGL.vertex3f(west, south, sw_top);
00632 
00633                 gGL.end();
00634 
00635                 gGL.color4f(0.f, 1.f, 1.f, 0.2f);
00636                 gGL.begin(LLVertexBuffer::QUADS);
00637 
00638                 gGL.vertex3f(west, north, nw_bottom);
00639                 gGL.vertex3f(west, north, nw_top);
00640                 gGL.vertex3f(east, north, ne_top);
00641                 gGL.vertex3f(east, north, ne_bottom);
00642 
00643                 gGL.vertex3f(east, north, ne_bottom);
00644                 gGL.vertex3f(east, north, ne_top);
00645                 gGL.vertex3f(east, south, se_top);
00646                 gGL.vertex3f(east, south, se_bottom);
00647 
00648                 gGL.vertex3f(east, south, se_bottom);
00649                 gGL.vertex3f(east, south, se_top);
00650                 gGL.vertex3f(west, south, sw_top);
00651                 gGL.vertex3f(west, south, sw_bottom);
00652 
00653                 gGL.vertex3f(west, south, sw_bottom);
00654                 gGL.vertex3f(west, south, sw_top);
00655                 gGL.vertex3f(west, north, nw_top);
00656                 gGL.vertex3f(west, north, nw_bottom);
00657 
00658                 gGL.end();
00659 
00660                 LLUI::setLineWidth(1.f);
00661         }
00662 }
00663 */
00664 
00665 
00666 // north = a wall going north/south.  Need that info to set up texture
00667 // coordinates correctly.
00668 void LLViewerParcelMgr::renderOneSegment(F32 x1, F32 y1, F32 x2, F32 y2, F32 height, U8 direction, LLViewerRegion* regionp)
00669 {
00670         // HACK: At edge of last region of world, we need to make sure the region
00671         // resolves correctly so we can get a height value.
00672         const F32 BORDER = REGION_WIDTH_METERS - 0.1f;
00673 
00674         F32 clamped_x1 = x1;
00675         F32 clamped_y1 = y1;
00676         F32 clamped_x2 = x2;
00677         F32 clamped_y2 = y2;
00678 
00679         if (clamped_x1 > BORDER) clamped_x1 = BORDER;
00680         if (clamped_y1 > BORDER) clamped_y1 = BORDER;
00681         if (clamped_x2 > BORDER) clamped_x2 = BORDER;
00682         if (clamped_y2 > BORDER) clamped_y2 = BORDER;
00683 
00684         F32 z;
00685         F32 z1;
00686         F32 z2;
00687 
00688         z1 = regionp->getLand().resolveHeightRegion( LLVector3( clamped_x1, clamped_y1, 0.f ) );
00689         z2 = regionp->getLand().resolveHeightRegion( LLVector3( clamped_x2, clamped_y2, 0.f ) );
00690 
00691         // Convert x1 and x2 from region-local to agent coords.
00692         LLVector3 origin = regionp->getOriginAgent();
00693         x1 += origin.mV[VX];
00694         x2 += origin.mV[VX];
00695         y1 += origin.mV[VY];
00696         y2 += origin.mV[VY];
00697 
00698         if (height < 1.f)
00699         {
00700                 z = z1+height;
00701                 gGL.vertex3f(x1, y1, z);
00702 
00703                 gGL.vertex3f(x1, y1, z1);
00704 
00705                 gGL.vertex3f(x2, y2, z2);
00706 
00707                 z = z2+height;
00708                 gGL.vertex3f(x2, y2, z);
00709         }
00710         else
00711         {
00712                 F32 tex_coord1;
00713                 F32 tex_coord2;
00714 
00715                 if (WEST_MASK == direction)
00716                 {
00717                         tex_coord1 = y1;
00718                         tex_coord2 = y2;
00719                 }
00720                 else if (SOUTH_MASK == direction)
00721                 {
00722                         tex_coord1 = x1;
00723                         tex_coord2 = x2;
00724                 }
00725                 else if (EAST_MASK == direction)
00726                 {
00727                         tex_coord1 = y2;
00728                         tex_coord2 = y1;
00729                 }
00730                 else /* (NORTH_MASK == direction) */
00731                 {
00732                         tex_coord1 = x2;
00733                         tex_coord2 = x1;
00734                 }
00735 
00736 
00737                 gGL.texCoord2f(tex_coord1*0.5f+0.5f, z1*0.5f);
00738                 gGL.vertex3f(x1, y1, z1);
00739 
00740                 gGL.texCoord2f(tex_coord2*0.5f+0.5f, z2*0.5f);
00741                 gGL.vertex3f(x2, y2, z2);
00742 
00743                 // top edge stairsteps
00744                 z = llmax(z2+height, z1+height);
00745                 gGL.texCoord2f(tex_coord2*0.5f+0.5f, z*0.5f);
00746                 gGL.vertex3f(x2, y2, z);
00747 
00748                 gGL.texCoord2f(tex_coord1*0.5f+0.5f, z*0.5f);
00749                 gGL.vertex3f(x1, y1, z);
00750         }
00751 }
00752 
00753 
00754 void LLViewerParcelMgr::renderHighlightSegments(const U8* segments, LLViewerRegion* regionp)
00755 {
00756         S32 x, y;
00757         F32 x1, y1;     // start point
00758         F32 x2, y2;     // end point
00759         bool has_segments = false;
00760 
00761         LLGLSUIDefault gls_ui;
00762         LLGLSNoTexture gls_no_texture;
00763         LLGLDepthTest gls_depth(GL_TRUE);
00764 
00765         gGL.color4f(1.f, 1.f, 0.f, 0.2f);
00766 
00767         const S32 STRIDE = (mParcelsPerEdge+1);
00768 
00769         // Cheat and give this the same pick-name as land
00770         
00771         
00772         for (y = 0; y < STRIDE; y++)
00773         {
00774                 for (x = 0; x < STRIDE; x++)
00775                 {
00776                         U8 segment_mask = segments[x + y*STRIDE];
00777 
00778                         if (segment_mask & SOUTH_MASK)
00779                         {
00780                                 x1 = x * PARCEL_GRID_STEP_METERS;
00781                                 y1 = y * PARCEL_GRID_STEP_METERS;
00782 
00783                                 x2 = x1 + PARCEL_GRID_STEP_METERS;
00784                                 y2 = y1;
00785                                 
00786                                 if (!has_segments)
00787                                 {
00788                                         has_segments = true;
00789                                         gGL.begin(LLVertexBuffer::QUADS);
00790                                 }
00791                                 renderOneSegment(x1, y1, x2, y2, PARCEL_POST_HEIGHT, SOUTH_MASK, regionp);
00792                         }
00793 
00794                         if (segment_mask & WEST_MASK)
00795                         {
00796                                 x1 = x * PARCEL_GRID_STEP_METERS;
00797                                 y1 = y * PARCEL_GRID_STEP_METERS;
00798 
00799                                 x2 = x1;
00800                                 y2 = y1 + PARCEL_GRID_STEP_METERS;
00801 
00802                                 if (!has_segments)
00803                                 {
00804                                         has_segments = true;
00805                                         gGL.begin(LLVertexBuffer::QUADS);
00806                                 }
00807                                 renderOneSegment(x1, y1, x2, y2, PARCEL_POST_HEIGHT, WEST_MASK, regionp);
00808                         }
00809                 }
00810         }
00811 
00812         if (has_segments)
00813         {
00814                 gGL.end();
00815         }
00816 }
00817 
00818 
00819 void LLViewerParcelMgr::renderCollisionSegments(U8* segments, BOOL use_pass, LLViewerRegion* regionp)
00820 {
00821 
00822         S32 x, y;
00823         F32 x1, y1;     // start point
00824         F32 x2, y2;     // end point
00825         F32 alpha = 0;
00826         F32 dist = 0;
00827         F32 dx, dy;
00828         F32 collision_height;
00829 
00830         const S32 STRIDE = (mParcelsPerEdge+1);
00831         
00832         LLVector3 pos = gAgent.getPositionAgent();
00833 
00834         F32 pos_x = pos.mV[VX];
00835         F32 pos_y = pos.mV[VY];
00836 
00837         LLGLSUIDefault gls_ui;
00838         LLGLDepthTest gls_depth(GL_TRUE);
00839         LLGLDisable cull(GL_CULL_FACE);
00840         
00841         if (mCollisionBanned == BA_BANNED)
00842         {
00843                 collision_height = BAN_HEIGHT;
00844         }
00845         else
00846         {
00847                 collision_height = PARCEL_HEIGHT;
00848         }
00849 
00850         
00851         if (use_pass && (mCollisionBanned == BA_NOT_ON_LIST))
00852         {
00853                 LLViewerImage::bindTexture(mPassImage);
00854         }
00855         else
00856         {
00857                 LLViewerImage::bindTexture(mBlockedImage);
00858         }
00859 
00860         gGL.begin(LLVertexBuffer::QUADS);
00861 
00862         for (y = 0; y < STRIDE; y++)
00863         {
00864                 for (x = 0; x < STRIDE; x++)
00865                 {
00866                         U8 segment_mask = segments[x + y*STRIDE];
00867                         U8 direction;
00868                         const F32 MAX_ALPHA = 0.95f;
00869                         const S32 DIST_OFFSET = 5;
00870                         const S32 MIN_DIST_SQ = DIST_OFFSET*DIST_OFFSET;
00871                         const S32 MAX_DIST_SQ = 169;
00872 
00873                         if (segment_mask & SOUTH_MASK)
00874                         {
00875                                 x1 = x * PARCEL_GRID_STEP_METERS;
00876                                 y1 = y * PARCEL_GRID_STEP_METERS;
00877 
00878                                 x2 = x1 + PARCEL_GRID_STEP_METERS;
00879                                 y2 = y1;
00880 
00881                                 if (gRenderForSelect)
00882                                 {
00883                                         LLColor4U color((U8)(GL_NAME_PARCEL_WALL >> 16), (U8)(GL_NAME_PARCEL_WALL >> 8), (U8)GL_NAME_PARCEL_WALL);
00884                                         gGL.color4ubv(color.mV);
00885                                 }
00886                                 else
00887                                 {
00888                                         dy = (pos_y - y1) + DIST_OFFSET;
00889                                         
00890                                         if (pos_x < x1)
00891                                                 dx = pos_x - x1;
00892                                         else if (pos_x > x2)
00893                                                 dx = pos_x - x2;
00894                                         else 
00895                                                 dx = 0;
00896                                         
00897                                         dist = dx*dx+dy*dy;
00898 
00899                                         if (dist < MIN_DIST_SQ)
00900                                                 alpha = MAX_ALPHA;
00901                                         else if (dist > MAX_DIST_SQ)
00902                                                 alpha = 0.0f;
00903                                         else
00904                                                 alpha = 30/dist;
00905 
00906                                         alpha = llclamp(alpha, 0.0f, MAX_ALPHA);
00907 
00908                                         gGL.color4f(1.f, 1.f, 1.f, alpha);
00909                                 }
00910 
00911                                 if ((pos_y - y1) < 0) direction = SOUTH_MASK;
00912                                 else            direction = NORTH_MASK;
00913 
00914                                 // avoid Z fighting
00915                                 renderOneSegment(x1+0.1f, y1+0.1f, x2+0.1f, y2+0.1f, collision_height, direction, regionp);
00916 
00917                         }
00918 
00919                         if (segment_mask & WEST_MASK)
00920                         {
00921                                 x1 = x * PARCEL_GRID_STEP_METERS;
00922                                 y1 = y * PARCEL_GRID_STEP_METERS;
00923 
00924                                 x2 = x1;
00925                                 y2 = y1 + PARCEL_GRID_STEP_METERS;
00926 
00927                                 if (gRenderForSelect)
00928                                 {
00929                                         LLColor4U color((U8)(GL_NAME_PARCEL_WALL >> 16), (U8)(GL_NAME_PARCEL_WALL >> 8), (U8)GL_NAME_PARCEL_WALL);
00930                                         gGL.color4ubv(color.mV);
00931                                 }
00932                                 else
00933                                 {                                       
00934                                         dx = (pos_x - x1) + DIST_OFFSET;
00935                 
00936                                         if (pos_y < y1) 
00937                                                 dy = pos_y - y1;
00938                                         else if (pos_y > y2)
00939                                                 dy = pos_y - y2;
00940                                         else 
00941                                                 dy = 0;
00942 
00943                                         dist = dx*dx+dy*dy;
00944                                         
00945                                         if (dist < MIN_DIST_SQ) 
00946                                                 alpha = MAX_ALPHA;
00947                                         else if (dist > MAX_DIST_SQ)
00948                                                 alpha = 0.0f;
00949                                         else
00950                                                 alpha = 30/dist;
00951 
00952                                         alpha = llclamp(alpha, 0.0f, MAX_ALPHA);
00953 
00954                                         gGL.color4f(1.f, 1.f, 1.f, alpha);
00955                                 }
00956 
00957                                 if ((pos_x - x1) > 0) direction = WEST_MASK;
00958                                 else            direction = EAST_MASK;
00959                                 
00960                                 // avoid Z fighting
00961                                 renderOneSegment(x1+0.1f, y1+0.1f, x2+0.1f, y2+0.1f, collision_height, direction, regionp);
00962 
00963                         }
00964                 }
00965         }
00966 
00967         gGL.end();
00968 }
00969 
00970 void draw_line_cube(F32 width, const LLVector3& center)
00971 {
00972         width = 0.5f * width;
00973         gGL.vertex3f(center.mV[VX] + width ,center.mV[VY] + width,center.mV[VZ] + width);
00974         gGL.vertex3f(center.mV[VX] - width ,center.mV[VY] + width,center.mV[VZ] + width);
00975         gGL.vertex3f(center.mV[VX] - width ,center.mV[VY] + width,center.mV[VZ] + width);
00976         gGL.vertex3f(center.mV[VX] - width ,center.mV[VY] - width,center.mV[VZ] + width);
00977         gGL.vertex3f(center.mV[VX] - width ,center.mV[VY] - width,center.mV[VZ] + width);
00978         gGL.vertex3f(center.mV[VX] + width ,center.mV[VY] - width,center.mV[VZ] + width);
00979         gGL.vertex3f(center.mV[VX] + width ,center.mV[VY] - width,center.mV[VZ] + width);
00980         gGL.vertex3f(center.mV[VX] + width ,center.mV[VY] + width,center.mV[VZ] + width);
00981 
00982         gGL.vertex3f(center.mV[VX] + width ,center.mV[VY] + width,center.mV[VZ] - width);
00983         gGL.vertex3f(center.mV[VX] - width ,center.mV[VY] + width,center.mV[VZ] - width);
00984         gGL.vertex3f(center.mV[VX] - width ,center.mV[VY] + width,center.mV[VZ] - width);
00985         gGL.vertex3f(center.mV[VX] - width ,center.mV[VY] - width,center.mV[VZ] - width);
00986         gGL.vertex3f(center.mV[VX] - width ,center.mV[VY] - width,center.mV[VZ] - width);
00987         gGL.vertex3f(center.mV[VX] + width ,center.mV[VY] - width,center.mV[VZ] - width);
00988         gGL.vertex3f(center.mV[VX] + width ,center.mV[VY] - width,center.mV[VZ] - width);
00989         gGL.vertex3f(center.mV[VX] + width ,center.mV[VY] + width,center.mV[VZ] - width);
00990 
00991         gGL.vertex3f(center.mV[VX] + width ,center.mV[VY] + width,center.mV[VZ] + width);
00992         gGL.vertex3f(center.mV[VX] + width ,center.mV[VY] + width,center.mV[VZ] - width);
00993         gGL.vertex3f(center.mV[VX] - width ,center.mV[VY] + width,center.mV[VZ] + width);
00994         gGL.vertex3f(center.mV[VX] - width ,center.mV[VY] + width,center.mV[VZ] - width);
00995         gGL.vertex3f(center.mV[VX] - width ,center.mV[VY] - width,center.mV[VZ] + width);
00996         gGL.vertex3f(center.mV[VX] - width ,center.mV[VY] - width,center.mV[VZ] - width);
00997         gGL.vertex3f(center.mV[VX] + width ,center.mV[VY] - width,center.mV[VZ] + width);
00998         gGL.vertex3f(center.mV[VX] + width ,center.mV[VY] - width,center.mV[VZ] - width);
00999 }
01000 
01001 
01002 void LLViewerObjectList::renderObjectBeacons()
01003 {
01004         if (mDebugBeacons.empty())
01005         {
01006                 return;
01007         }
01008 
01009         //const LLFontGL *font = LLResMgr::getInstance()->getRes(LLFONT_SANSSERIF);
01010 
01011         LLGLSUIDefault gls_ui;
01012 
01013         {
01014                 LLGLSNoTexture gls_ui_no_texture;
01015 
01016                 S32 last_line_width = -1;
01017                 // gGL.begin(LLVertexBuffer::LINES); // Always happens in (line_width != last_line_width)
01018                 
01019                 for (S32 i = 0; i < mDebugBeacons.count(); i++)
01020                 {
01021                         const LLDebugBeacon &debug_beacon = mDebugBeacons[i];
01022                         LLColor4 color = debug_beacon.mColor;
01023                         color.mV[3] *= 0.25f;
01024                         S32 line_width = debug_beacon.mLineWidth;
01025                         if (line_width != last_line_width)
01026                         {
01027                                 if (i > 0)
01028                                 {
01029                                         gGL.end();
01030                                         gGL.flush();
01031                                 }
01032                                 glLineWidth( (F32)line_width );
01033                                 last_line_width = line_width;
01034                                 gGL.begin(LLVertexBuffer::LINES);
01035                         }
01036 
01037                         const LLVector3 &thisline = debug_beacon.mPositionAgent;
01038                         gGL.color4fv(color.mV);
01039                         gGL.vertex3f(thisline.mV[VX],thisline.mV[VY],thisline.mV[VZ] - 50.f);
01040                         gGL.vertex3f(thisline.mV[VX],thisline.mV[VY],thisline.mV[VZ] + 50.f);
01041                         gGL.vertex3f(thisline.mV[VX] - 2.f,thisline.mV[VY],thisline.mV[VZ]);
01042                         gGL.vertex3f(thisline.mV[VX] + 2.f,thisline.mV[VY],thisline.mV[VZ]);
01043                         gGL.vertex3f(thisline.mV[VX],thisline.mV[VY] - 2.f,thisline.mV[VZ]);
01044                         gGL.vertex3f(thisline.mV[VX],thisline.mV[VY] + 2.f,thisline.mV[VZ]);
01045 
01046                         draw_line_cube(0.10f, thisline);
01047                 }
01048                 gGL.end();
01049         }
01050 
01051         {
01052                 LLGLSNoTexture gls_ui_no_texture;
01053                 LLGLDepthTest gls_depth(GL_TRUE);
01054                 
01055                 S32 last_line_width = -1;
01056                 // gGL.begin(LLVertexBuffer::LINES); // Always happens in (line_width != last_line_width)
01057                 
01058                 for (S32 i = 0; i < mDebugBeacons.count(); i++)
01059                 {
01060                         const LLDebugBeacon &debug_beacon = mDebugBeacons[i];
01061 
01062                         S32 line_width = debug_beacon.mLineWidth;
01063                         if (line_width != last_line_width)
01064                         {
01065                                 if (i > 0)
01066                                 {
01067                                         gGL.end();
01068                                         gGL.flush();
01069                                 }
01070                                 glLineWidth( (F32)line_width );
01071                                 last_line_width = line_width;
01072                                 gGL.begin(LLVertexBuffer::LINES);
01073                         }
01074 
01075                         const LLVector3 &thisline = debug_beacon.mPositionAgent;
01076                         gGL.color4fv(debug_beacon.mColor.mV);
01077                         gGL.vertex3f(thisline.mV[VX],thisline.mV[VY],thisline.mV[VZ] - 0.5f);
01078                         gGL.vertex3f(thisline.mV[VX],thisline.mV[VY],thisline.mV[VZ] + 0.5f);
01079                         gGL.vertex3f(thisline.mV[VX] - 0.5f,thisline.mV[VY],thisline.mV[VZ]);
01080                         gGL.vertex3f(thisline.mV[VX] + 0.5f,thisline.mV[VY],thisline.mV[VZ]);
01081                         gGL.vertex3f(thisline.mV[VX],thisline.mV[VY] - 0.5f,thisline.mV[VZ]);
01082                         gGL.vertex3f(thisline.mV[VX],thisline.mV[VY] + 0.5f,thisline.mV[VZ]);
01083 
01084                         draw_line_cube(0.10f, thisline);
01085                 }
01086                 
01087                 gGL.end();
01088                 gGL.flush();
01089                 glLineWidth(1.f);
01090 
01091                 for (S32 i = 0; i < mDebugBeacons.count(); i++)
01092                 {
01093                         LLDebugBeacon &debug_beacon = mDebugBeacons[i];
01094                         if (debug_beacon.mString == "")
01095                         {
01096                                 continue;
01097                         }
01098                         LLHUDText *hud_textp = (LLHUDText *)LLHUDObject::addHUDObject(LLHUDObject::LL_HUD_TEXT);
01099 
01100                         hud_textp->setZCompare(FALSE);
01101                         LLColor4 color;
01102                         color = debug_beacon.mTextColor;
01103                         color.mV[3] *= 1.f;
01104 
01105                         hud_textp->setString(utf8str_to_wstring(debug_beacon.mString.c_str()));
01106                         hud_textp->setColor(color);
01107                         hud_textp->setPositionAgent(debug_beacon.mPositionAgent);
01108                         debug_beacon.mHUDObject = hud_textp;
01109                 }
01110         }
01111 }
01112 
01113 
01114 void pre_show_depth_buffer()
01115 {
01116         glClear(GL_STENCIL_BUFFER_BIT);
01117         glEnable(GL_STENCIL_TEST);
01118         glStencilFunc(GL_ALWAYS,0,0);
01119         glStencilOp(GL_INCR,GL_INCR,GL_INCR);
01120 }
01121 
01122 void post_show_depth_buffer()
01123 {
01124         int xsize =500, ysize =500;
01125         U8 *buf = new U8[xsize*ysize];
01126 
01127         glReadPixels(0,0,xsize,ysize,GL_STENCIL_INDEX,GL_UNSIGNED_BYTE, buf);
01128 
01129         int total = 0;
01130         int i;
01131         for (i=0;i<xsize*ysize;i++) 
01132         {
01133                 total += buf[i];
01134                 buf[i] <<= 3;
01135         }
01136 
01137         float DC = (float)total/(float)(ysize*xsize);
01138         int DCline = llfloor((xsize-20) * DC / 10.0f);
01139         int stride = xsize / 10;
01140 
01141         int y = 2;
01142 
01143         for (i=0;i<DCline;i++)
01144         {
01145                 if (i % stride == 0) i+=2;
01146                 if (i > xsize) y=6;
01147                 buf[ysize*(y+0)+i]=255;
01148                 buf[ysize*(y+1)+i]=255;
01149                 buf[ysize*(y+2)+i]=255;
01150         }
01151         glDrawPixels(xsize,ysize,GL_RED,GL_UNSIGNED_BYTE,buf);
01152 
01153         delete [] buf;
01154 }

Generated on Fri May 16 08:33:37 2008 for SecondLife by  doxygen 1.5.5