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

Generated on Thu Jul 1 06:08:40 2010 for Second Life Viewer by  doxygen 1.4.7