Mercurial > hg > Members > e075743
diff src/CollisionNode.cpp @ 10:5727d511a13a
add src in Martial Project Xcode.
author | tokumoritaichirou@nw0743.st.ie.u-ryukyu.ac.jp |
---|---|
date | Wed, 03 Feb 2010 03:39:04 +0900 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/CollisionNode.cpp Wed Feb 03 03:39:04 2010 +0900 @@ -0,0 +1,71 @@ +/* + * CollisionNode.cpp + * Martial + * + * Created by ryoma on 10/01/26. + * Copyright 2010 琉球大学. All rights reserved. + * + */ + +#include "CollisionNode.h" + +CollisionNode::CollisionNode(char* name, osg::Sphere* shape): + name(name), shape(shape) { + collision = false; + attack = false; + guard = false; + radius = shape->getRadius(); + drawable = new osg::ShapeDrawable(shape); + drawable->setColor(osg::Vec4f(1,1,1,1)); + collisionNode = new osg::Geode(); + collisionNode->addDrawable(drawable); +} + +CollisionNode::CollisionNode(char* name, osg::Cylinder* shape): + name(name), shape(shape) { + collision = false; + attack = false; + guard = false; + radius = shape->getRadius(); + drawable = new osg::ShapeDrawable(shape); + drawable->setColor(osg::Vec4f(1,1,1,1)); + collisionNode = new osg::Geode(); + collisionNode->addDrawable(drawable); +} + +CollisionNode::CollisionNode(char* name, osg::Geode* geode, osg::Shape* shape): + name(name), collisionNode(geode), shape(shape) { + collision = false; + attack = false; + guard = false; + drawable = new osg::ShapeDrawable(shape); + drawable->setColor(osg::Vec4f(1,1,1,1)); + collisionNode->addDrawable(drawable); +} + + +void CollisionNode::setCollision(bool _collision) { + _collision ? drawable->setColor(osg::Vec4f(1,0,0,1)) : drawable->setColor(osg::Vec4f(1,1,1,1)); + collision = _collision; +} + +char* CollisionNode::getName() { + return name; +} + +osg::NodePath CollisionNode::getNodePath() { + return collisionNode->getParentalNodePaths().front(); +} + +osg::Geode* CollisionNode::getGeode() { + return collisionNode; +} + +osg::BoundingSphere CollisionNode::getBound(osg::Matrix localToWorldMatrix) { + osg::Vec3 t = localToWorldMatrix.getTrans(); + osg::BoundingSphere bound = collisionNode->computeBound(); + //printf("[%.3f, %.3f, %.3f]\n", localToWorldMatrix.getTrans().x(), localToWorldMatrix.getTrans().y(), + // localToWorldMatrix.getTrans().z()); + bound.set(bound.center()*localToWorldMatrix, radius*0.01); + return bound; +}