PageRenderTime 377ms CodeModel.GetById 243ms app.highlight 16ms RepoModel.GetById 114ms app.codeStats 0ms

/indra/newview/llhudrender.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 149 lines | 102 code | 19 blank | 28 comment | 6 complexity | 6aeca5b387804bf4f4303c2039111abb MD5 | raw file
  1/** 
  2 * @file llhudrender.cpp
  3 * @brief LLHUDRender class implementation
  4 *
  5 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llhudrender.h"
 30
 31#include "llrender.h"
 32#include "llgl.h"
 33#include "llviewercamera.h"
 34#include "v3math.h"
 35#include "llquaternion.h"
 36#include "llfontgl.h"
 37#include "llglheaders.h"
 38#include "llviewerwindow.h"
 39#include "llui.h"
 40
 41void hud_render_utf8text(const std::string &str, const LLVector3 &pos_agent,
 42					 const LLFontGL &font,
 43					 const U8 style,
 44					 const LLFontGL::ShadowType shadow,
 45					 const F32 x_offset, const F32 y_offset,
 46					 const LLColor4& color,
 47					 const BOOL orthographic)
 48{
 49	LLWString wstr(utf8str_to_wstring(str));
 50	hud_render_text(wstr, pos_agent, font, style, shadow, x_offset, y_offset, color, orthographic);
 51}
 52
 53void hud_render_text(const LLWString &wstr, const LLVector3 &pos_agent,
 54					const LLFontGL &font,
 55					const U8 style,
 56					const LLFontGL::ShadowType shadow,
 57					const F32 x_offset, const F32 y_offset,
 58					const LLColor4& color,
 59					const BOOL orthographic)
 60{
 61	LLViewerCamera* camera = LLViewerCamera::getInstance();
 62	// Do cheap plane culling
 63	LLVector3 dir_vec = pos_agent - camera->getOrigin();
 64	dir_vec /= dir_vec.magVec();
 65
 66	if (wstr.empty() || (!orthographic && dir_vec * camera->getAtAxis() <= 0.f))
 67	{
 68		return;
 69	}
 70
 71	LLVector3 right_axis;
 72	LLVector3 up_axis;
 73	if (orthographic)
 74	{
 75		right_axis.setVec(0.f, -1.f / gViewerWindow->getWorldViewHeightScaled(), 0.f);
 76		up_axis.setVec(0.f, 0.f, 1.f / gViewerWindow->getWorldViewHeightScaled());
 77	}
 78	else
 79	{
 80		camera->getPixelVectors(pos_agent, up_axis, right_axis);
 81	}
 82	LLCoordFrame render_frame = *camera;
 83	LLQuaternion rot;
 84	if (!orthographic)
 85	{
 86		rot = render_frame.getQuaternion();
 87		rot = rot * LLQuaternion(-F_PI_BY_TWO, camera->getYAxis());
 88		rot = rot * LLQuaternion(F_PI_BY_TWO, camera->getXAxis());
 89	}
 90	else
 91	{
 92		rot = LLQuaternion(-F_PI_BY_TWO, LLVector3(0.f, 0.f, 1.f));
 93		rot = rot * LLQuaternion(-F_PI_BY_TWO, LLVector3(0.f, 1.f, 0.f));
 94	}
 95	F32 angle;
 96	LLVector3 axis;
 97	rot.getAngleAxis(&angle, axis);
 98
 99	LLVector3 render_pos = pos_agent + (floorf(x_offset) * right_axis) + (floorf(y_offset) * up_axis);
100
101	//get the render_pos in screen space
102	
103	F64 winX, winY, winZ;
104	LLRect world_view_rect = gViewerWindow->getWorldViewRectRaw();
105	S32	viewport[4];
106	viewport[0] = world_view_rect.mLeft;
107	viewport[1] = world_view_rect.mBottom;
108	viewport[2] = world_view_rect.getWidth();
109	viewport[3] = world_view_rect.getHeight();
110
111	F64 mdlv[16];
112	F64 proj[16];
113
114	for (U32 i = 0; i < 16; i++)
115	{
116		mdlv[i] = (F64) gGLModelView[i];
117		proj[i] = (F64) gGLProjection[i];
118	}
119
120	gluProject(render_pos.mV[0], render_pos.mV[1], render_pos.mV[2],
121				mdlv, proj, (GLint*) viewport,
122				&winX, &winY, &winZ);
123		
124	//fonts all render orthographically, set up projection``
125	gGL.matrixMode(LLRender::MM_PROJECTION);
126	gGL.pushMatrix();
127	gGL.matrixMode(LLRender::MM_MODELVIEW);
128	gGL.pushMatrix();
129	LLUI::pushMatrix();
130		
131	gl_state_for_2d(world_view_rect.getWidth(), world_view_rect.getHeight());
132	gViewerWindow->setup3DViewport();
133	
134	winX -= world_view_rect.mLeft;
135	winY -= world_view_rect.mBottom;
136	LLUI::loadIdentity();
137	gGL.loadIdentity();
138	LLUI::translate((F32) winX*1.0f/LLFontGL::sScaleX, (F32) winY*1.0f/(LLFontGL::sScaleY), -(((F32) winZ*2.f)-1.f));
139	F32 right_x;
140	
141	font.render(wstr, 0, 0, 0, color, LLFontGL::LEFT, LLFontGL::BASELINE, style, shadow, wstr.length(), 1000, &right_x);
142
143	LLUI::popMatrix();
144	gGL.popMatrix();
145
146	gGL.matrixMode(LLRender::MM_PROJECTION);
147	gGL.popMatrix();
148	gGL.matrixMode(LLRender::MM_MODELVIEW);
149}