]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/placementtrans.cxx
Mathias:
[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 }
38
39 ssgPlacementTransform::~ssgPlacementTransform(void)
40 {
41 }
42
43 ssgBase *ssgPlacementTransform::clone(int clone_flags)
44 {
45   ssgPlacementTransform *b = new ssgPlacementTransform;
46   b->copy_from(this, clone_flags);
47   return b;
48 }
49
50 void
51 ssgPlacementTransform::copy_from(ssgPlacementTransform *src, int clone_flags)
52 {
53   ssgBaseTransform::copy_from(src, clone_flags);
54   sgdCopyVec3(_placement_offset, src->_placement_offset);
55   sgdCopyVec3(_scenery_center,  src->_scenery_center);
56 }
57
58 void ssgPlacementTransform::setTransform(sgdVec3 off)
59 {
60   sgdCopyVec3(_placement_offset, off);
61   sgdVec3 tmp;
62   sgdSubVec3(tmp, _placement_offset, _scenery_center);
63   sgMat4 tmat;
64   sgZeroVec4(tmat[0]);
65   tmat[0][0] = 1;
66   sgZeroVec4(tmat[1]);
67   tmat[1][1] = 1;
68   sgZeroVec4(tmat[2]);
69   tmat[2][2] = 1;
70   sgSetVec3(tmat[3], tmp);
71   tmat[3][3] = 1;
72   ssgTransform::setTransform(tmat);
73 }
74
75 void ssgPlacementTransform::setTransform(sgdVec3 off, sgMat4 rot)
76 {
77   sgdCopyVec3(_placement_offset, off);
78   sgdVec3 tmp;
79   sgdSubVec3(tmp, _placement_offset, _scenery_center);
80   sgMat4 tmat;
81   sgCopyVec4(tmat[0], rot[0]);
82   sgCopyVec4(tmat[1], rot[1]);
83   sgCopyVec4(tmat[2], rot[2]);
84   sgSetVec3(tmat[3], tmp);
85   tmat[3][3] = 1;
86   ssgTransform::setTransform(tmat);
87 }
88
89 void ssgPlacementTransform::setSceneryCenter(sgdVec3 xyz)
90 {
91   sgdCopyVec3(_scenery_center, xyz);
92   sgdVec3 tmp;
93   sgdSubVec3(tmp, _placement_offset, _scenery_center);
94   sgMat4 tmat;
95   getTransform(tmat);
96   sgSetVec3(tmat[3], tmp);
97   ssgTransform::setTransform(tmat);
98 }