diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llhudconnector.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llhudconnector.cpp')
-rw-r--r-- | linden/indra/newview/llhudconnector.cpp | 217 |
1 files changed, 217 insertions, 0 deletions
diff --git a/linden/indra/newview/llhudconnector.cpp b/linden/indra/newview/llhudconnector.cpp new file mode 100644 index 0000000..18c1bfc --- /dev/null +++ b/linden/indra/newview/llhudconnector.cpp | |||
@@ -0,0 +1,217 @@ | |||
1 | /** | ||
2 | * @file llhudconnector.cpp | ||
3 | * @brief LLHUDConnector class implementation | ||
4 | * | ||
5 | * Copyright (c) 2002-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #include "llviewerprecompiledheaders.h" | ||
29 | |||
30 | #include "llhudconnector.h" | ||
31 | #include "llviewercamera.h" | ||
32 | #include "llviewerobject.h" | ||
33 | |||
34 | #include "llgl.h" | ||
35 | #include "llimagegl.h" | ||
36 | #include "llsphere.h" | ||
37 | #include "llhudrender.h" | ||
38 | #include "llfontgl.h" | ||
39 | #include "llglheaders.h" | ||
40 | |||
41 | LLHUDConnector::LLHUDConnector(const U8 type) : | ||
42 | LLHUDObject(type), | ||
43 | mZCompare(TRUE) | ||
44 | { | ||
45 | mColor = LLColor4(1.f, 1.f, 1.f, 1.f); | ||
46 | mFirstColor = mColor; | ||
47 | mSecondColor = mColor; | ||
48 | mDoFade = TRUE; | ||
49 | mFadeDistance = 40.f; | ||
50 | mFadeRange = 10.f; | ||
51 | mDrawFirst = mDrawSecond = TRUE; | ||
52 | |||
53 | mLabel = "Foo!"; | ||
54 | } | ||
55 | |||
56 | LLHUDConnector::~LLHUDConnector() | ||
57 | { | ||
58 | } | ||
59 | |||
60 | void LLHUDConnector::setLabel(const LLString &label) | ||
61 | { | ||
62 | mLabel = label; | ||
63 | } | ||
64 | |||
65 | void LLHUDConnector::setTargets(LLViewerObject *first_object, LLViewerObject *second_object) | ||
66 | { | ||
67 | setSourceObject(first_object); | ||
68 | setTargetObject(second_object); | ||
69 | } | ||
70 | |||
71 | void LLHUDConnector::render() | ||
72 | { | ||
73 | if (mSourceObject.isNull() || mTargetObject.isNull()) | ||
74 | { | ||
75 | mSourceObject = NULL; | ||
76 | mTargetObject = NULL; | ||
77 | return; | ||
78 | } | ||
79 | |||
80 | if (mSourceObject->isDead() || mTargetObject->isDead()) | ||
81 | { | ||
82 | mSourceObject = NULL; | ||
83 | mTargetObject = NULL; | ||
84 | return; | ||
85 | } | ||
86 | |||
87 | LLVector3 first_pos_agent = mSourceObject->getPositionAgent(); | ||
88 | LLVector3 second_pos_agent = mTargetObject->getPositionAgent(); | ||
89 | |||
90 | LLVector3 center_agent = 0.5f*(first_pos_agent + second_pos_agent); | ||
91 | F32 dist = (center_agent - gCamera->getOrigin()).magVec(); | ||
92 | F32 alpha_factor = 1.f; | ||
93 | |||
94 | if (mDoFade) | ||
95 | { | ||
96 | if (dist > mFadeDistance) | ||
97 | { | ||
98 | alpha_factor = llmax(0.f, 1.f - (dist - mFadeDistance)/mFadeRange); | ||
99 | } | ||
100 | } | ||
101 | |||
102 | if (alpha_factor < 0.01f) | ||
103 | { | ||
104 | return; | ||
105 | } | ||
106 | |||
107 | LLGLSPipelineAlpha gls_pipeline_alpha; | ||
108 | LLImageGL::unbindTexture(0, GL_TEXTURE_2D); | ||
109 | |||
110 | LLVector3 dir_vec = first_pos_agent - second_pos_agent; | ||
111 | dir_vec.normVec(); | ||
112 | dir_vec *= 0.05f; | ||
113 | |||
114 | LLVector3 first_line_pos = first_pos_agent - dir_vec; | ||
115 | LLVector3 second_line_pos = second_pos_agent + dir_vec; | ||
116 | |||
117 | LLColor4 color; | ||
118 | |||
119 | // Spheres on ends of connectors | ||
120 | if (mDrawFirst) | ||
121 | { | ||
122 | color = mFirstColor; | ||
123 | color.mV[3] *= alpha_factor; | ||
124 | glColor4fv(color.mV); | ||
125 | glPushMatrix(); | ||
126 | glTranslatef(first_pos_agent.mV[0], first_pos_agent.mV[1], first_pos_agent.mV[2]); | ||
127 | glScalef(0.1f, 0.1f, 0.1f); | ||
128 | gSphere.render(); | ||
129 | glPopMatrix(); | ||
130 | } | ||
131 | |||
132 | if (mDrawSecond) | ||
133 | { | ||
134 | color = mSecondColor; | ||
135 | color.mV[3] *= alpha_factor; | ||
136 | glColor4fv(color.mV); | ||
137 | glPushMatrix(); | ||
138 | glTranslatef(second_pos_agent.mV[0], second_pos_agent.mV[1], second_pos_agent.mV[2]); | ||
139 | glScalef(0.1f, 0.1f, 0.1f); | ||
140 | gSphere.render(); | ||
141 | glPopMatrix(); | ||
142 | } | ||
143 | |||
144 | color = mColor; | ||
145 | color.mV[3] *= alpha_factor; | ||
146 | glColor4fv(color.mV); | ||
147 | glBegin(GL_LINES); | ||
148 | glVertex3fv(first_line_pos.mV); | ||
149 | glVertex3fv(second_line_pos.mV); | ||
150 | glEnd(); | ||
151 | |||
152 | { | ||
153 | LLGLDepthTest gls_depth(GL_FALSE); | ||
154 | // Spheres on ends of connectors | ||
155 | if (mDrawFirst) | ||
156 | { | ||
157 | color = mFirstColor; | ||
158 | color.mV[3] *= 0.25f*alpha_factor; | ||
159 | glColor4fv(color.mV); | ||
160 | glPushMatrix(); | ||
161 | glTranslatef(first_pos_agent.mV[0], first_pos_agent.mV[1], first_pos_agent.mV[2]); | ||
162 | glScalef(0.1f, 0.1f, 0.1f); | ||
163 | gSphere.render(); | ||
164 | glPopMatrix(); | ||
165 | } | ||
166 | if (mDrawSecond) | ||
167 | { | ||
168 | color = mSecondColor; | ||
169 | color.mV[3] *= 0.25f*alpha_factor; | ||
170 | glColor4fv(color.mV); | ||
171 | glPushMatrix(); | ||
172 | glTranslatef(second_pos_agent.mV[0], second_pos_agent.mV[1], second_pos_agent.mV[2]); | ||
173 | glScalef(0.1f, 0.1f, 0.1f); | ||
174 | gSphere.render(); | ||
175 | glPopMatrix(); | ||
176 | } | ||
177 | { | ||
178 | LLGLSNoTexture no_texture; | ||
179 | color = mColor; | ||
180 | color.mV[3] *= 0.25f*alpha_factor; | ||
181 | glColor4fv(color.mV); | ||
182 | glBegin(GL_LINES); | ||
183 | glVertex3fv(first_line_pos.mV); | ||
184 | glVertex3fv(second_line_pos.mV); | ||
185 | glEnd(); | ||
186 | } | ||
187 | } | ||
188 | |||
189 | LLFontGL *fontp = LLFontGL::sSansSerif; | ||
190 | if (mLabel.size()) | ||
191 | { | ||
192 | hud_render_utf8text(mLabel, center_agent, *fontp, LLFontGL::NORMAL, -0.5f*fontp->getWidthF32(mLabel), 0, LLColor4::white, FALSE); | ||
193 | } | ||
194 | } | ||
195 | |||
196 | void LLHUDConnector::setZCompare(const BOOL zcompare) | ||
197 | { | ||
198 | mZCompare = zcompare; | ||
199 | } | ||
200 | |||
201 | void LLHUDConnector::setColors(const LLColor4 &color, const LLColor4 &first_color, const LLColor4 &second_color) | ||
202 | { | ||
203 | mColor = color; | ||
204 | mFirstColor = first_color; | ||
205 | mSecondColor = second_color; | ||
206 | } | ||
207 | |||
208 | void LLHUDConnector::setDoFade(const BOOL do_fade) | ||
209 | { | ||
210 | mDoFade = do_fade; | ||
211 | } | ||
212 | |||
213 | void LLHUDConnector::setEndpoints(const BOOL &first, const BOOL &second) | ||
214 | { | ||
215 | mDrawFirst = first; | ||
216 | mDrawSecond = second; | ||
217 | } | ||