view src/CollisionNode.cpp @ 13:39e0c583e0a3 default tip

add GiantroboClassfile.
author tokumoritaichirou@w-133-13-243-110.cc.u-ryukyu.ac.jp
date Wed, 03 Feb 2010 18:37:01 +0900
parents 5727d511a13a
children
line wrap: on
line source

/*
 *  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;
}