comparison src/MovableObject.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 * MovableObject.cpp
3 * Race
4 *
5 * Created by ryoma on 10/01/23.
6 * Copyright 2010 琉球大学. All rights reserved.
7 *
8 */
9
10 #include "MovableObject.h"
11 #include "GameManager.h"
12
13 /** MovableObjectのコンストラクタ.
14 * osg::Nodeを描画物体として受け取り、動く物体を生成する
15 * @param _node 描画されるノード, _name ノードの名前
16 */
17
18 MovableObject::MovableObject(char* _name) {
19 init();
20 scale = osg::Vec3(1.0,1.0,1.0);
21 defaultDirection = osg::Vec3(0.0,0.0,0.0);
22 name = _name;
23 mform = new osg::MatrixTransform();
24 frame();
25 }
26
27 MovableObject::MovableObject(osg::Node* _node, char* _name) {
28 init();
29 name = _name;
30 node = _node;
31 mform = new osg::MatrixTransform();
32 mform->addChild(node);
33 }
34
35 void MovableObject::init() {
36 position = osg::Vec3(0.0,0.0,0.0);
37 velocity = osg::Vec3(0.0,0.0,0.0);
38 acceleration = osg::Vec3(0.0,0.0,0.0);
39 angularVelocity = osg::Vec3(0.0,0.0,0.0);
40 direction = osg::Vec3(0.0,0.0,0.0);
41 }
42
43 void MovableObject::move(osg::Vec3 s) {
44 }
45
46 void MovableObject::rotate(osg::Vec3 r) {
47 }
48
49 void MovableObject::accelerate(osg::Vec3 a) {
50 velocity += a;
51 }
52
53 void MovableObject::setPos(osg::Vec3 p) {
54 position = p;
55 }
56
57 void MovableObject::setVel(osg::Vec3 v) {
58 velocity = v;
59 }
60
61 void MovableObject::setAcc(osg::Vec3 a) {
62 acceleration = a;
63 }
64
65 void MovableObject::setDir(osg::Vec3 r) {
66 direction = r;
67 }
68
69 void MovableObject::setDefaultDirection(osg::Vec3 r) {
70 defaultDirection = r;
71 }
72
73 void MovableObject::setAngularVelocity(osg::Vec3 r) {
74 angularVelocity = r;
75 }
76
77 void MovableObject::setScale(osg::Vec3 s) {
78 scale = s;
79 }
80
81 osg::Vec3 MovableObject::getPos() {
82 return position;
83 }
84
85 osg::Vec3 MovableObject::getVel() {
86 return velocity;
87 }
88
89 osg::Vec3 MovableObject::getAcc() {
90 return acceleration;
91 }
92
93 osg::Vec3 MovableObject::getDir() {
94 return direction;
95 }
96
97 osg::Vec3 MovableObject::getDefaultDirection() {
98 return defaultDirection;
99 }
100
101 char* MovableObject::getName() {
102 return name;
103 }
104
105 osg::MatrixTransform* MovableObject::getForm() {
106 return mform;
107 }
108
109 void MovableObject::dump() {
110 }
111
112 /* 位置,体勢の再計算のみ */
113 void MovableObject::frame() {
114 osg::Matrixd roteMatrix;
115 osg::Matrixd accMatrix;
116 osg::Matrixd dirMatrix;
117
118 direction += angularVelocity;
119 accMatrix.makeTranslate(acceleration);
120 roteMatrix.makeRotate(
121 osg::Quat(
122 defaultDirection.x(), osg::Vec3(1,0,0),
123 defaultDirection.y(), osg::Vec3(0,1,0),
124 defaultDirection.z(), osg::Vec3(0,0,1)
125 )
126 );
127
128 velocity += (accMatrix*roteMatrix).getTrans();
129 position += velocity;
130
131 /* 3Dモデルが元々正面向きのため、90度補正の再計算 */
132 /* 毎回計算が無駄だと思うので、ツール側で補正するべき */
133 /*roteMatrix.makeRotate(
134 osg::Quat(
135 defaultDirection.x()+direction.x(), osg::Vec3(1,0,0),
136 defaultDirection.y()+direction.y(), osg::Vec3(0,1,0),
137 defaultDirection.z()+direction.z(), osg::Vec3(0,0,1)
138 )
139 );*/
140
141 dirMatrix.makeTranslate(position);
142 accMatrix.makeScale(scale);
143 mform->setMatrix(accMatrix*accMatrix*roteMatrix);
144 }
145
146 void MovableObject::checkCollision() {
147 }
148
149 void MovableObject::collision(osg::Vec3 pos, osg::Vec3 reaction) {
150
151 }