1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
|
/*************************************************************************
*
* $RCSfile: viewpt3d.cxx,v $
*
* $Revision: 1.2 $
*
* last change: $Author: thb $ $Date: 2001-07-17 07:04:30 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#ifndef _VIEWPT3D_HXX
#include "viewpt3d.hxx"
#endif
#ifndef _VOLUME3D_HXX
#include "volume3d.hxx"
#endif
#ifndef _SVDIO_HXX
#include "svdio.hxx"
#endif
/*************************************************************************
|*
|* Konstruktor
|*
\************************************************************************/
Viewport3D::Viewport3D() :
aVRP(0, 0, 5),
aVPN(0, 0, 1),
aVUV(0, 1, 1),
aPRP(0, 0, 2),
fVPD(-3),
aViewPoint (0, 0, 5000),
fNearClipDist (0.0),
fFarClipDist (0.0),
fWRatio (1.0),
fHRatio (1.0),
eProjection(PR_PERSPECTIVE),
eAspectMapping(AS_NO_MAPPING),
bTfValid(0),
// DeviceRect-Groesse < 0 -> ungueltig
aDeviceRect(Point(0,0), Size(-1,-1))
{
aViewWin.X = -1; aViewWin.Y = -1;
aViewWin.W = 2; aViewWin.H = 2;
}
/*************************************************************************
|*
|* View-Transformationsmatrix berechnen
|*
\************************************************************************/
void Viewport3D::MakeTransform(void)
{
if ( !bTfValid )
{
double fV, fXupVp, fYupVp;
aViewPoint = aVRP + aVPN * aPRP.Z();
// auf Einheitsmatrix zuruecksetzen
aViewTf.Identity();
// in den Ursprung verschieben
aViewTf.Translate(-aVRP);
// fV = Laenge der Projektion von aVPN auf die yz-Ebene:
fV = aVPN.GetYZLength();
if ( fV != 0 )
aViewTf.RotateX(aVPN.Y() / fV, aVPN.Z() / fV);
aViewTf.RotateY(- aVPN.X(), fV);
// X- und Y-Koordinaten des View Up Vektors in das (vorlaeufige)
// View-Koordinatensytem umrechnen
fXupVp = aViewTf[0][0] * aVUV[0] + aViewTf[0][1] * aVUV[1] + aViewTf[0][2] * aVUV[2];
fYupVp = aViewTf[1][0] * aVUV[0] + aViewTf[1][1] * aVUV[1] + aViewTf[1][2] * aVUV[2];
fV = sqrt(fXupVp * fXupVp + fYupVp * fYupVp);
if ( fV != 0 )
aViewTf.RotateZ(fXupVp / fV, fYupVp / fV);
aViewTf = Matrix4D(aViewTf);
bTfValid = TRUE;
}
}
/*************************************************************************
|*
|* ViewWindow (in View-Koordinaten) setzen
|*
\************************************************************************/
void Viewport3D::SetViewWindow(double fX, double fY, double fW, double fH)
{
aViewWin.X = fX;
aViewWin.Y = fY;
if ( fW > 0 ) aViewWin.W = fW;
else aViewWin.W = 1.0;
if ( fH > 0 ) aViewWin.H = fH;
else aViewWin.H = 1.0;
fWRatio = aDeviceRect.GetWidth() / aViewWin.W;
fHRatio = aDeviceRect.GetHeight() / aViewWin.H;
}
/*************************************************************************
|*
|* ViewWindow zurueckgeben
|*
\************************************************************************/
void Viewport3D::GetViewWindow(double& rX, double& rY,
double& rW, double& rH) const
{
rX = aViewWin.X;
rY = aViewWin.Y;
rW = aViewWin.W;
rH = aViewWin.H;
}
/*************************************************************************
|*
|* View-Window genau um das mit rTransform transformierte Volumen legen
|*
\************************************************************************/
void Viewport3D::FitViewToVolume(const Volume3D& rVolume, Matrix4D aTransform)
{
Vector3D aTfVec;
Volume3D aFitVol;
aTransform *= GetViewTransform();
Vol3DPointIterator aIter(rVolume, &aTransform);
while ( aIter.Next(aTfVec) )
{
DoProjection(aTfVec);
aFitVol.Union(aTfVec);
}
SetViewWindow(aFitVol.MinVec().X(), aFitVol.MinVec().Y(),
aFitVol.GetWidth(), aFitVol.GetHeight());
}
/*************************************************************************
|*
|* DeviceWindow des Ausgabegeraetes setzen
|*
\************************************************************************/
void Viewport3D::SetDeviceWindow(const Rectangle& rRect)
{
long nNewW = rRect.GetWidth();
long nNewH = rRect.GetHeight();
long nOldW = aDeviceRect.GetWidth();
long nOldH = aDeviceRect.GetHeight();
switch ( eAspectMapping )
{
double fRatio, fTmp;
// Mapping, ohne die reale Groesse der Objekte im Device-Window
// zu aendern
case AS_HOLD_SIZE:
// Wenn Device ungueltig (w, h = -1), zunaechst
// View mit AsHoldX anpassen
if ( nOldW > 0 && nOldH > 0 )
{
fRatio = (double) nNewW / nOldW;
aViewWin.X *= fRatio;
aViewWin.W *= fRatio;
fRatio = (double) nNewH / nOldH;
aViewWin.Y *= fRatio;
aViewWin.H *= fRatio;
break;
}
case AS_HOLD_X:
// View-Hoehe an -Breite anpassen
fRatio = (double) nNewH / nNewW;
fTmp = aViewWin.H;
aViewWin.H = aViewWin.W * fRatio;
aViewWin.Y = aViewWin.Y * aViewWin.H / fTmp;
break;
case AS_HOLD_Y:
// View-Breite an -Hoehe anpassen
fRatio = (double) nNewW / nNewH;
fTmp = aViewWin.W;
aViewWin.W = aViewWin.H * fRatio;
aViewWin.X = aViewWin.X * aViewWin.W / fTmp;
break;
}
fWRatio = nNewW / aViewWin.W;
fHRatio = nNewH / aViewWin.H;
aDeviceRect = rRect;
}
/*************************************************************************
|*
|* Beobachterposition (PRP) in Weltkoordinaten zurueckgeben
|*
\************************************************************************/
const Vector3D& Viewport3D::GetViewPoint()
{
MakeTransform();
return aViewPoint;
}
/*************************************************************************
|*
|* Transformationsmatrix zurueckgeben
|*
\************************************************************************/
const Matrix4D& Viewport3D::GetViewTransform()
{
MakeTransform();
return aViewTf;
}
/*************************************************************************
|*
|* uebergebenen Punkt transformieren
|*
\************************************************************************/
Vector3D& Viewport3D::Transform(Vector3D& rVec)
{
MakeTransform();
rVec *= aViewTf;
return rVec;
}
/*************************************************************************
|*
|* neuen Punkt transformiert zurueckgeben
|*
\************************************************************************/
Vector3D Viewport3D::Transformed(const Vector3D& rVec)
{
Vector3D aNewVec = rVec;
Transform(aNewVec);
return aNewVec;
}
/*************************************************************************
|*
|* 3D-Punkt auf Viewplane projizieren
|*
\************************************************************************/
Vector3D& Viewport3D::DoProjection(Vector3D& rVec) const
{
if ( eProjection == PR_PERSPECTIVE )
{
double fPrDist = fVPD - aPRP.Z();
if ( aPRP.Z() == rVec.Z() )
rVec.X() = rVec.Y() = 0;
else
{
// Das ist die Version fuer beliebigen PRP, wird aber
// aus Performancegruenden nicht verwendet
/* double fZDiv = rVec.Z() / fPrDist;
double fZSub = 1 - fZDiv;
rVec.X() = (rVec.X() - aPRP.X() * fZDiv) / fZSub;
rVec.Y() = (rVec.Y() - aPRP.Y() * fZDiv) / fZSub;
*/
fPrDist /= rVec.Z() - aPRP.Z();
rVec.X() *= fPrDist;
rVec.Y() *= fPrDist;
}
}
return rVec;
}
/*************************************************************************
|*
|* 3D-Punkt auf Geraetekoordinaten mappen
|*
\************************************************************************/
Vector3D Viewport3D::MapToDevice(const Vector3D& rVec) const
{
Vector3D aRetval;
// Y-Koordinate subtrahieren, da die Device-Y-Achse von oben
// nach unten verlaeuft
aRetval.X() = (double)aDeviceRect.Left() + ((rVec.X() - aViewWin.X) * fWRatio);
aRetval.Y() = (double)aDeviceRect.Bottom() - ((rVec.Y() - aViewWin.Y) * fHRatio);
aRetval.Z() = rVec.Z();
return aRetval;
}
/*************************************************************************
|*
|* 3D-Punkt auf Viewplane projizieren und auf Geraetekoordinaten mappen
|*
\************************************************************************/
Vector3D Viewport3D::ProjectAndMap(Vector3D aVec) const
{
DoProjection(aVec);
return MapToDevice(aVec);
}
/*************************************************************************
|*
|* Device-Werte fuer Breite und Hoehe des Vektors in View-Werte
|* wandeln, abhaengig von der Projektion
|*
\************************************************************************/
Vector3D Viewport3D::MapSizeToView(const Vector3D& rVec)
{
Vector3D aVec(rVec);
// zuerst von Device in View umrechnen
aVec.X() /= fWRatio;
aVec.Y() /= fHRatio;
// dann die Perspektivtransformation umkehren
/* if ( eProjection == PR_PERSPECTIVE )
{
double fPrDist = fVPD - aPRP.Z();
if ( aPRP.Z() != aVec.Z() )
{
fPrDist /= aVec.Z() - aPRP.Z();
aVec.X() /= fPrDist;
aVec.Y() /= fPrDist;
}
}
*/ return aVec;
}
/*************************************************************************
|*
|* View Reference Point setzen
|*
\************************************************************************/
void Viewport3D::SetVRP(const Vector3D& rNewVRP)
{
aVRP = rNewVRP;
bTfValid = FALSE;
}
/*************************************************************************
|*
|* View Plane Normal setzen
|*
\************************************************************************/
void Viewport3D::SetVPN(const Vector3D& rNewVPN)
{
aVPN = rNewVPN;
aVPN.Normalize();
bTfValid = FALSE;
}
/*************************************************************************
|*
|* View Up Vector setzen
|*
\************************************************************************/
void Viewport3D::SetVUV(const Vector3D& rNewVUV)
{
aVUV = rNewVUV;
bTfValid = FALSE;
}
/*************************************************************************
|*
|* Center Of Projection setzen
|*
\************************************************************************/
void Viewport3D::SetPRP(const Vector3D& rNewPRP)
{
aPRP = rNewPRP;
aPRP.X() = 0;
aPRP.Y() = 0;
bTfValid = FALSE;
}
/*************************************************************************
|*
|* View Plane Distance setzen
|*
\************************************************************************/
void Viewport3D::SetVPD(double fNewVPD)
{
fVPD = fNewVPD;
bTfValid = FALSE;
}
/*************************************************************************
|*
|* Abstand der vorderen Clippingebene setzen
|*
\************************************************************************/
void Viewport3D::SetNearClipDist(double fNewNCD)
{
fNearClipDist = fNewNCD;
bTfValid = FALSE;
}
/*************************************************************************
|*
|* Abstand der hinteren Clippingebene setzen
|*
\************************************************************************/
void Viewport3D::SetFarClipDist(double fNewFCD)
{
fFarClipDist = fNewFCD;
bTfValid = FALSE;
}
/*************************************************************************
|*
|* Stream-Out-Operator fuer Viewport3D (Version 3.1)
|*
\************************************************************************/
void Viewport3D::WriteData31(SvStream& rOut) const
{
#ifndef SVX_LIGHT
rOut << aVRP;
rOut << aVPN;
rOut << aVUV;
rOut << aPRP;
rOut << fVPD;
rOut << fNearClipDist;
rOut << fFarClipDist;
rOut << UINT16(eProjection);
rOut << UINT16(eAspectMapping);
rOut << aDeviceRect;
rOut << aViewWin.X;
rOut << aViewWin.Y;
rOut << aViewWin.W;
rOut << aViewWin.H;
#endif
}
/*************************************************************************
|*
|* Stream-Out-Operator fuer Viewport3D ab File-Revision 13
|* implementiert zum Hauptupdate 355 am 4.2.97 FG (freigegeben ab 356)
|*
\************************************************************************/
void Viewport3D::WriteData(SvStream& rOut) const
{
#ifndef SVX_LIGHT
if (rOut.GetVersion() < 3560)
{
Viewport3D::WriteData31(rOut);
return;
}
SdrDownCompat aCompat(rOut, STREAM_WRITE);
#ifdef DBG_UTIL
aCompat.SetID("Viewport3D");
#endif
rOut << aVRP;
rOut << aVPN;
rOut << aVUV;
rOut << aPRP;
rOut << fVPD;
rOut << fNearClipDist;
rOut << fFarClipDist;
rOut << UINT16(eProjection);
rOut << UINT16(eAspectMapping);
rOut << aDeviceRect;
rOut << aViewWin.X;
rOut << aViewWin.Y;
rOut << aViewWin.W;
rOut << aViewWin.H;
#endif
}
/*************************************************************************
|*
|* Stream-In-Operator fuer Viewport3D fuer die Version 3.1
|*
\************************************************************************/
void Viewport3D::ReadData31(SvStream& rIn)
{
UINT16 nTmp16;
rIn >> aVRP;
rIn >> aVPN;
rIn >> aVUV;
rIn >> aPRP;
rIn >> fVPD;
rIn >> fNearClipDist;
rIn >> fFarClipDist;
rIn >> nTmp16; eProjection = ProjectionType(nTmp16);
rIn >> nTmp16; eAspectMapping = AspectMapType(nTmp16);
rIn >> aDeviceRect;
rIn >> aViewWin.X;
rIn >> aViewWin.Y;
rIn >> aViewWin.W;
rIn >> aViewWin.H;
// es gibt einige Docs mit zweifelhaften werten, daher wird die Dist auf 0 gesetzt
if ((fNearClipDist <= 1e-100) || (fNearClipDist >= 1e100)) fNearClipDist = 0.0;
if ((fFarClipDist <= 1e-100) || (fFarClipDist >= 1e100)) fFarClipDist = 0.0;
fWRatio = aDeviceRect.GetWidth() / aViewWin.W;
fHRatio = aDeviceRect.GetHeight() / aViewWin.H;
bTfValid = FALSE;
}
/*************************************************************************
|*
|* ReadData-Methode fuer Viewport3D, gueltig fuer Filerevisionen ab 13
|* eingecheckt ab Revision 355 am 4.2.97 (FG) (freigegeben ab 356)
|*
\************************************************************************/
void Viewport3D::ReadData(const SdrObjIOHeader& rHead, SvStream& rIn)
{
if ((rHead.GetVersion() < 13) || (rIn.GetVersion() < 3560))
{
Viewport3D::ReadData31 (rIn);
return;
}
SdrDownCompat aCompat(rIn, STREAM_READ);
#ifdef DBG_UTIL
aCompat.SetID("Viewport3D");
#endif
UINT16 nTmp16;
rIn >> aVRP;
rIn >> aVPN;
rIn >> aVUV;
rIn >> aPRP;
rIn >> fVPD;
rIn >> fNearClipDist;
rIn >> fFarClipDist;
rIn >> nTmp16; eProjection = ProjectionType(nTmp16);
rIn >> nTmp16; eAspectMapping = AspectMapType(nTmp16);
rIn >> aDeviceRect;
rIn >> aViewWin.X;
rIn >> aViewWin.Y;
rIn >> aViewWin.W;
rIn >> aViewWin.H;
// es gibt einige Docs mit zweifelhaften werten, daher wird die Dist auf 0 gesetzt
if ((fNearClipDist <= 1e-100) || (fNearClipDist >= 1e100)) fNearClipDist = 0.0;
if ((fFarClipDist <= 1e-100) || (fFarClipDist >= 1e100)) fFarClipDist = 0.0;
fWRatio = aDeviceRect.GetWidth() / aViewWin.W;
fHRatio = aDeviceRect.GetHeight() / aViewWin.H;
bTfValid = FALSE;
}
// FG: eigentlich sollten die Stream-Funktionen in der 3D-Engine nicht verwendet werden
// sondern WriteData und ReadData, da man insbesondere bei ReadData einen
// zusaetzlichen Parameter hat der die File-Revision enthaelt.
/*************************************************************************
|*
|* Stream-Out-Operator fuer Viewport3D
|*
\************************************************************************/
#ifndef SVX_LIGHT
SvStream& operator<<(SvStream& rOStream, const Viewport3D& rViewpt)
{
rViewpt.WriteData31(rOStream);
return rOStream;
}
#endif
/*************************************************************************
|*
|* Stream-In-Operator fuer Viewport3D
|*
\************************************************************************/
SvStream& operator>>(SvStream& rIStream, Viewport3D& rViewpt)
{
rViewpt.ReadData31(rIStream);
return rIStream;
}
|