📄 vector3.cpp
字号:
/* Combat Simulator Project * Copyright (C) 2002, 2003 Mark Rose <mkrose@users.sf.net> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *//** * @file Vector3.cpp * * A three-dimensional vector class. * * This source code was originally based on the Vec3 class of * the OpenSceneGraph library, Copyright 1998-2003 Robert Osfield. * Source code from OpenSceneGraph is used here under the GNU General * Public License Version 2 or later, as permitted under the * OpenSceneGraph Public License Version 0.0 (exception 3) and the GNU * Lesser Public License Version 2 (clause 3). **///#ifdef WIN32
#include "stdafx.h"
//#endif
#include "Vector3.h"#include "Matrix3.h"
#include "Quat.h"#include <iomanip>#include <sstream>/// Null vectorconst Vector3 Vector3::ZERO (0.0, 0.0, 0.0);/// Unit vector in Xconst Vector3 Vector3::XAXIS(1.0, 0.0, 0.0);/// Unit vector in Yconst Vector3 Vector3::YAXIS(0.0, 1.0, 0.0);/// Unit vector in Zconst Vector3 Vector3::ZAXIS(0.0, 0.0, 1.0);Matrix3 Vector3::starMatrix() const { return Matrix3(0.0, -_z, _y, _z, 0.0, -_x, -_y, _x, 0.0);}std::string Vector3::asString() const { std::ostringstream os; os << "[" << std::setw(8) << x() << " " << std::setw(8) << y() << " " << std::setw(8) << z() << "]"; return os.str();}
#ifdef WIN32void Vector3::serialize(CArchive* ar) {
if(ar->IsLoading())
(*ar) >> _x >> _y >> _z;
else
(*ar) << _x << _y << _z;}
#endif// Binary multiply --- adjusted relative to osg for active transformations!
//const Quat Vector3::operator*(const Quat& rhs) const {
// return Quat(rhs._w*_x + - rhs._y*_z + rhs._z*_y,
// rhs._w*_y + rhs._x*_z + - rhs._z*_x,
// rhs._w*_z - rhs._x*_y + rhs._y*_x ,
// - rhs._x*_x - rhs._y*_y - rhs._z*_z);
//}void Vector3::parseXML(const char* cdata) { int n = sscanf(cdata, "%lf %lf %lf", &_x, &_y, &_z); if (n!=3) throw std::string("SYNTAX ERROR: expecting 3 floats");}std::ostream &operator <<(std::ostream &o, Vector3 const &v) { return o << v.asString(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -