Mercurial > hg > Members > e075743
comparison 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 |
comparison
equal
deleted
inserted
replaced
9:143f7b9f867d | 10:5727d511a13a |
---|---|
1 /* | |
2 * CollisionNode.cpp | |
3 * Martial | |
4 * | |
5 * Created by ryoma on 10/01/26. | |
6 * Copyright 2010 琉球大学. All rights reserved. | |
7 * | |
8 */ | |
9 | |
10 #include "CollisionNode.h" | |
11 | |
12 CollisionNode::CollisionNode(char* name, osg::Sphere* shape): | |
13 name(name), shape(shape) { | |
14 collision = false; | |
15 attack = false; | |
16 guard = false; | |
17 radius = shape->getRadius(); | |
18 drawable = new osg::ShapeDrawable(shape); | |
19 drawable->setColor(osg::Vec4f(1,1,1,1)); | |
20 collisionNode = new osg::Geode(); | |
21 collisionNode->addDrawable(drawable); | |
22 } | |
23 | |
24 CollisionNode::CollisionNode(char* name, osg::Cylinder* shape): | |
25 name(name), shape(shape) { | |
26 collision = false; | |
27 attack = false; | |
28 guard = false; | |
29 radius = shape->getRadius(); | |
30 drawable = new osg::ShapeDrawable(shape); | |
31 drawable->setColor(osg::Vec4f(1,1,1,1)); | |
32 collisionNode = new osg::Geode(); | |
33 collisionNode->addDrawable(drawable); | |
34 } | |
35 | |
36 CollisionNode::CollisionNode(char* name, osg::Geode* geode, osg::Shape* shape): | |
37 name(name), collisionNode(geode), shape(shape) { | |
38 collision = false; | |
39 attack = false; | |
40 guard = false; | |
41 drawable = new osg::ShapeDrawable(shape); | |
42 drawable->setColor(osg::Vec4f(1,1,1,1)); | |
43 collisionNode->addDrawable(drawable); | |
44 } | |
45 | |
46 | |
47 void CollisionNode::setCollision(bool _collision) { | |
48 _collision ? drawable->setColor(osg::Vec4f(1,0,0,1)) : drawable->setColor(osg::Vec4f(1,1,1,1)); | |
49 collision = _collision; | |
50 } | |
51 | |
52 char* CollisionNode::getName() { | |
53 return name; | |
54 } | |
55 | |
56 osg::NodePath CollisionNode::getNodePath() { | |
57 return collisionNode->getParentalNodePaths().front(); | |
58 } | |
59 | |
60 osg::Geode* CollisionNode::getGeode() { | |
61 return collisionNode; | |
62 } | |
63 | |
64 osg::BoundingSphere CollisionNode::getBound(osg::Matrix localToWorldMatrix) { | |
65 osg::Vec3 t = localToWorldMatrix.getTrans(); | |
66 osg::BoundingSphere bound = collisionNode->computeBound(); | |
67 //printf("[%.3f, %.3f, %.3f]\n", localToWorldMatrix.getTrans().x(), localToWorldMatrix.getTrans().y(), | |
68 // localToWorldMatrix.getTrans().z()); | |
69 bound.set(bound.center()*localToWorldMatrix, radius*0.01); | |
70 return bound; | |
71 } |