# include <config.h>
#endif
-#include <string.h> // for strcmp()
+#include <string.h> // for strcmp()
#include <plib/sg.h>
#include <plib/ssg.h>
int nKids = node->getNumKids();
for (int i = 0; i < nKids; i++) {
ssgEntity * result =
- find_named_node(((ssgBranch*)node)->getKid(i), name);
+ find_named_node(((ssgBranch*)node)->getKid(i), name);
if (result != 0)
- return result;
+ return result;
}
}
return 0;
*/
static void
set_rotation (sgMat4 &matrix, double position_deg,
- sgVec3 ¢er, sgVec3 &axis)
+ sgVec3 ¢er, sgVec3 &axis)
{
float temp_angle = -position_deg * SG_DEGREES_TO_RADIANS ;
{
SGPropertyNode props;
- // Load the 3D aircraft object itself
+ // Load the 3D aircraft object itself
SGPath xmlpath = globals->get_fg_root();
SGPath modelpath = path;
xmlpath.append(modelpath.str());
- // Check for an XML wrapper
+ // Check for an XML wrapper
if (xmlpath.str().substr(xmlpath.str().size() - 4, 4) == ".xml") {
readProperties(xmlpath.str(), &props);
if (props.hasValue("/path")) {
}
}
- // Assume that textures are in
- // the same location as the XML file.
+ // Assume that textures are in
+ // the same location as the XML file.
ssgTexturePath((char *)xmlpath.dir().c_str());
_model = ssgLoad((char *)modelpath.c_str());
if (_model == 0)
throw sg_exception("Failed to load 3D model");
- // Load animations
+ // Load animations
vector<SGPropertyNode *> animation_nodes = props.getChildren("animation");
for (unsigned int i = 0; i < animation_nodes.size(); i++) {
vector<SGPropertyNode *> name_nodes =
SG_LOG(SG_INPUT, SG_ALERT, "No object-name given for transformation");
} else {
for (unsigned int j = 0; j < name_nodes.size(); j++) {
- Animation * animation =
- make_animation(name_nodes[j]->getStringValue(), animation_nodes[i]);
- if (animation != 0)
- _animations.push_back(animation);
+ Animation * animation =
+ make_animation(name_nodes[j]->getStringValue(), animation_nodes[i]);
+ if (animation != 0)
+ _animations.push_back(animation);
}
}
}
- // Set up the range selector node
+ // Set up the range selector node
float ranges[2];
ssgRangeSelector * lod = new ssgRangeSelector;
lod->addKid(_model);
lod->setRanges(ranges, 2);
- // Set up the alignment node
+ // Set up the alignment node
ssgTransform * align = new ssgTransform;
align->addKid(lod);
sgMat4 rot_matrix;
sgMultMat4(res_matrix, off_matrix, rot_matrix);
align->setTransform(res_matrix);
- // Set up the position node
+ // Set up the position node
_position->addKid(align);
- // Set up the selector node
+ // Set up the selector node
_selector->addKid(_position);
_selector->clrTraversalMaskBits(SSGTRAV_HOT);
- // Set up a location class
+ // Set up a location class
_location = (FGLocation *) new FGLocation;
}
for (unsigned int i = 0; i < _animations.size(); i++)
_animations[i]->update(dt);
- sgCoord obj_pos;
-
- sgMat4 POS, TRANS;
-
_location->setPosition( _lon_deg, _lat_deg, _elev_ft );
_location->setOrientation( _roll_deg, _pitch_deg, _heading_deg );
- sgCopyMat4(TRANS, _location->getTransformMatrix());
- sgMakeTransMat4( POS, _location->get_view_pos() );
-
- sgPostMultMat4( TRANS, POS );
- sgSetCoord( &obj_pos, TRANS );
+ sgMat4 POS;
+ sgCopyMat4(POS, _location->getTransformMatrix());
+
+ sgVec3 trans;
+ sgCopyVec3(trans, _location->get_view_pos());
- _position->setTransform(&obj_pos);
+ for( int i=0; i<4; i++) {
+ float tmp = POS[i][3];
+ for( int j=0; j<3; j++ ) {
+ POS[i][j] += (tmp * trans[j]);
+ }
+ }
+ _position->setTransform(POS);
}
bool
void
FG3DModel::setOrientation (double roll_deg, double pitch_deg,
- double heading_deg)
+ double heading_deg)
{
_roll_deg = roll_deg;
_pitch_deg = pitch_deg;
FG3DModel::Animation *
FG3DModel::make_animation (const char * object_name,
- SGPropertyNode * node)
+ SGPropertyNode * node)
{
Animation * animation = 0;
const char * type = node->getStringValue("type");
void
FG3DModel::NullAnimation::init (ssgEntity * object,
- SGPropertyNode * props)
+ SGPropertyNode * props)
{
splice_branch(_branch, object);
_branch->setName(props->getStringValue("name", 0));
void
FG3DModel::RangeAnimation::init (ssgEntity * object,
- SGPropertyNode * props)
+ SGPropertyNode * props)
{
float ranges[2];
splice_branch(_branch, object);
void
FG3DModel::SelectAnimation::init (ssgEntity * object,
- SGPropertyNode * props)
+ SGPropertyNode * props)
{
splice_branch(_selector, object);
_selector->setName(props->getStringValue("name", 0));
void
FG3DModel::SpinAnimation::init (ssgEntity * object,
- SGPropertyNode * props)
+ SGPropertyNode * props)
{
- // Splice in the new transform node
+ // Splice in the new transform node
splice_branch(_transform, object);
_transform->setName(props->getStringValue("name", 0));
_prop = fgGetNode(props->getStringValue("property", "/null"), true);
void
FG3DModel::RotateAnimation::init (ssgEntity * object,
- SGPropertyNode * props)
+ SGPropertyNode * props)
{
- // Splice in the new transform node
+ // Splice in the new transform node
splice_branch(_transform, object);
_transform->setName(props->getStringValue("name", 0));
_prop = fgGetNode(props->getStringValue("property", "/null"), true);
void
FG3DModel::TranslateAnimation::init (ssgEntity * object,
- SGPropertyNode * props)
+ SGPropertyNode * props)
{
- // Splice in the new transform node
+ // Splice in the new transform node
splice_branch(_transform, object);
_transform->setName(props->getStringValue("name", 0));
_prop = fgGetNode(props->getStringValue("property", "/null"), true);