view 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
line wrap: on
line source

/*
 *  MovableObject.cpp
 *  Race
 *
 *  Created by ryoma on 10/01/23.
 *  Copyright 2010 琉球大学. All rights reserved.
 *
 */

#include "MovableObject.h"
#include "GameManager.h"

/** MovableObjectのコンストラクタ.
 * osg::Nodeを描画物体として受け取り、動く物体を生成する
 * @param _node 描画されるノード, _name ノードの名前
 */

MovableObject::MovableObject(char* _name) {
	init();
	scale = osg::Vec3(1.0,1.0,1.0);
	defaultDirection = osg::Vec3(0.0,0.0,0.0);
	name = _name;
	mform = new osg::MatrixTransform();
	frame();
}

MovableObject::MovableObject(osg::Node* _node, char* _name) {
	init();
	name = _name;
	node = _node;
	mform = new osg::MatrixTransform();
	mform->addChild(node);
}

void MovableObject::init() {
	position = osg::Vec3(0.0,0.0,0.0);
	velocity = osg::Vec3(0.0,0.0,0.0);
	acceleration = osg::Vec3(0.0,0.0,0.0);
	angularVelocity = osg::Vec3(0.0,0.0,0.0);
	direction = osg::Vec3(0.0,0.0,0.0);
}

void MovableObject::move(osg::Vec3 s) {
}

void MovableObject::rotate(osg::Vec3 r) {
}

void MovableObject::accelerate(osg::Vec3 a) {
	velocity += a;
}

void MovableObject::setPos(osg::Vec3 p) {
	position = p;
}

void MovableObject::setVel(osg::Vec3 v) {
	velocity = v;
}

void MovableObject::setAcc(osg::Vec3 a) {
	acceleration = a;
}

void MovableObject::setDir(osg::Vec3 r) {
	direction = r;
}

void MovableObject::setDefaultDirection(osg::Vec3 r) {
	defaultDirection = r;
}

void MovableObject::setAngularVelocity(osg::Vec3 r) {
	angularVelocity = r;
}

void MovableObject::setScale(osg::Vec3 s) {
	scale = s;
}

osg::Vec3 MovableObject::getPos() {
	return position;
}

osg::Vec3 MovableObject::getVel() {
	return velocity;
}

osg::Vec3 MovableObject::getAcc() {
	return acceleration;
}

osg::Vec3 MovableObject::getDir() {
	return direction;
}

osg::Vec3 MovableObject::getDefaultDirection() {
	return defaultDirection;
}

char* MovableObject::getName() {
	return name;
}

osg::MatrixTransform* MovableObject::getForm() {
	return mform;
}

void MovableObject::dump() {
}

/* 位置,体勢の再計算のみ */
void MovableObject::frame() {
	osg::Matrixd roteMatrix;
	osg::Matrixd accMatrix;
	osg::Matrixd dirMatrix;

	direction += angularVelocity;
	accMatrix.makeTranslate(acceleration);
	roteMatrix.makeRotate(
		osg::Quat(
			defaultDirection.x(), osg::Vec3(1,0,0),
			defaultDirection.y(), osg::Vec3(0,1,0),
			defaultDirection.z(), osg::Vec3(0,0,1)
		)
	);

	velocity += (accMatrix*roteMatrix).getTrans();
	position += velocity;

	/* 3Dモデルが元々正面向きのため、90度補正の再計算 */
	/* 毎回計算が無駄だと思うので、ツール側で補正するべき */
	/*roteMatrix.makeRotate(
		osg::Quat(
			defaultDirection.x()+direction.x(), osg::Vec3(1,0,0),
			defaultDirection.y()+direction.y(), osg::Vec3(0,1,0),
			defaultDirection.z()+direction.z(), osg::Vec3(0,0,1)
		)
	);*/

	dirMatrix.makeTranslate(position);
	accMatrix.makeScale(scale);
	mform->setMatrix(accMatrix*accMatrix*roteMatrix);
}

void MovableObject::checkCollision() {
}

void MovableObject::collision(osg::Vec3 pos, osg::Vec3 reaction) {

}