Click here to Skip to main content
15,891,764 members
Articles / Desktop Programming / Win32

Half Life Game Level Viewer

Rate me:
Please Sign up or sign in to vote.
4.61/5 (23 votes)
7 Feb 2009CPOL26 min read 79.9K   2.3K   60  
DirectX based application to open and view Half Life 1 game files
//
//	Vector2.h
//
//	Copyright (c) Paul Higinbotham
//

#ifndef __VECTOR2_H_
#define __VECTOR2_H_


#include "Math.h"
#include <cassert>


namespace ZGraphics
{


template <typename TR>
class Vector2
{
public:
	Vector2();
	Vector2(TR fX, TR fY);
	Vector2(const TR fVector[2]);
	Vector2(const Vector2<TR> & rCopy);
	~Vector2() {}

	// Data access
	const TR & operator[] (size_t tIndex) const;
	TR & operator[] (size_t tIndex);
	const TR * GetPtr() const;
	TR * GetPtr();
	TR X() const;
	TR Y() const;

	// assignment
	Vector2 & operator= (const Vector2 & rhs);
	Vector2 & operator= (const float fVector[2]);

	// arithmetic
	Vector2 operator* (const Vector2 &rhs) const;
	Vector2 operator* (TR fScalar) const;
	Vector2 operator/ (TR fScalar) const;
	Vector2 operator+ (const Vector2 &rhs) const;
	Vector2 operator- (const Vector2 &rhs) const;
	Vector2 operator- () const;
	//
	Vector2 & operator*= (TR fScalar);
	Vector2 & operator/= (TR fScalar);
	Vector2 & operator+= (const Vector2 & rhs);
	Vector2 & operator-= (const Vector2 & rhs);

	// compare
	bool operator== (const Vector2 & rhs) const;
	bool operator!= (const Vector2 & rhs) const;

	// Other operations
	TR Dot(const Vector2& rVector)const;
	TR Normalize();
	TR Mag() const;
	TR MagSquared() const;
	Vector2 & ABS();
	Vector2 & Invert();

	// Class constants
	static const Vector2 cZero;
    static const Vector2 cUnitX;
    static const Vector2 cUnitY;

private:
	TR	m_vData[2];
};


// Include the implementation file
#include "Vector2.inl"


typedef Vector2<float> Vector2f;
typedef Vector2<double> Vector2d;


} /* namespace ZGraphics */


#endif /* __VECTOR2_H_ */

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
I am a senior software developer currently doing contract work for Microsoft. My educational background is in electrical engineering and I hold a masters degree from the University of Washington. I have experience in hardware and systems design but have done primarily software development for the last two decades. I have worked for various small companies as well as start-up companies, and have worked as a full time employee SDE at Microsoft Corporation.

Comments and Discussions