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
|
/******************************************************************/
/* This file is part of the homework assignments for CSCI-427/527 */
/* at The College of William & Mary and authored by Pieter Peers. */
/* No part of this file, whether altered or in original form, can */
/* be distributed or used outside the context of CSCI-427/527 */
/* without consent of either the College of William & Mary or */
/* Pieter Peers. */
/******************************************************************/
#include <cassert>
#include "sceneIO_core.h"
#include "sceneIO_transformation3d.h"
#include "rotationX3d.h"
#include "rotationY3d.h"
#include "rotationZ3d.h"
#include "rotation3d.h"
#include "translation3d.h"
#include "scale3d.h"
#include "errorMessage.h"
static transformation3d importRotationX(const XMLNode& node)
{
return rotationX3d(getFloat(node, "angle", 0.0f));
}
static transformation3d importRotationY(const XMLNode& node)
{
return rotationY3d(getFloat(node, "angle", 0.0f));
}
static transformation3d importRotationZ(const XMLNode& node)
{
return rotationZ3d(getFloat(node, "angle", 0.0f));
}
static transformation3d importRotationAxis(const XMLNode& node)
{
return rotation3d(getFloat(node, "angle", 0.0f),
getVec3d(node, "axis", vec3d(0.0f, 0.0f, 1.0f)));
}
static transformation3d importTranslation(const XMLNode& node)
{
return translation3d(getVec3d(node, "offset", vec3d(0.0f)));
}
static transformation3d importScale(const XMLNode& node)
{
vec3d scale = getVec3d(node, "scale", vec3d(1.0f));
return scale3d(scale.x, scale.y, scale.z);
}
void importTransformation(const XMLNode& node, transformation3d& transform)
{
// sanity check
assert(node.name() == "transformation");
// accumulate all child nodes
for(XMLNode childNode = node.firstChild(); childNode.isValid(); childNode++)
{
// get transformation type:
std::string type = childNode.name();
// parse
if(type == "rotationX") transform *= importRotationX(childNode);
else if(type == "rotationY") transform *= importRotationY(childNode);
else if(type == "rotationZ") transform *= importRotationZ(childNode);
else if(type == "rotation") transform *= importRotationAxis(childNode);
else if(type == "translation") transform *= importTranslation(childNode);
else if(type == "scale") transform *= importScale(childNode);
else errorMessage("Unknown transformation (%s)", type.c_str());
}
// Done.
}
|