Exemple #1
0
void Camera::handleKeyboard(float delta)
{

	int moveLeft = InputHandler::getKeystate(GLFW_KEY_A) != GLFW_RELEASE ? -1 : 0;
	int moveRight = InputHandler::getKeystate(GLFW_KEY_D) != GLFW_RELEASE ? 1 : 0;
	int moveForward = InputHandler::getKeystate(GLFW_KEY_W) != GLFW_RELEASE ? 1 : 0;
	int moveBackward = InputHandler::getKeystate(GLFW_KEY_S) != GLFW_RELEASE ? -1 : 0;

	float trans_factor = translation_speed * delta;

	translateLocal((moveLeft + moveRight)*trans_factor, 0, (moveForward + moveBackward)*trans_factor);

	int rotateLeft = InputHandler::getKeystate(GLFW_KEY_LEFT) != GLFW_RELEASE ? -1 : 0;
	int rotateRight = InputHandler::getKeystate(GLFW_KEY_RIGHT) != GLFW_RELEASE ? 1 : 0;
	int rotateUp = InputHandler::getKeystate(GLFW_KEY_UP) != GLFW_RELEASE ? 1 : 0;
	int rotateDown = InputHandler::getKeystate(GLFW_KEY_DOWN) != GLFW_RELEASE ? -1 : 0;

	float rot_factor = rotation_speed * delta;

	updateRotation((rotateLeft + rotateRight)*rot_factor, (rotateUp + rotateDown)*rot_factor);
}
Exemple #2
0
void Matrix44::translateLocal(Vector v){
    translateLocal(v[0], v[1], v[2]);
}
Exemple #3
0
void Object3D::moveDown(float distance)
{
	translateLocal(Vector3D::Y_AXIS, -distance);
}
Exemple #4
0
void Object3D::moveRight(float distance)
{
	translateLocal(Vector3D::X_AXIS, distance);
}
Exemple #5
0
void Object3D::moveLeft(float distance)
{
	translateLocal(Vector3D::X_AXIS, -distance);
}
Exemple #6
0
void Object3D::moveBackward(float distance)
{
	translateLocal(Vector3D::Z_AXIS, -distance);
}
void SceneGraphComponent::executeEvent(GameEvent *event)
{
	switch (event->id())
	{
	case GameEvent::E_SET_TRANSFORMATION:
		setTransformation(static_cast<const float*>(event->data()));
		break;
	case GameEvent::E_TRANSFORMATION:
		memcpy(static_cast<float*>(event->data()), m_transformation, sizeof(float) * 16);
		break;
	case GameEvent::E_SET_TRANSLATION:
		{
			Vec3f* translation = static_cast<Vec3f*>(event->data());
			m_transformation[12] = translation->x;
			m_transformation[13] = translation->y;
			m_transformation[14] = translation->z;
			sendTransformation();
		}
		break;
	case GameEvent::E_SET_SCALE:
		setScale(static_cast<Vec3f*>(event->data()));
		break;
	case GameEvent::E_MESH_DATA:
		getMeshData(static_cast<MeshData*>(event->data()));
		break;
	case GameEvent::E_TRANSLATE_LOCAL:
		translateLocal(static_cast<Vec3f*>(event->data()));
		break;
	case GameEvent::E_TRANSLATE_GLOBAL:
		translateGlobal(static_cast<Vec3f*>(event->data()));
		break;
	case GameEvent::E_ROTATE_LOCAL:
		rotate(static_cast<Vec3f*>(event->data()));
		break;
	case GameEvent::E_SET_ROTATION:
		setRotation(static_cast<Vec3f*>(event->data()));
		break;
	case GameEvent::E_ATTACH:
		attach(static_cast<Attach*>(event->data()));
		break;	
	case GameEvent::E_SET_NODE_PARENT:
		setParentNode(static_cast<Attach*>(event->data()));
		break;
	case GameEvent::E_MORPH_TARGET:
		if (m_hordeID > 0)
		{
			h3dSetModelMorpher(m_hordeID, static_cast<MorphTarget*>(event->data())->Name, static_cast<MorphTarget*>(event->data())->Value);
			h3dUpdateModel(m_hordeID, H3DModelUpdateFlags::Geometry );		
		}
		break;
	case GameEvent::E_ACTIVATE_CAM:
		if (m_hordeID > 0 && h3dGetNodeType(m_hordeID) == H3DNodeTypes::Camera)
			SceneGraphManager::instance()->setActiveCam( m_hordeID );
		break;
	case GameEvent::E_SET_ANIM_FRAME:
		{
			if (m_hordeID > 0)
			{
				const SetAnimFrame* const data = static_cast<SetAnimFrame*>(event->data());			
				h3dSetModelAnimParams(m_hordeID, data->Stage, data->Time, data->Weight);	
				h3dUpdateModel(m_hordeID, H3DModelUpdateFlags::Animation | H3DModelUpdateFlags::Geometry );		
			}
		}
		break;
	case GameEvent::E_SET_ENABLED:
		setEnabled(*static_cast<bool*>(event->data()));
		break;
	case GameEvent::E_GET_VISIBILITY:
		{
			bool* visible = static_cast<bool*>(event->data());
			if (visible)
				*visible = getVisibility();
		}
		break;
	case GameEvent::E_GET_PROJECTION_MATRIX:
		{
			float* mat = static_cast<float*>(event->data());
			SceneGraphManager::instance()->getCameraProjectionMatrix(mat);
		}
		break;
	case GameEvent::E_GET_ACTIVE_CAM:
		if (SceneGraphManager::instance()->getActiveCam() == m_hordeID)
		{
			unsigned int* id = static_cast<unsigned int*>(event->data());
			if (id)
				*id = m_owner->worldId();
		}
		break;
	case GameEvent::E_GET_SCENEGRAPH_ID:
		{
			int* id = static_cast<int*>(event->data());
			if (id)
				*id = m_hordeID;
		}
		break;
	}
}