1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12 */
13
14 #include <osgUtil/TransformAttributeFunctor>
15
16 using namespace osgUtil;
17
TransformAttributeFunctor(const osg::Matrix & m)18 TransformAttributeFunctor::TransformAttributeFunctor(const osg::Matrix& m)
19 {
20 _m = m;
21 _im.invert(_m);
22 }
23
~TransformAttributeFunctor()24 TransformAttributeFunctor::~TransformAttributeFunctor()
25 {
26 }
27
apply(osg::Drawable::AttributeType type,unsigned int count,osg::Vec3 * begin)28 void TransformAttributeFunctor::apply(osg::Drawable::AttributeType type,unsigned int count,osg::Vec3* begin)
29 {
30 if (type == osg::Drawable::VERTICES)
31 {
32 osg::Vec3* end = begin+count;
33 for (osg::Vec3* itr=begin;itr<end;++itr)
34 {
35 (*itr) = (*itr)*_m;
36 }
37 }
38 else if (type == osg::Drawable::NORMALS)
39 {
40 osg::Vec3* end = begin+count;
41 for (osg::Vec3* itr=begin;itr<end;++itr)
42 {
43 // note post mult by inverse for normals.
44 (*itr) = osg::Matrix::transform3x3(_im,(*itr));
45 (*itr).normalize();
46 }
47 }
48 }
49
apply(osg::Drawable::AttributeType type,unsigned int count,osg::Vec3d * begin)50 void TransformAttributeFunctor::apply(osg::Drawable::AttributeType type,unsigned int count,osg::Vec3d* begin)
51 {
52 if (type == osg::Drawable::VERTICES)
53 {
54 osg::Vec3d* end = begin+count;
55 for (osg::Vec3d* itr=begin;itr<end;++itr)
56 {
57 (*itr) = (*itr)*_m;
58 }
59 }
60 else if (type == osg::Drawable::NORMALS)
61 {
62 osg::Vec3d* end = begin+count;
63 for (osg::Vec3d* itr=begin;itr<end;++itr)
64 {
65 // note post mult by inverse for normals.
66 (*itr) = osg::Matrix::transform3x3(_im,(*itr));
67 (*itr).normalize();
68 }
69 }
70 }
71