]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/placementtrans.cxx
Mathias: silence some valgrind warnings so that you can concentrate better on the...
[simgear.git] / simgear / scene / model / placementtrans.cxx
1 // placementtrans.hxx -- class for carrying transforms for placing models in the world
2 //
3 // Written by Mathias Froehlich, started April 2005.
4 //
5 // Copyright (C) 2005 Mathias Froehlich
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21
22
23 #ifndef __cplusplus                                                          
24 # error This library requires C++
25 #endif                                   
26
27 #include <simgear/compiler.h>
28 #include <simgear/constants.h>
29
30 #include <plib/sg.h>
31 #include <plib/ssg.h>
32
33 #include "placementtrans.hxx"
34
35 ssgPlacementTransform::ssgPlacementTransform(void)
36 {
37   sgdSetVec3(_placement_offset, 0, 0, 0);
38   sgdSetVec3(_scenery_center, 0, 0, 0);
39 }
40
41 ssgPlacementTransform::~ssgPlacementTransform(void)
42 {
43 }
44
45 ssgBase *ssgPlacementTransform::clone(int clone_flags)
46 {
47   ssgPlacementTransform *b = new ssgPlacementTransform;
48   b->copy_from(this, clone_flags);
49   return b;
50 }
51
52 void
53 ssgPlacementTransform::copy_from(ssgPlacementTransform *src, int clone_flags)
54 {
55   ssgBaseTransform::copy_from(src, clone_flags);
56   sgdCopyVec3(_placement_offset, src->_placement_offset);
57   sgdCopyVec3(_scenery_center,  src->_scenery_center);
58 }
59
60 void ssgPlacementTransform::setTransform(sgdVec3 off)
61 {
62   sgdCopyVec3(_placement_offset, off);
63   sgdVec3 tmp;
64   sgdSubVec3(tmp, _placement_offset, _scenery_center);
65   sgMat4 tmat;
66   sgZeroVec4(tmat[0]);
67   tmat[0][0] = 1;
68   sgZeroVec4(tmat[1]);
69   tmat[1][1] = 1;
70   sgZeroVec4(tmat[2]);
71   tmat[2][2] = 1;
72   sgSetVec3(tmat[3], tmp);
73   tmat[3][3] = 1;
74   ssgTransform::setTransform(tmat);
75 }
76
77 void ssgPlacementTransform::setTransform(sgdVec3 off, sgMat4 rot)
78 {
79   sgdCopyVec3(_placement_offset, off);
80   sgdVec3 tmp;
81   sgdSubVec3(tmp, _placement_offset, _scenery_center);
82   sgMat4 tmat;
83   sgCopyVec4(tmat[0], rot[0]);
84   sgCopyVec4(tmat[1], rot[1]);
85   sgCopyVec4(tmat[2], rot[2]);
86   sgSetVec3(tmat[3], tmp);
87   tmat[3][3] = 1;
88   ssgTransform::setTransform(tmat);
89 }
90
91 void ssgPlacementTransform::setSceneryCenter(sgdVec3 xyz)
92 {
93   sgdCopyVec3(_scenery_center, xyz);
94   sgdVec3 tmp;
95   sgdSubVec3(tmp, _placement_offset, _scenery_center);
96   sgMat4 tmat;
97   getTransform(tmat);
98   sgSetVec3(tmat[3], tmp);
99   ssgTransform::setTransform(tmat);
100 }