xref: /aoo42x/main/tools/source/generic/b3dtrans.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_tools.hxx"
30*cdf0e10cSrcweir #include <tools/b3dtrans.hxx>
31*cdf0e10cSrcweir #include <tools/debug.hxx>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir /*************************************************************************
34*cdf0e10cSrcweir |*
35*cdf0e10cSrcweir |* Transformationen fuer alle 3D Ausgaben
36*cdf0e10cSrcweir |*
37*cdf0e10cSrcweir \************************************************************************/
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir B3dTransformationSet::B3dTransformationSet()
40*cdf0e10cSrcweir {
41*cdf0e10cSrcweir 	Reset();
42*cdf0e10cSrcweir }
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir B3dTransformationSet::~B3dTransformationSet()
45*cdf0e10cSrcweir {
46*cdf0e10cSrcweir }
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir void B3dTransformationSet::Orientation(basegfx::B3DHomMatrix& rTarget, basegfx::B3DPoint aVRP, basegfx::B3DVector aVPN, basegfx::B3DVector aVUP)
49*cdf0e10cSrcweir {
50*cdf0e10cSrcweir 	rTarget.translate( -aVRP.getX(), -aVRP.getY(), -aVRP.getZ());
51*cdf0e10cSrcweir 	aVUP.normalize();
52*cdf0e10cSrcweir 	aVPN.normalize();
53*cdf0e10cSrcweir 	basegfx::B3DVector aRx(aVUP);
54*cdf0e10cSrcweir 	basegfx::B3DVector aRy(aVPN);
55*cdf0e10cSrcweir 	aRx = aRx.getPerpendicular(aRy);
56*cdf0e10cSrcweir 	aRx.normalize();
57*cdf0e10cSrcweir 	aRy = aRy.getPerpendicular(aRx);
58*cdf0e10cSrcweir 	aRy.normalize();
59*cdf0e10cSrcweir 	basegfx::B3DHomMatrix aTemp;
60*cdf0e10cSrcweir 	aTemp.set(0, 0, aRx.getX());
61*cdf0e10cSrcweir 	aTemp.set(0, 1, aRx.getY());
62*cdf0e10cSrcweir 	aTemp.set(0, 2, aRx.getZ());
63*cdf0e10cSrcweir 	aTemp.set(1, 0, aRy.getX());
64*cdf0e10cSrcweir 	aTemp.set(1, 1, aRy.getY());
65*cdf0e10cSrcweir 	aTemp.set(1, 2, aRy.getZ());
66*cdf0e10cSrcweir 	aTemp.set(2, 0, aVPN.getX());
67*cdf0e10cSrcweir 	aTemp.set(2, 1, aVPN.getY());
68*cdf0e10cSrcweir 	aTemp.set(2, 2, aVPN.getZ());
69*cdf0e10cSrcweir 	rTarget *= aTemp;
70*cdf0e10cSrcweir }
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir void B3dTransformationSet::Frustum(basegfx::B3DHomMatrix& rTarget, double fLeft, double fRight, double fBottom, double fTop, double fNear, double fFar)
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir 	if(!(fNear > 0.0))
75*cdf0e10cSrcweir 	{
76*cdf0e10cSrcweir 		fNear = 0.001;
77*cdf0e10cSrcweir 	}
78*cdf0e10cSrcweir 	if(!(fFar > 0.0))
79*cdf0e10cSrcweir 	{
80*cdf0e10cSrcweir 		fFar = 1.0;
81*cdf0e10cSrcweir 	}
82*cdf0e10cSrcweir 	if(fNear == fFar)
83*cdf0e10cSrcweir 	{
84*cdf0e10cSrcweir 		fFar = fNear + 1.0;
85*cdf0e10cSrcweir 	}
86*cdf0e10cSrcweir 	if(fLeft == fRight)
87*cdf0e10cSrcweir 	{
88*cdf0e10cSrcweir 		fLeft -= 1.0;
89*cdf0e10cSrcweir 		fRight += 1.0;
90*cdf0e10cSrcweir 	}
91*cdf0e10cSrcweir 	if(fTop == fBottom)
92*cdf0e10cSrcweir 	{
93*cdf0e10cSrcweir 		fBottom -= 1.0;
94*cdf0e10cSrcweir 		fTop += 1.0;
95*cdf0e10cSrcweir 	}
96*cdf0e10cSrcweir 	basegfx::B3DHomMatrix aTemp;
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 	aTemp.set(0, 0, 2.0 * fNear / (fRight - fLeft));
99*cdf0e10cSrcweir 	aTemp.set(1, 1, 2.0 * fNear / (fTop - fBottom));
100*cdf0e10cSrcweir 	aTemp.set(0, 2, (fRight + fLeft) / (fRight - fLeft));
101*cdf0e10cSrcweir 	aTemp.set(1, 2, (fTop + fBottom) / (fTop - fBottom));
102*cdf0e10cSrcweir 	aTemp.set(2, 2, -1.0 * ((fFar + fNear) / (fFar - fNear)));
103*cdf0e10cSrcweir 	aTemp.set(3, 2, -1.0);
104*cdf0e10cSrcweir 	aTemp.set(2, 3, -1.0 * ((2.0 * fFar * fNear) / (fFar - fNear)));
105*cdf0e10cSrcweir 	aTemp.set(3, 3, 0.0);
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 	rTarget *= aTemp;
108*cdf0e10cSrcweir }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir void B3dTransformationSet::Ortho(basegfx::B3DHomMatrix& rTarget, double fLeft, double fRight, double fBottom, double fTop, double fNear, double fFar)
111*cdf0e10cSrcweir {
112*cdf0e10cSrcweir 	if(fNear == fFar)
113*cdf0e10cSrcweir 	{
114*cdf0e10cSrcweir 		DBG_ERROR("Near and far clipping plane in Ortho definition are identical");
115*cdf0e10cSrcweir 		fFar = fNear + 1.0;
116*cdf0e10cSrcweir 	}
117*cdf0e10cSrcweir 	if(fLeft == fRight)
118*cdf0e10cSrcweir 	{
119*cdf0e10cSrcweir 		DBG_ERROR("Left and right in Ortho definition are identical");
120*cdf0e10cSrcweir 		fLeft -= 1.0;
121*cdf0e10cSrcweir 		fRight += 1.0;
122*cdf0e10cSrcweir 	}
123*cdf0e10cSrcweir 	if(fTop == fBottom)
124*cdf0e10cSrcweir 	{
125*cdf0e10cSrcweir 		DBG_ERROR("Top and bottom in Ortho definition are identical");
126*cdf0e10cSrcweir 		fBottom -= 1.0;
127*cdf0e10cSrcweir 		fTop += 1.0;
128*cdf0e10cSrcweir 	}
129*cdf0e10cSrcweir 	basegfx::B3DHomMatrix aTemp;
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 	aTemp.set(0, 0, 2.0 / (fRight - fLeft));
132*cdf0e10cSrcweir 	aTemp.set(1, 1, 2.0 / (fTop - fBottom));
133*cdf0e10cSrcweir 	aTemp.set(2, 2, -1.0 * (2.0 / (fFar - fNear)));
134*cdf0e10cSrcweir 	aTemp.set(0, 3, -1.0 * ((fRight + fLeft) / (fRight - fLeft)));
135*cdf0e10cSrcweir 	aTemp.set(1, 3, -1.0 * ((fTop + fBottom) / (fTop - fBottom)));
136*cdf0e10cSrcweir 	aTemp.set(2, 3, -1.0 * ((fFar + fNear) / (fFar - fNear)));
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 	rTarget *= aTemp;
139*cdf0e10cSrcweir }
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir /*************************************************************************
142*cdf0e10cSrcweir |*
143*cdf0e10cSrcweir |* Reset der Werte
144*cdf0e10cSrcweir |*
145*cdf0e10cSrcweir \************************************************************************/
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir void B3dTransformationSet::Reset()
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir 	// Matritzen auf Einheitsmatritzen
150*cdf0e10cSrcweir 	maObjectTrans.identity();
151*cdf0e10cSrcweir 	PostSetObjectTrans();
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 	Orientation(maOrientation);
154*cdf0e10cSrcweir 	PostSetOrientation();
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 	maTexture.identity();
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 	mfLeftBound = mfBottomBound = -1.0;
159*cdf0e10cSrcweir 	mfRightBound = mfTopBound = 1.0;
160*cdf0e10cSrcweir 	mfNearBound = 0.001;
161*cdf0e10cSrcweir 	mfFarBound = 1.001;
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 	meRatio = Base3DRatioGrow;
164*cdf0e10cSrcweir 	mfRatio = 0.0;
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 	maViewportRectangle = Rectangle(-1, -1, 2, 2);
167*cdf0e10cSrcweir 	maVisibleRectangle = maViewportRectangle;
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 	mbPerspective = sal_True;
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 	mbProjectionValid = sal_False;
172*cdf0e10cSrcweir 	mbObjectToDeviceValid = sal_False;
173*cdf0e10cSrcweir 	mbWorldToViewValid = sal_False;
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 	CalcViewport();
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir /*************************************************************************
179*cdf0e10cSrcweir |*
180*cdf0e10cSrcweir |* Objekttransformation
181*cdf0e10cSrcweir |*
182*cdf0e10cSrcweir \************************************************************************/
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir void B3dTransformationSet::SetObjectTrans(const basegfx::B3DHomMatrix& rObj)
185*cdf0e10cSrcweir {
186*cdf0e10cSrcweir 	maObjectTrans = rObj;
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 	mbObjectToDeviceValid = sal_False;
189*cdf0e10cSrcweir 	mbInvTransObjectToEyeValid = sal_False;
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 	PostSetObjectTrans();
192*cdf0e10cSrcweir }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir void B3dTransformationSet::PostSetObjectTrans()
195*cdf0e10cSrcweir {
196*cdf0e10cSrcweir 	// Zuweisen und Inverse bestimmen
197*cdf0e10cSrcweir 	maInvObjectTrans = maObjectTrans;
198*cdf0e10cSrcweir 	maInvObjectTrans.invert();
199*cdf0e10cSrcweir }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir /*************************************************************************
202*cdf0e10cSrcweir |*
203*cdf0e10cSrcweir |* Orientierungstransformation
204*cdf0e10cSrcweir |*
205*cdf0e10cSrcweir \************************************************************************/
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir void B3dTransformationSet::SetOrientation( basegfx::B3DPoint aVRP, basegfx::B3DVector aVPN, basegfx::B3DVector aVUP)
208*cdf0e10cSrcweir {
209*cdf0e10cSrcweir 	maOrientation.identity();
210*cdf0e10cSrcweir 	Orientation(maOrientation, aVRP, aVPN, aVUP);
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir 	mbInvTransObjectToEyeValid = sal_False;
213*cdf0e10cSrcweir 	mbObjectToDeviceValid = sal_False;
214*cdf0e10cSrcweir 	mbWorldToViewValid = sal_False;
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 	PostSetOrientation();
217*cdf0e10cSrcweir }
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir void B3dTransformationSet::SetOrientation(basegfx::B3DHomMatrix& mOrient)
220*cdf0e10cSrcweir {
221*cdf0e10cSrcweir 	maOrientation = mOrient;
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 	mbInvTransObjectToEyeValid = sal_False;
224*cdf0e10cSrcweir 	mbObjectToDeviceValid = sal_False;
225*cdf0e10cSrcweir 	mbWorldToViewValid = sal_False;
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir 	PostSetOrientation();
228*cdf0e10cSrcweir }
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir void B3dTransformationSet::PostSetOrientation()
231*cdf0e10cSrcweir {
232*cdf0e10cSrcweir 	// Zuweisen und Inverse bestimmen
233*cdf0e10cSrcweir 	maInvOrientation = maOrientation;
234*cdf0e10cSrcweir 	maInvOrientation.invert();
235*cdf0e10cSrcweir }
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir /*************************************************************************
238*cdf0e10cSrcweir |*
239*cdf0e10cSrcweir |* Projektionstransformation
240*cdf0e10cSrcweir |*
241*cdf0e10cSrcweir \************************************************************************/
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir void B3dTransformationSet::SetProjection(const basegfx::B3DHomMatrix& mProject)
244*cdf0e10cSrcweir {
245*cdf0e10cSrcweir 	maProjection = mProject;
246*cdf0e10cSrcweir 	PostSetProjection();
247*cdf0e10cSrcweir }
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir const basegfx::B3DHomMatrix& B3dTransformationSet::GetProjection()
250*cdf0e10cSrcweir {
251*cdf0e10cSrcweir 	if(!mbProjectionValid)
252*cdf0e10cSrcweir 		CalcViewport();
253*cdf0e10cSrcweir 	return maProjection;
254*cdf0e10cSrcweir }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir const basegfx::B3DHomMatrix& B3dTransformationSet::GetInvProjection()
257*cdf0e10cSrcweir {
258*cdf0e10cSrcweir 	if(!mbProjectionValid)
259*cdf0e10cSrcweir 		CalcViewport();
260*cdf0e10cSrcweir 	return maInvProjection;
261*cdf0e10cSrcweir }
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir void B3dTransformationSet::PostSetProjection()
264*cdf0e10cSrcweir {
265*cdf0e10cSrcweir 	// Zuweisen und Inverse bestimmen
266*cdf0e10cSrcweir 	maInvProjection = GetProjection();
267*cdf0e10cSrcweir 	maInvProjection.invert();
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir 	// Abhaengige Matritzen invalidieren
270*cdf0e10cSrcweir 	mbObjectToDeviceValid = sal_False;
271*cdf0e10cSrcweir 	mbWorldToViewValid = sal_False;
272*cdf0e10cSrcweir }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir /*************************************************************************
275*cdf0e10cSrcweir |*
276*cdf0e10cSrcweir |* Texturtransformation
277*cdf0e10cSrcweir |*
278*cdf0e10cSrcweir \************************************************************************/
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir void B3dTransformationSet::SetTexture(const basegfx::B2DHomMatrix& rTxt)
281*cdf0e10cSrcweir {
282*cdf0e10cSrcweir 	maTexture = rTxt;
283*cdf0e10cSrcweir 	PostSetTexture();
284*cdf0e10cSrcweir }
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir void B3dTransformationSet::PostSetTexture()
287*cdf0e10cSrcweir {
288*cdf0e10cSrcweir }
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir /*************************************************************************
291*cdf0e10cSrcweir |*
292*cdf0e10cSrcweir |* Viewport-Transformation
293*cdf0e10cSrcweir |*
294*cdf0e10cSrcweir \************************************************************************/
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir void B3dTransformationSet::CalcViewport()
297*cdf0e10cSrcweir {
298*cdf0e10cSrcweir 	// Faktoren fuer die Projektion
299*cdf0e10cSrcweir 	double fLeft(mfLeftBound);
300*cdf0e10cSrcweir 	double fRight(mfRightBound);
301*cdf0e10cSrcweir 	double fBottom(mfBottomBound);
302*cdf0e10cSrcweir 	double fTop(mfTopBound);
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir 	// Soll das Seitenverhaeltnis Beachtung finden?
305*cdf0e10cSrcweir 	// Falls ja, Bereich der Projektion an Seitenverhaeltnis anpassen
306*cdf0e10cSrcweir 	if(GetRatio() != 0.0)
307*cdf0e10cSrcweir 	{
308*cdf0e10cSrcweir 		// Berechne aktuelles Seitenverhaeltnis der Bounds
309*cdf0e10cSrcweir 		double fBoundWidth = (double)(maViewportRectangle.GetWidth() + 1);
310*cdf0e10cSrcweir 		double fBoundHeight = (double)(maViewportRectangle.GetHeight() + 1);
311*cdf0e10cSrcweir 		double fActRatio = 1;
312*cdf0e10cSrcweir 		double fFactor;
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir 		if(fBoundWidth != 0.0)
315*cdf0e10cSrcweir 			fActRatio = fBoundHeight / fBoundWidth;
316*cdf0e10cSrcweir 		// FIXME   else in this case has a lot of problems,  should this return.
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir 		switch(meRatio)
319*cdf0e10cSrcweir 		{
320*cdf0e10cSrcweir 			case Base3DRatioShrink :
321*cdf0e10cSrcweir 			{
322*cdf0e10cSrcweir 				// Kleineren Teil vergroessern
323*cdf0e10cSrcweir 				if(fActRatio > mfRatio)
324*cdf0e10cSrcweir 				{
325*cdf0e10cSrcweir 					// X vergroessern
326*cdf0e10cSrcweir 					fFactor = 1.0 / fActRatio;
327*cdf0e10cSrcweir 					fRight	*= fFactor;
328*cdf0e10cSrcweir 					fLeft *= fFactor;
329*cdf0e10cSrcweir 				}
330*cdf0e10cSrcweir 				else
331*cdf0e10cSrcweir 				{
332*cdf0e10cSrcweir 					// Y vergroessern
333*cdf0e10cSrcweir 					fFactor = fActRatio;
334*cdf0e10cSrcweir 					fTop *= fFactor;
335*cdf0e10cSrcweir 					fBottom *= fFactor;
336*cdf0e10cSrcweir 				}
337*cdf0e10cSrcweir 				break;
338*cdf0e10cSrcweir 			}
339*cdf0e10cSrcweir 			case Base3DRatioGrow :
340*cdf0e10cSrcweir 			{
341*cdf0e10cSrcweir 				// GroesserenTeil verkleinern
342*cdf0e10cSrcweir 				if(fActRatio > mfRatio)
343*cdf0e10cSrcweir 				{
344*cdf0e10cSrcweir 					// Y verkleinern
345*cdf0e10cSrcweir 					fFactor = fActRatio;
346*cdf0e10cSrcweir 					fTop *= fFactor;
347*cdf0e10cSrcweir 					fBottom *= fFactor;
348*cdf0e10cSrcweir 				}
349*cdf0e10cSrcweir 				else
350*cdf0e10cSrcweir 				{
351*cdf0e10cSrcweir 					// X verkleinern
352*cdf0e10cSrcweir 					fFactor = 1.0 / fActRatio;
353*cdf0e10cSrcweir 					fRight	*= fFactor;
354*cdf0e10cSrcweir 					fLeft *= fFactor;
355*cdf0e10cSrcweir 				}
356*cdf0e10cSrcweir 				break;
357*cdf0e10cSrcweir 			}
358*cdf0e10cSrcweir 			case Base3DRatioMiddle :
359*cdf0e10cSrcweir 			{
360*cdf0e10cSrcweir 				// Mitteln
361*cdf0e10cSrcweir 				fFactor = ((1.0 / fActRatio) + 1.0) / 2.0;
362*cdf0e10cSrcweir 				fRight *= fFactor;
363*cdf0e10cSrcweir 				fLeft *= fFactor;
364*cdf0e10cSrcweir 				fFactor = (fActRatio + 1.0) / 2.0;
365*cdf0e10cSrcweir 				fTop *= fFactor;
366*cdf0e10cSrcweir 				fBottom *= fFactor;
367*cdf0e10cSrcweir 				break;
368*cdf0e10cSrcweir 			}
369*cdf0e10cSrcweir 		}
370*cdf0e10cSrcweir 	}
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir 	// Ueberschneiden sich Darstellungsflaeche und Objektflaeche?
373*cdf0e10cSrcweir 	maSetBound = maViewportRectangle;
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir 	// Mit den neuen Werten Projektion und ViewPort setzen
376*cdf0e10cSrcweir 	basegfx::B3DHomMatrix aNewProjection;
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir 	// #i36281#
379*cdf0e10cSrcweir 	// OpenGL needs a little more rough additional size to not let
380*cdf0e10cSrcweir 	// the front face vanish. Changed from SMALL_DVALUE to 0.000001,
381*cdf0e10cSrcweir 	// which is 1/10000th, comared with 1/tenth of a million from SMALL_DVALUE.
382*cdf0e10cSrcweir 	const double fDistPart((mfFarBound - mfNearBound) * 0.0001);
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir 	// Near, Far etwas grosszuegiger setzen, um falsches,
385*cdf0e10cSrcweir 	// zu kritisches clippen zu verhindern
386*cdf0e10cSrcweir 	if(mbPerspective)
387*cdf0e10cSrcweir 	{
388*cdf0e10cSrcweir 		Frustum(aNewProjection, fLeft, fRight, fBottom, fTop, mfNearBound - fDistPart, mfFarBound + fDistPart);
389*cdf0e10cSrcweir 	}
390*cdf0e10cSrcweir 	else
391*cdf0e10cSrcweir 	{
392*cdf0e10cSrcweir 		Ortho(aNewProjection, fLeft, fRight, fBottom, fTop, mfNearBound - fDistPart, mfFarBound + fDistPart);
393*cdf0e10cSrcweir 	}
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir 	// jetzt schon auf gueltig setzen um Endlosschleife zu vermeiden
396*cdf0e10cSrcweir 	mbProjectionValid = sal_True;
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir 	// Neue Projektion setzen
399*cdf0e10cSrcweir 	SetProjection(aNewProjection);
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir 	// fill parameters for ViewportTransformation
402*cdf0e10cSrcweir 	// Translation
403*cdf0e10cSrcweir 	maTranslate.setX((double)maSetBound.Left() + ((maSetBound.GetWidth() - 1L) / 2.0));
404*cdf0e10cSrcweir 	maTranslate.setY((double)maSetBound.Top() + ((maSetBound.GetHeight() - 1L) / 2.0));
405*cdf0e10cSrcweir 	maTranslate.setZ(ZBUFFER_DEPTH_RANGE / 2.0);
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir 	// Skalierung
408*cdf0e10cSrcweir 	maScale.setX((maSetBound.GetWidth() - 1L) / 2.0);
409*cdf0e10cSrcweir 	maScale.setY((maSetBound.GetHeight() - 1L) / -2.0);
410*cdf0e10cSrcweir 	maScale.setZ(ZBUFFER_DEPTH_RANGE / 2.0);
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir 	// Auf Veraenderung des ViewPorts reagieren
413*cdf0e10cSrcweir 	PostSetViewport();
414*cdf0e10cSrcweir }
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir void B3dTransformationSet::SetRatio(double fNew)
417*cdf0e10cSrcweir {
418*cdf0e10cSrcweir 	if(mfRatio != fNew)
419*cdf0e10cSrcweir 	{
420*cdf0e10cSrcweir 		mfRatio = fNew;
421*cdf0e10cSrcweir 		mbProjectionValid = sal_False;
422*cdf0e10cSrcweir 		mbObjectToDeviceValid = sal_False;
423*cdf0e10cSrcweir 		mbWorldToViewValid = sal_False;
424*cdf0e10cSrcweir 	}
425*cdf0e10cSrcweir }
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir void B3dTransformationSet::SetRatioMode(Base3DRatio eNew)
428*cdf0e10cSrcweir {
429*cdf0e10cSrcweir 	if(meRatio != eNew)
430*cdf0e10cSrcweir 	{
431*cdf0e10cSrcweir 		meRatio = eNew;
432*cdf0e10cSrcweir 		mbProjectionValid = sal_False;
433*cdf0e10cSrcweir 		mbObjectToDeviceValid = sal_False;
434*cdf0e10cSrcweir 		mbWorldToViewValid = sal_False;
435*cdf0e10cSrcweir 	}
436*cdf0e10cSrcweir }
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir void B3dTransformationSet::SetDeviceRectangle(double fL, double fR, double fB, double fT,
439*cdf0e10cSrcweir 	sal_Bool bBroadCastChange)
440*cdf0e10cSrcweir {
441*cdf0e10cSrcweir 	if(fL != mfLeftBound || fR != mfRightBound || fB != mfBottomBound || fT != mfTopBound)
442*cdf0e10cSrcweir 	{
443*cdf0e10cSrcweir 		mfLeftBound = fL;
444*cdf0e10cSrcweir 		mfRightBound = fR;
445*cdf0e10cSrcweir 		mfBottomBound = fB;
446*cdf0e10cSrcweir 		mfTopBound = fT;
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir 		mbProjectionValid = sal_False;
449*cdf0e10cSrcweir 		mbObjectToDeviceValid = sal_False;
450*cdf0e10cSrcweir 		mbWorldToViewValid = sal_False;
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir 		// Aenderung bekanntmachen
453*cdf0e10cSrcweir 		if(bBroadCastChange)
454*cdf0e10cSrcweir 			DeviceRectangleChange();
455*cdf0e10cSrcweir 	}
456*cdf0e10cSrcweir }
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir void B3dTransformationSet::SetDeviceVolume(const basegfx::B3DRange& rVol, sal_Bool bBroadCastChange)
459*cdf0e10cSrcweir {
460*cdf0e10cSrcweir 	SetDeviceRectangle(rVol.getMinX(), rVol.getMaxX(), rVol.getMinY(), rVol.getMaxY(), bBroadCastChange);
461*cdf0e10cSrcweir 	SetFrontClippingPlane(rVol.getMinZ());
462*cdf0e10cSrcweir 	SetBackClippingPlane(rVol.getMaxZ());
463*cdf0e10cSrcweir }
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir void B3dTransformationSet::DeviceRectangleChange()
466*cdf0e10cSrcweir {
467*cdf0e10cSrcweir }
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir void B3dTransformationSet::GetDeviceRectangle(double &fL, double &fR, double& fB, double& fT)
470*cdf0e10cSrcweir {
471*cdf0e10cSrcweir 	fL = mfLeftBound;
472*cdf0e10cSrcweir 	fR = mfRightBound;
473*cdf0e10cSrcweir 	fB = mfBottomBound;
474*cdf0e10cSrcweir 	fT = mfTopBound;
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir 	mbProjectionValid = sal_False;
477*cdf0e10cSrcweir 	mbObjectToDeviceValid = sal_False;
478*cdf0e10cSrcweir 	mbWorldToViewValid = sal_False;
479*cdf0e10cSrcweir }
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir basegfx::B3DRange B3dTransformationSet::GetDeviceVolume()
482*cdf0e10cSrcweir {
483*cdf0e10cSrcweir 	basegfx::B3DRange aRet;
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir 	aRet.expand(basegfx::B3DTuple(mfLeftBound, mfBottomBound, mfNearBound));
486*cdf0e10cSrcweir 	aRet.expand(basegfx::B3DTuple(mfRightBound, mfTopBound, mfFarBound));
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir 	return aRet;
489*cdf0e10cSrcweir }
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir void B3dTransformationSet::SetFrontClippingPlane(double fF)
492*cdf0e10cSrcweir {
493*cdf0e10cSrcweir 	if(mfNearBound != fF)
494*cdf0e10cSrcweir 	{
495*cdf0e10cSrcweir 		mfNearBound = fF;
496*cdf0e10cSrcweir 		mbProjectionValid = sal_False;
497*cdf0e10cSrcweir 		mbObjectToDeviceValid = sal_False;
498*cdf0e10cSrcweir 		mbWorldToViewValid = sal_False;
499*cdf0e10cSrcweir 	}
500*cdf0e10cSrcweir }
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir void B3dTransformationSet::SetBackClippingPlane(double fB)
503*cdf0e10cSrcweir {
504*cdf0e10cSrcweir 	if(mfFarBound != fB)
505*cdf0e10cSrcweir 	{
506*cdf0e10cSrcweir 		mfFarBound = fB;
507*cdf0e10cSrcweir 		mbProjectionValid = sal_False;
508*cdf0e10cSrcweir 		mbObjectToDeviceValid = sal_False;
509*cdf0e10cSrcweir 		mbWorldToViewValid = sal_False;
510*cdf0e10cSrcweir 	}
511*cdf0e10cSrcweir }
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir void B3dTransformationSet::SetPerspective(sal_Bool bNew)
514*cdf0e10cSrcweir {
515*cdf0e10cSrcweir 	if(mbPerspective != bNew)
516*cdf0e10cSrcweir 	{
517*cdf0e10cSrcweir 		mbPerspective = bNew;
518*cdf0e10cSrcweir 		mbProjectionValid = sal_False;
519*cdf0e10cSrcweir 		mbObjectToDeviceValid = sal_False;
520*cdf0e10cSrcweir 		mbWorldToViewValid = sal_False;
521*cdf0e10cSrcweir 	}
522*cdf0e10cSrcweir }
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir void B3dTransformationSet::SetViewportRectangle(Rectangle& rRect, Rectangle& rVisible)
525*cdf0e10cSrcweir {
526*cdf0e10cSrcweir 	if(rRect != maViewportRectangle || rVisible != maVisibleRectangle)
527*cdf0e10cSrcweir 	{
528*cdf0e10cSrcweir 		maViewportRectangle = rRect;
529*cdf0e10cSrcweir 		maVisibleRectangle = rVisible;
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir 		mbProjectionValid = sal_False;
532*cdf0e10cSrcweir 		mbObjectToDeviceValid = sal_False;
533*cdf0e10cSrcweir 		mbWorldToViewValid = sal_False;
534*cdf0e10cSrcweir 	}
535*cdf0e10cSrcweir }
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir void B3dTransformationSet::PostSetViewport()
538*cdf0e10cSrcweir {
539*cdf0e10cSrcweir }
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir const Rectangle& B3dTransformationSet::GetLogicalViewportBounds()
542*cdf0e10cSrcweir {
543*cdf0e10cSrcweir 	if(!mbProjectionValid)
544*cdf0e10cSrcweir 		CalcViewport();
545*cdf0e10cSrcweir 	return maSetBound;
546*cdf0e10cSrcweir }
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir const basegfx::B3DVector& B3dTransformationSet::GetScale()
549*cdf0e10cSrcweir {
550*cdf0e10cSrcweir 	if(!mbProjectionValid)
551*cdf0e10cSrcweir 		CalcViewport();
552*cdf0e10cSrcweir 	return maScale;
553*cdf0e10cSrcweir }
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir const basegfx::B3DVector& B3dTransformationSet::GetTranslate()
556*cdf0e10cSrcweir {
557*cdf0e10cSrcweir 	if(!mbProjectionValid)
558*cdf0e10cSrcweir 		CalcViewport();
559*cdf0e10cSrcweir 	return maTranslate;
560*cdf0e10cSrcweir }
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir /*************************************************************************
563*cdf0e10cSrcweir |*
564*cdf0e10cSrcweir |* Hilfsmatrixberechnungsroutinen
565*cdf0e10cSrcweir |*
566*cdf0e10cSrcweir \************************************************************************/
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir void B3dTransformationSet::CalcMatObjectToDevice()
569*cdf0e10cSrcweir {
570*cdf0e10cSrcweir 	// ObjectToDevice berechnen (Orientation * Projection * Object)
571*cdf0e10cSrcweir 	maObjectToDevice = maObjectTrans;
572*cdf0e10cSrcweir 	maObjectToDevice *= maOrientation;
573*cdf0e10cSrcweir 	maObjectToDevice *= GetProjection();
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir 	// auf gueltig setzen
576*cdf0e10cSrcweir 	mbObjectToDeviceValid = sal_True;
577*cdf0e10cSrcweir }
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir const basegfx::B3DHomMatrix& B3dTransformationSet::GetObjectToDevice()
580*cdf0e10cSrcweir {
581*cdf0e10cSrcweir 	if(!mbObjectToDeviceValid)
582*cdf0e10cSrcweir 		CalcMatObjectToDevice();
583*cdf0e10cSrcweir 	return maObjectToDevice;
584*cdf0e10cSrcweir }
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir void B3dTransformationSet::CalcMatInvTransObjectToEye()
587*cdf0e10cSrcweir {
588*cdf0e10cSrcweir 	maInvTransObjectToEye = maObjectTrans;
589*cdf0e10cSrcweir 	maInvTransObjectToEye *= maOrientation;
590*cdf0e10cSrcweir 	maInvTransObjectToEye.invert();
591*cdf0e10cSrcweir 	maInvTransObjectToEye.transpose();
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir 	// eventuelle Translationen rausschmeissen, da diese
594*cdf0e10cSrcweir 	// Matrix nur zur Transformation von Vektoren gedacht ist
595*cdf0e10cSrcweir 	maInvTransObjectToEye.set(3, 0, 0.0);
596*cdf0e10cSrcweir 	maInvTransObjectToEye.set(3, 1, 0.0);
597*cdf0e10cSrcweir 	maInvTransObjectToEye.set(3, 2, 0.0);
598*cdf0e10cSrcweir 	maInvTransObjectToEye.set(3, 3, 1.0);
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir 	// auf gueltig setzen
601*cdf0e10cSrcweir 	mbInvTransObjectToEyeValid = sal_True;
602*cdf0e10cSrcweir }
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir const basegfx::B3DHomMatrix& B3dTransformationSet::GetInvTransObjectToEye()
605*cdf0e10cSrcweir {
606*cdf0e10cSrcweir 	if(!mbInvTransObjectToEyeValid)
607*cdf0e10cSrcweir 		CalcMatInvTransObjectToEye();
608*cdf0e10cSrcweir 	return maInvTransObjectToEye;
609*cdf0e10cSrcweir }
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir basegfx::B3DHomMatrix B3dTransformationSet::GetMatFromObjectToView()
612*cdf0e10cSrcweir {
613*cdf0e10cSrcweir 	basegfx::B3DHomMatrix aFromObjectToView = GetObjectToDevice();
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir 	const basegfx::B3DVector& rScale(GetScale());
616*cdf0e10cSrcweir 	aFromObjectToView.scale(rScale.getX(), rScale.getY(), rScale.getZ());
617*cdf0e10cSrcweir 	const basegfx::B3DVector& rTranslate(GetTranslate());
618*cdf0e10cSrcweir 	aFromObjectToView.translate(rTranslate.getX(), rTranslate.getY(), rTranslate.getZ());
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir 	return aFromObjectToView;
621*cdf0e10cSrcweir }
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir void B3dTransformationSet::CalcMatFromWorldToView()
624*cdf0e10cSrcweir {
625*cdf0e10cSrcweir 	maMatFromWorldToView = maOrientation;
626*cdf0e10cSrcweir 	maMatFromWorldToView *= GetProjection();
627*cdf0e10cSrcweir 	const basegfx::B3DVector& rScale(GetScale());
628*cdf0e10cSrcweir 	maMatFromWorldToView.scale(rScale.getX(), rScale.getY(), rScale.getZ());
629*cdf0e10cSrcweir 	const basegfx::B3DVector& rTranslate(GetTranslate());
630*cdf0e10cSrcweir 	maMatFromWorldToView.translate(rTranslate.getX(), rTranslate.getY(), rTranslate.getZ());
631*cdf0e10cSrcweir 	maInvMatFromWorldToView = maMatFromWorldToView;
632*cdf0e10cSrcweir 	maInvMatFromWorldToView.invert();
633*cdf0e10cSrcweir 
634*cdf0e10cSrcweir 	// gueltig setzen
635*cdf0e10cSrcweir 	mbWorldToViewValid = sal_True;
636*cdf0e10cSrcweir }
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir const basegfx::B3DHomMatrix& B3dTransformationSet::GetMatFromWorldToView()
639*cdf0e10cSrcweir {
640*cdf0e10cSrcweir 	if(!mbWorldToViewValid)
641*cdf0e10cSrcweir 		CalcMatFromWorldToView();
642*cdf0e10cSrcweir 	return maMatFromWorldToView;
643*cdf0e10cSrcweir }
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir const basegfx::B3DHomMatrix& B3dTransformationSet::GetInvMatFromWorldToView()
646*cdf0e10cSrcweir {
647*cdf0e10cSrcweir 	if(!mbWorldToViewValid)
648*cdf0e10cSrcweir 		CalcMatFromWorldToView();
649*cdf0e10cSrcweir 	return maInvMatFromWorldToView;
650*cdf0e10cSrcweir }
651*cdf0e10cSrcweir 
652*cdf0e10cSrcweir /*************************************************************************
653*cdf0e10cSrcweir |*
654*cdf0e10cSrcweir |* Direkter Zugriff auf verschiedene Transformationen
655*cdf0e10cSrcweir |*
656*cdf0e10cSrcweir \************************************************************************/
657*cdf0e10cSrcweir 
658*cdf0e10cSrcweir const basegfx::B3DPoint B3dTransformationSet::WorldToEyeCoor(const basegfx::B3DPoint& rVec)
659*cdf0e10cSrcweir {
660*cdf0e10cSrcweir 	basegfx::B3DPoint aVec(rVec);
661*cdf0e10cSrcweir 	aVec *= GetOrientation();
662*cdf0e10cSrcweir 	return aVec;
663*cdf0e10cSrcweir }
664*cdf0e10cSrcweir 
665*cdf0e10cSrcweir const basegfx::B3DPoint B3dTransformationSet::EyeToWorldCoor(const basegfx::B3DPoint& rVec)
666*cdf0e10cSrcweir {
667*cdf0e10cSrcweir 	basegfx::B3DPoint aVec(rVec);
668*cdf0e10cSrcweir 	aVec *= GetInvOrientation();
669*cdf0e10cSrcweir 	return aVec;
670*cdf0e10cSrcweir }
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir const basegfx::B3DPoint B3dTransformationSet::EyeToViewCoor(const basegfx::B3DPoint& rVec)
673*cdf0e10cSrcweir {
674*cdf0e10cSrcweir 	basegfx::B3DPoint aVec(rVec);
675*cdf0e10cSrcweir 	aVec *= GetProjection();
676*cdf0e10cSrcweir 	aVec *= GetScale();
677*cdf0e10cSrcweir 	aVec += GetTranslate();
678*cdf0e10cSrcweir 	return aVec;
679*cdf0e10cSrcweir }
680*cdf0e10cSrcweir 
681*cdf0e10cSrcweir const basegfx::B3DPoint B3dTransformationSet::ViewToEyeCoor(const basegfx::B3DPoint& rVec)
682*cdf0e10cSrcweir {
683*cdf0e10cSrcweir 	basegfx::B3DPoint aVec(rVec);
684*cdf0e10cSrcweir 	aVec -= GetTranslate();
685*cdf0e10cSrcweir 	aVec = aVec / GetScale();
686*cdf0e10cSrcweir 	aVec *= GetInvProjection();
687*cdf0e10cSrcweir 	return aVec;
688*cdf0e10cSrcweir }
689*cdf0e10cSrcweir 
690*cdf0e10cSrcweir const basegfx::B3DPoint B3dTransformationSet::WorldToViewCoor(const basegfx::B3DPoint& rVec)
691*cdf0e10cSrcweir {
692*cdf0e10cSrcweir 	basegfx::B3DPoint aVec(rVec);
693*cdf0e10cSrcweir 	aVec *= GetMatFromWorldToView();
694*cdf0e10cSrcweir 	return aVec;
695*cdf0e10cSrcweir }
696*cdf0e10cSrcweir 
697*cdf0e10cSrcweir const basegfx::B3DPoint B3dTransformationSet::ViewToWorldCoor(const basegfx::B3DPoint& rVec)
698*cdf0e10cSrcweir {
699*cdf0e10cSrcweir 	basegfx::B3DPoint aVec(rVec);
700*cdf0e10cSrcweir 	aVec *= GetInvMatFromWorldToView();
701*cdf0e10cSrcweir 	return aVec;
702*cdf0e10cSrcweir }
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir const basegfx::B3DPoint B3dTransformationSet::DeviceToViewCoor(const basegfx::B3DPoint& rVec)
705*cdf0e10cSrcweir {
706*cdf0e10cSrcweir 	basegfx::B3DPoint aVec(rVec);
707*cdf0e10cSrcweir 	aVec *= GetScale();
708*cdf0e10cSrcweir 	aVec += GetTranslate();
709*cdf0e10cSrcweir 	return aVec;
710*cdf0e10cSrcweir }
711*cdf0e10cSrcweir 
712*cdf0e10cSrcweir const basegfx::B3DPoint B3dTransformationSet::ViewToDeviceCoor(const basegfx::B3DPoint& rVec)
713*cdf0e10cSrcweir {
714*cdf0e10cSrcweir 	basegfx::B3DPoint aVec(rVec);
715*cdf0e10cSrcweir 	aVec -= GetTranslate();
716*cdf0e10cSrcweir 	aVec = aVec / GetScale();
717*cdf0e10cSrcweir 	return aVec;
718*cdf0e10cSrcweir }
719*cdf0e10cSrcweir 
720*cdf0e10cSrcweir const basegfx::B3DPoint B3dTransformationSet::ObjectToWorldCoor(const basegfx::B3DPoint& rVec)
721*cdf0e10cSrcweir {
722*cdf0e10cSrcweir 	basegfx::B3DPoint aVec(rVec);
723*cdf0e10cSrcweir 	aVec *= GetObjectTrans();
724*cdf0e10cSrcweir 	return aVec;
725*cdf0e10cSrcweir }
726*cdf0e10cSrcweir 
727*cdf0e10cSrcweir const basegfx::B3DPoint B3dTransformationSet::WorldToObjectCoor(const basegfx::B3DPoint& rVec)
728*cdf0e10cSrcweir {
729*cdf0e10cSrcweir 	basegfx::B3DPoint aVec(rVec);
730*cdf0e10cSrcweir 	aVec *= GetInvObjectTrans();
731*cdf0e10cSrcweir 	return aVec;
732*cdf0e10cSrcweir }
733*cdf0e10cSrcweir 
734*cdf0e10cSrcweir const basegfx::B3DPoint B3dTransformationSet::ObjectToViewCoor(const basegfx::B3DPoint& rVec)
735*cdf0e10cSrcweir {
736*cdf0e10cSrcweir 	basegfx::B3DPoint aVec(rVec);
737*cdf0e10cSrcweir 	aVec *= GetObjectTrans();
738*cdf0e10cSrcweir 	aVec *= GetMatFromWorldToView();
739*cdf0e10cSrcweir 	return aVec;
740*cdf0e10cSrcweir }
741*cdf0e10cSrcweir 
742*cdf0e10cSrcweir const basegfx::B3DPoint B3dTransformationSet::ViewToObjectCoor(const basegfx::B3DPoint& rVec)
743*cdf0e10cSrcweir {
744*cdf0e10cSrcweir 	basegfx::B3DPoint aVec(rVec);
745*cdf0e10cSrcweir 	aVec *= GetInvMatFromWorldToView();
746*cdf0e10cSrcweir 	aVec *= GetInvObjectTrans();
747*cdf0e10cSrcweir 	return aVec;
748*cdf0e10cSrcweir }
749*cdf0e10cSrcweir 
750*cdf0e10cSrcweir const basegfx::B3DPoint B3dTransformationSet::ObjectToEyeCoor(const basegfx::B3DPoint& rVec)
751*cdf0e10cSrcweir {
752*cdf0e10cSrcweir 	basegfx::B3DPoint aVec(rVec);
753*cdf0e10cSrcweir 	aVec *= GetObjectTrans();
754*cdf0e10cSrcweir 	aVec *= GetOrientation();
755*cdf0e10cSrcweir 	return aVec;
756*cdf0e10cSrcweir }
757*cdf0e10cSrcweir 
758*cdf0e10cSrcweir const basegfx::B3DPoint B3dTransformationSet::EyeToObjectCoor(const basegfx::B3DPoint& rVec)
759*cdf0e10cSrcweir {
760*cdf0e10cSrcweir 	basegfx::B3DPoint aVec(rVec);
761*cdf0e10cSrcweir 	aVec *= GetInvOrientation();
762*cdf0e10cSrcweir 	aVec *= GetInvObjectTrans();
763*cdf0e10cSrcweir 	return aVec;
764*cdf0e10cSrcweir }
765*cdf0e10cSrcweir 
766*cdf0e10cSrcweir const basegfx::B3DPoint B3dTransformationSet::DeviceToEyeCoor(const basegfx::B3DPoint& rVec)
767*cdf0e10cSrcweir {
768*cdf0e10cSrcweir 	basegfx::B3DPoint aVec(rVec);
769*cdf0e10cSrcweir 	aVec *= GetInvProjection();
770*cdf0e10cSrcweir 	return aVec;
771*cdf0e10cSrcweir }
772*cdf0e10cSrcweir 
773*cdf0e10cSrcweir const basegfx::B3DPoint B3dTransformationSet::EyeToDeviceCoor(const basegfx::B3DPoint& rVec)
774*cdf0e10cSrcweir {
775*cdf0e10cSrcweir 	basegfx::B3DPoint aVec(rVec);
776*cdf0e10cSrcweir 	aVec *= GetProjection();
777*cdf0e10cSrcweir 	return aVec;
778*cdf0e10cSrcweir }
779*cdf0e10cSrcweir 
780*cdf0e10cSrcweir const basegfx::B3DPoint B3dTransformationSet::InvTransObjectToEye(const basegfx::B3DPoint& rVec)
781*cdf0e10cSrcweir {
782*cdf0e10cSrcweir 	basegfx::B3DPoint aVec(rVec);
783*cdf0e10cSrcweir 	aVec *= GetInvTransObjectToEye();
784*cdf0e10cSrcweir 	return aVec;
785*cdf0e10cSrcweir }
786*cdf0e10cSrcweir 
787*cdf0e10cSrcweir const basegfx::B2DPoint B3dTransformationSet::TransTextureCoor(const basegfx::B2DPoint& rVec)
788*cdf0e10cSrcweir {
789*cdf0e10cSrcweir 	basegfx::B2DPoint aVec(rVec);
790*cdf0e10cSrcweir 	aVec *= GetTexture();
791*cdf0e10cSrcweir 	return aVec;
792*cdf0e10cSrcweir }
793*cdf0e10cSrcweir 
794*cdf0e10cSrcweir /*************************************************************************
795*cdf0e10cSrcweir |*
796*cdf0e10cSrcweir |* Konstruktor B3dViewport
797*cdf0e10cSrcweir |*
798*cdf0e10cSrcweir \************************************************************************/
799*cdf0e10cSrcweir 
800*cdf0e10cSrcweir B3dViewport::B3dViewport()
801*cdf0e10cSrcweir :	B3dTransformationSet(),
802*cdf0e10cSrcweir 	aVRP(0, 0, 0),
803*cdf0e10cSrcweir 	aVPN(0, 0, 1),
804*cdf0e10cSrcweir 	aVUV(0, 1, 0)
805*cdf0e10cSrcweir {
806*cdf0e10cSrcweir 	CalcOrientation();
807*cdf0e10cSrcweir }
808*cdf0e10cSrcweir 
809*cdf0e10cSrcweir B3dViewport::~B3dViewport()
810*cdf0e10cSrcweir {
811*cdf0e10cSrcweir }
812*cdf0e10cSrcweir 
813*cdf0e10cSrcweir void B3dViewport::SetVRP(const basegfx::B3DPoint& rNewVRP)
814*cdf0e10cSrcweir {
815*cdf0e10cSrcweir 	aVRP = rNewVRP;
816*cdf0e10cSrcweir 	CalcOrientation();
817*cdf0e10cSrcweir }
818*cdf0e10cSrcweir 
819*cdf0e10cSrcweir void B3dViewport::SetVPN(const basegfx::B3DVector& rNewVPN)
820*cdf0e10cSrcweir {
821*cdf0e10cSrcweir 	aVPN = rNewVPN;
822*cdf0e10cSrcweir 	CalcOrientation();
823*cdf0e10cSrcweir }
824*cdf0e10cSrcweir 
825*cdf0e10cSrcweir void B3dViewport::SetVUV(const basegfx::B3DVector& rNewVUV)
826*cdf0e10cSrcweir {
827*cdf0e10cSrcweir 	aVUV = rNewVUV;
828*cdf0e10cSrcweir 	CalcOrientation();
829*cdf0e10cSrcweir }
830*cdf0e10cSrcweir 
831*cdf0e10cSrcweir void B3dViewport::SetViewportValues(
832*cdf0e10cSrcweir 	const basegfx::B3DPoint& rNewVRP,
833*cdf0e10cSrcweir 	const basegfx::B3DVector& rNewVPN,
834*cdf0e10cSrcweir 	const basegfx::B3DVector& rNewVUV)
835*cdf0e10cSrcweir {
836*cdf0e10cSrcweir 	aVRP = rNewVRP;
837*cdf0e10cSrcweir 	aVPN = rNewVPN;
838*cdf0e10cSrcweir 	aVUV = rNewVUV;
839*cdf0e10cSrcweir 	CalcOrientation();
840*cdf0e10cSrcweir }
841*cdf0e10cSrcweir 
842*cdf0e10cSrcweir void B3dViewport::CalcOrientation()
843*cdf0e10cSrcweir {
844*cdf0e10cSrcweir 	SetOrientation(aVRP, aVPN, aVUV);
845*cdf0e10cSrcweir }
846*cdf0e10cSrcweir 
847*cdf0e10cSrcweir /*************************************************************************
848*cdf0e10cSrcweir |*
849*cdf0e10cSrcweir |* Konstruktor B3dViewport
850*cdf0e10cSrcweir |*
851*cdf0e10cSrcweir \************************************************************************/
852*cdf0e10cSrcweir 
853*cdf0e10cSrcweir B3dCamera::B3dCamera(
854*cdf0e10cSrcweir 	const basegfx::B3DPoint& rPos, const basegfx::B3DVector& rLkAt,
855*cdf0e10cSrcweir 	double fFocLen, double fBnkAng, sal_Bool bUseFocLen)
856*cdf0e10cSrcweir :	B3dViewport(),
857*cdf0e10cSrcweir 	aPosition(rPos),
858*cdf0e10cSrcweir 	aCorrectedPosition(rPos),
859*cdf0e10cSrcweir 	aLookAt(rLkAt),
860*cdf0e10cSrcweir 	fFocalLength(fFocLen),
861*cdf0e10cSrcweir 	fBankAngle(fBnkAng),
862*cdf0e10cSrcweir 	bUseFocalLength(bUseFocLen)
863*cdf0e10cSrcweir {
864*cdf0e10cSrcweir 	CalcNewViewportValues();
865*cdf0e10cSrcweir }
866*cdf0e10cSrcweir 
867*cdf0e10cSrcweir B3dCamera::~B3dCamera()
868*cdf0e10cSrcweir {
869*cdf0e10cSrcweir }
870*cdf0e10cSrcweir 
871*cdf0e10cSrcweir void B3dCamera::SetPosition(const basegfx::B3DPoint& rNewPos)
872*cdf0e10cSrcweir {
873*cdf0e10cSrcweir 	if(rNewPos != aPosition)
874*cdf0e10cSrcweir 	{
875*cdf0e10cSrcweir 		// Zuweisen
876*cdf0e10cSrcweir 		aCorrectedPosition = aPosition = rNewPos;
877*cdf0e10cSrcweir 
878*cdf0e10cSrcweir 		// Neuberechnung
879*cdf0e10cSrcweir 		CalcNewViewportValues();
880*cdf0e10cSrcweir 	}
881*cdf0e10cSrcweir }
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir void B3dCamera::SetLookAt(const basegfx::B3DVector& rNewLookAt)
884*cdf0e10cSrcweir {
885*cdf0e10cSrcweir 	if(rNewLookAt != aLookAt)
886*cdf0e10cSrcweir 	{
887*cdf0e10cSrcweir 		// Zuweisen
888*cdf0e10cSrcweir 		aLookAt = rNewLookAt;
889*cdf0e10cSrcweir 
890*cdf0e10cSrcweir 		// Neuberechnung
891*cdf0e10cSrcweir 		CalcNewViewportValues();
892*cdf0e10cSrcweir 	}
893*cdf0e10cSrcweir }
894*cdf0e10cSrcweir 
895*cdf0e10cSrcweir void B3dCamera::SetPositionAndLookAt(const basegfx::B3DPoint& rNewPos, const basegfx::B3DVector& rNewLookAt)
896*cdf0e10cSrcweir {
897*cdf0e10cSrcweir 	if(rNewPos != aPosition || rNewLookAt != aLookAt)
898*cdf0e10cSrcweir 	{
899*cdf0e10cSrcweir 		// Zuweisen
900*cdf0e10cSrcweir 		aPosition = rNewPos;
901*cdf0e10cSrcweir 		aLookAt = rNewLookAt;
902*cdf0e10cSrcweir 
903*cdf0e10cSrcweir 		// Neuberechnung
904*cdf0e10cSrcweir 		CalcNewViewportValues();
905*cdf0e10cSrcweir 	}
906*cdf0e10cSrcweir }
907*cdf0e10cSrcweir 
908*cdf0e10cSrcweir void B3dCamera::SetFocalLength(double fLen)
909*cdf0e10cSrcweir {
910*cdf0e10cSrcweir 	if(fLen != fFocalLength)
911*cdf0e10cSrcweir 	{
912*cdf0e10cSrcweir 		// Zuweisen
913*cdf0e10cSrcweir 		if(fLen < 5.0)
914*cdf0e10cSrcweir 			fLen = 5.0;
915*cdf0e10cSrcweir 		fFocalLength = fLen;
916*cdf0e10cSrcweir 
917*cdf0e10cSrcweir 		// Neuberechnung
918*cdf0e10cSrcweir 		CalcNewViewportValues();
919*cdf0e10cSrcweir 	}
920*cdf0e10cSrcweir }
921*cdf0e10cSrcweir 
922*cdf0e10cSrcweir void B3dCamera::SetBankAngle(double fAngle)
923*cdf0e10cSrcweir {
924*cdf0e10cSrcweir 	if(fAngle != fBankAngle)
925*cdf0e10cSrcweir 	{
926*cdf0e10cSrcweir 		// Zuweisen
927*cdf0e10cSrcweir 		fBankAngle = fAngle;
928*cdf0e10cSrcweir 
929*cdf0e10cSrcweir 		// Neuberechnung
930*cdf0e10cSrcweir 		CalcNewViewportValues();
931*cdf0e10cSrcweir 	}
932*cdf0e10cSrcweir }
933*cdf0e10cSrcweir 
934*cdf0e10cSrcweir void B3dCamera::SetUseFocalLength(sal_Bool bNew)
935*cdf0e10cSrcweir {
936*cdf0e10cSrcweir 	if(bNew != (sal_Bool)bUseFocalLength)
937*cdf0e10cSrcweir 	{
938*cdf0e10cSrcweir 		// Zuweisen
939*cdf0e10cSrcweir 		bUseFocalLength = bNew;
940*cdf0e10cSrcweir 
941*cdf0e10cSrcweir 		// Neuberechnung
942*cdf0e10cSrcweir 		CalcNewViewportValues();
943*cdf0e10cSrcweir 	}
944*cdf0e10cSrcweir }
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir void B3dCamera::DeviceRectangleChange()
947*cdf0e10cSrcweir {
948*cdf0e10cSrcweir 	// call parent
949*cdf0e10cSrcweir 	B3dViewport::DeviceRectangleChange();
950*cdf0e10cSrcweir 
951*cdf0e10cSrcweir 	// Auf Aenderung reagieren
952*cdf0e10cSrcweir 	CalcNewViewportValues();
953*cdf0e10cSrcweir }
954*cdf0e10cSrcweir 
955*cdf0e10cSrcweir void B3dCamera::CalcNewViewportValues()
956*cdf0e10cSrcweir {
957*cdf0e10cSrcweir 	basegfx::B3DVector aViewVector(aPosition - aLookAt);
958*cdf0e10cSrcweir 	basegfx::B3DVector aNewVPN(aViewVector);
959*cdf0e10cSrcweir 
960*cdf0e10cSrcweir 	basegfx::B3DVector aNewVUV(0.0, 1.0, 0.0);
961*cdf0e10cSrcweir 	if(aNewVPN.getLength() < aNewVPN.getY())
962*cdf0e10cSrcweir 		aNewVUV.setX(0.5);
963*cdf0e10cSrcweir 
964*cdf0e10cSrcweir 	aNewVUV.normalize();
965*cdf0e10cSrcweir 	aNewVPN.normalize();
966*cdf0e10cSrcweir 
967*cdf0e10cSrcweir 	basegfx::B3DVector aNewToTheRight = aNewVPN;
968*cdf0e10cSrcweir 	aNewToTheRight = aNewToTheRight.getPerpendicular(aNewVUV);
969*cdf0e10cSrcweir 	aNewToTheRight.normalize();
970*cdf0e10cSrcweir 	aNewVUV = aNewToTheRight.getPerpendicular(aNewVPN);
971*cdf0e10cSrcweir 	aNewVUV.normalize();
972*cdf0e10cSrcweir 
973*cdf0e10cSrcweir 	SetViewportValues(aPosition, aNewVPN, aNewVUV);
974*cdf0e10cSrcweir 	if(CalcFocalLength())
975*cdf0e10cSrcweir 		SetViewportValues(aCorrectedPosition, aNewVPN, aNewVUV);
976*cdf0e10cSrcweir 
977*cdf0e10cSrcweir 	if(fBankAngle != 0.0)
978*cdf0e10cSrcweir 	{
979*cdf0e10cSrcweir 		basegfx::B3DHomMatrix aRotMat;
980*cdf0e10cSrcweir 		aRotMat.rotate(0.0, 0.0, fBankAngle);
981*cdf0e10cSrcweir 		basegfx::B3DVector aUp(0.0, 1.0, 0.0);
982*cdf0e10cSrcweir 		aUp *= aRotMat;
983*cdf0e10cSrcweir 		aUp = EyeToWorldCoor(aUp);
984*cdf0e10cSrcweir 		aUp.normalize();
985*cdf0e10cSrcweir 		SetVUV(aUp);
986*cdf0e10cSrcweir 	}
987*cdf0e10cSrcweir }
988*cdf0e10cSrcweir 
989*cdf0e10cSrcweir sal_Bool B3dCamera::CalcFocalLength()
990*cdf0e10cSrcweir {
991*cdf0e10cSrcweir 	double fWidth = GetDeviceRectangleWidth();
992*cdf0e10cSrcweir 	sal_Bool bRetval = sal_False;
993*cdf0e10cSrcweir 
994*cdf0e10cSrcweir 	if(bUseFocalLength)
995*cdf0e10cSrcweir 	{
996*cdf0e10cSrcweir 		// Position aufgrund der FocalLength korrigieren
997*cdf0e10cSrcweir 		aCorrectedPosition = basegfx::B3DPoint(0.0, 0.0, fFocalLength * fWidth / 35.0);
998*cdf0e10cSrcweir 		aCorrectedPosition = EyeToWorldCoor(aCorrectedPosition);
999*cdf0e10cSrcweir 		bRetval = sal_True;
1000*cdf0e10cSrcweir 	}
1001*cdf0e10cSrcweir 	else
1002*cdf0e10cSrcweir 	{
1003*cdf0e10cSrcweir 		// FocalLength anhand der Position anpassen
1004*cdf0e10cSrcweir 		basegfx::B3DPoint aOldPosition;
1005*cdf0e10cSrcweir 		aOldPosition = WorldToEyeCoor(aOldPosition);
1006*cdf0e10cSrcweir 		if(fWidth != 0.0)
1007*cdf0e10cSrcweir 			fFocalLength = aOldPosition.getZ() / fWidth * 35.0;
1008*cdf0e10cSrcweir 		if(fFocalLength < 5.0)
1009*cdf0e10cSrcweir 			fFocalLength = 5.0;
1010*cdf0e10cSrcweir 	}
1011*cdf0e10cSrcweir 	return bRetval;
1012*cdf0e10cSrcweir }
1013*cdf0e10cSrcweir 
1014*cdf0e10cSrcweir // eof
1015