⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 global.h

📁 浙江大学 RoboCup3D 2006 源代码
💻 H
字号:
/*************************************************************************** *   Copyright (C) 2004 - 2006 by ZJUBase                                  *
 *                                National Lab of Industrial Control Tech. * *                                Zhejiang University, China               *
*                                                                         * *   Team members:                                                         *
 *    Currently the team leader is,                                        * *           Hao JIANG (jianghao@iipc.zju.edu.cn; riveria@gmail.com)       *
 *    In the next season, the leader will be                               * *           Yifeng ZHANG (yfzhang@iipc.zju.edu.cn)                        *
 *    ZJUBase 3D agent is created by                                       * *           Dijun LUO (djluo@iipc.zju.edu.cn)                             *
 *    All the members who has ever contributed:                            * *           Jun JIANG                                                     *
 *           Xinfeng DU (xfdu@iipc.zju.edu.cn)                             *
 *           Yang ZHOU (yzhou@iipc.zju.edu.cn)                             *
 *           Zhipeng YANG                                                  *
 *           Xiang FAN                                                     *
 *                                                                         *
 *   Team Manager:                                                          *
 *      Ms. Rong XIONG (rxiong@iipc.zju.edu.cn)                            *
 *                                                                         *
 *   If you met any problems or you have something to discuss about        * *   ZJUBase. Please feel free to contact us through EMails given below.   * *                                                                         * *   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.             * ***************************************************************************/
#ifndef _GLOBAL_H_
#define _GLOBAL_H_

#pragma warning(disable:4786)
#pragma warning(disable:4503)
#define for if(0);else for

#include <math.h>
#include <gl/glaux.h>

const double pi = (double)acos(-1.);
const double eps = 1e-10;

class Vector2 {
public:
  double x;
  double y;

  Vector2(double vx = 0, double vy = 0) { x = vx; y = vy; }

  double mod(){return (double)sqrt(x*x + y*y );}
  double ang(){
    if(mod()>0)
        return (double)(( y>=0 ?  acos(x/mod()) : - acos(x/mod())) * 180/pi);
    return 0;
  }
  ~Vector2(){};
  double& operator[](int inx) { return inx == 1 ? y : x; }
  Vector2 operator -() { return Vector2(-x, -y); }
  Vector2 operator +(const Vector2 &a) { return Vector2(x + a.x, y + a.y); }
  Vector2 operator -(const Vector2 &a) { return Vector2(x - a.x, y - a.y); }
  Vector2 operator *(const double &a) { return Vector2(x * a, y * a); }
  Vector2 operator *(const Vector2 &a) { return Vector2(x * a.x, y * a.y); }
  Vector2 operator /(const double &a) { return Vector2(x / a, y / a); }
  Vector2 operator /(const Vector2 &a) { return Vector2(x / a.x, y / a.y); }
  void operator =(const double &a) { x = a; y = a; }
  void operator +=(const Vector2 &a) { x += a.x;  y += a.y; }
  void operator +=(const double &a) { x += a;  y += a; }
  void operator -=(const Vector2 &a) { x -= a.x;  y -= a.y; }
  void operator -=(const double &a) { x -= a;  y -= a; }
  void operator *=(const double &a) { x *= a;  y *= a; }
  void operator /=(const double &a) { x /= a;  y /= a; }
  operator !=(const Vector2 &a) { return (x != a.x) || (y != a.y); }
  operator !=(const double &a) { return (x != a) || (y != a); }
  operator ==(const Vector2 &a) { return (x == a.x) && (y == a.y); }
};

class Vector3 {
public:
  double x;
  double y;
  double z;
  Vector3(double vx = 0, double vy = 0,double vz = 0) { x = vx; y = vy;z=vz; }
  ~Vector3(){};
  double* GetData() { return &x; }
  double mod(){return (double)sqrt(x*x + y*y + z*z );}
  Vector3 Normalized() { if (mod() == 0) return *this; return *this / mod(); }
  double Dot(const Vector3 &a) const { return x * a.x + y * a.y + z * a.z; }
  Vector3 Cross(const Vector3 &a) const {
	  double xx = y * a.z - z * a.y;
	  double yy = z * a.x - x * a.z;
	  double zz = x * a.y - y * a.x;
	  return Vector3(xx, yy, zz);
  }
  double& operator[](int inx) { return inx == 2 ? z : (inx == 1 ? y : x); }
  Vector3 operator -() { return Vector3(-x, -y,-z); }
  Vector3 operator +(const Vector3 &a) { return Vector3(x + a.x, y + a.y,z+a.z); }
  Vector3 operator -(const Vector3 &a) { return Vector3(x - a.x, y - a.y,z-a.z); }
  Vector3 operator *(const double &a) { return Vector3(x * a, y * a, z*a); }
  Vector3 operator *(const Vector3 &a) { return Vector3(x * a.x, y * a.y,z*a.z); }
  Vector3 operator /(const double &a) { return Vector3(x / a, y / a,z/a); }
  Vector3 operator /(const Vector3 &a) { return Vector3(x / a.x, y / a.y,z/a.z); }
  Vector3 operator =(const double &a) { x = a; y = a; z=z; return *this; }
  Vector3 operator +=(const Vector3 &a) { x += a.x;  y += a.y; z +=a.z; return *this; }
  Vector3 operator +=(const double &a) { x += a;  y += a; z +=a; return *this; }
  Vector3 operator -=(const Vector3 &a) { x -= a.x;  y -= a.y; z -=a.z; return *this; }
  Vector3 operator -=(const double &a) { x -= a;  y -= a; z -=a; return *this; }
  Vector3 operator *=(const double &a) { x *= a;  y *= a; z*=a; return *this; }
  Vector3 operator /=(const double &a) { x /= a;  y /= a; z/=a; return *this; }
  bool operator !=(const Vector3 &a) { return (x != a.x) || (y != a.y) || (z != a.z); }
  bool operator !=(const double &a) { return (x != a) || (y != a) || (z != a); }
  bool operator ==(const Vector3 &a) { return (x == a.x) && (y == a.y) && (z == a.z); }
};

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -