[0b990d] | 1 | //
|
---|
| 2 | // transform.cc
|
---|
| 3 | //
|
---|
| 4 | // Copyright (C) 1996 Limit Point Systems, Inc.
|
---|
| 5 | //
|
---|
| 6 | // Author: Curtis Janssen <cljanss@limitpt.com>
|
---|
| 7 | // Maintainer: LPS
|
---|
| 8 | //
|
---|
| 9 | // This file is part of the SC Toolkit.
|
---|
| 10 | //
|
---|
| 11 | // The SC Toolkit is free software; you can redistribute it and/or modify
|
---|
| 12 | // it under the terms of the GNU Library General Public License as published by
|
---|
| 13 | // the Free Software Foundation; either version 2, or (at your option)
|
---|
| 14 | // any later version.
|
---|
| 15 | //
|
---|
| 16 | // The SC Toolkit is distributed in the hope that it will be useful,
|
---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | // GNU Library General Public License for more details.
|
---|
| 20 | //
|
---|
| 21 | // You should have received a copy of the GNU Library General Public License
|
---|
| 22 | // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
|
---|
| 23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 24 | //
|
---|
| 25 | // The U.S. Government is granted a limited license as per AL 91-7.
|
---|
| 26 | //
|
---|
| 27 |
|
---|
| 28 | #include <stdlib.h>
|
---|
| 29 | #include <util/render/transform.h>
|
---|
| 30 |
|
---|
| 31 | using namespace std;
|
---|
| 32 | using namespace sc;
|
---|
| 33 |
|
---|
| 34 | static ClassDesc Transform_cd(
|
---|
| 35 | typeid(Transform),"Transform",1,"public DescribedClass",
|
---|
| 36 | 0, create<Transform>, 0);
|
---|
| 37 |
|
---|
| 38 | Transform::Transform(const Ref<KeyVal>& keyval)
|
---|
| 39 | {
|
---|
| 40 | transform_ = identity3D();
|
---|
| 41 | if (keyval->exists("translate")) {
|
---|
| 42 | if (keyval->count("translate") != 3) {
|
---|
| 43 | ExEnv::errn() << "Transform: error in translation" << endl;
|
---|
| 44 | abort();
|
---|
| 45 | }
|
---|
| 46 | translate(keyval->doublevalue("translate",0),
|
---|
| 47 | keyval->doublevalue("translate",1),
|
---|
| 48 | keyval->doublevalue("translate",2));
|
---|
| 49 | }
|
---|
| 50 | if (keyval->exists("rotate")) {
|
---|
| 51 | if (keyval->count("rotate:axis") != 3
|
---|
| 52 | || !keyval->exists("rotate:angle")) {
|
---|
| 53 | ExEnv::errn() << "Transform: error in rotation" << endl;
|
---|
| 54 | abort();
|
---|
| 55 | }
|
---|
| 56 | vec3 axis(keyval->doublevalue("rotate:axis",0),
|
---|
| 57 | keyval->doublevalue("rotate:axis",1),
|
---|
| 58 | keyval->doublevalue("rotate:axis",2));
|
---|
| 59 | rotate(axis, keyval->doublevalue("rotate:angle"));
|
---|
| 60 | }
|
---|
| 61 | if (keyval->exists("scale")) {
|
---|
| 62 | double scalefactor = keyval->doublevalue("scale");
|
---|
| 63 | scale(scalefactor);
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | Transform::~Transform()
|
---|
| 68 | {
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | void
|
---|
| 72 | Transform::translate(double x, double y, double z)
|
---|
| 73 | {
|
---|
| 74 | vec3 r(x,y,z);
|
---|
| 75 | translate(r);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | void
|
---|
| 79 | Transform::translate(const vec3& r)
|
---|
| 80 | {
|
---|
| 81 | transform_ = translation3D(r) * transform_;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | void
|
---|
| 85 | Transform::rotate(const vec3& axis, double angle)
|
---|
| 86 | {
|
---|
| 87 | transform_ = rotation3D(axis, angle) * transform_;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | void
|
---|
| 91 | Transform::scale(double scalefactor)
|
---|
| 92 | {
|
---|
| 93 | transform_ = scaling3D(vec3(scalefactor,scalefactor,scalefactor))
|
---|
| 94 | * transform_;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | void
|
---|
| 98 | Transform::print(ostream& os) const
|
---|
| 99 | {
|
---|
| 100 | os << "Transform" << endl;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 104 |
|
---|
| 105 | // Local Variables:
|
---|
| 106 | // mode: c++
|
---|
| 107 | // c-file-style: "CLJ"
|
---|
| 108 | // End:
|
---|