tailieunhanh - Object oriented Game Development -P7
Object oriented Game Development -P7: There’s a better than 50% chance that you have picked this title off the shelf in a bookshop and are wondering if it’s going to be another one of those ‘secrets of the inner circle’ type of titles. You know, the ones that promise to tell you unspoken truths on how to write really cool games but in reality offer up a rehash of a manual you may already have for free anyway. | 166 Object-oriented game development Bearing in mind that all these functions take a single argument and return a single value there isn t really a problem with having a procedural interface File include cmath namespace MATHS template class T inline T Sin T x return T sinf float x and so on_ Implementing our own transcendentals lets us control how the functions are evaluated. For example the trig functions can be implemented by table look-up though the days when that was a requirement are fast receding . Now it s time to consider the intermediate-level maths components. Interestingly they are generalisations of low-level components adding the ability to change size dynamically to those classes. This is accompanied by a growth in the computational cost of using these classes. The MATHS Vector class is a general-purpose mathematical vector. It is resizable like an array class but it supports all the arithmetical and mathematical operations of the low-level vector classes except the cross-product . File namespace MATHS template class T class Vector public Lifecycle. Vector int Size Vector const Vector T rVector Vector The component model for game development 167 Access. int GetSize const return m_iSize void SetSize int iNewSize Operators. Vector T operator const Vector T rVector T operator int n const T operator int n Vector T operator const Vector T rVector Vector T operator- const Vector T rVector Vector T operator T s friend T operator const Vector T v1 const Vector T v2 friend Vector T operator const Vector T v1 const Vector T v2 friend Vector T operator- const Vector T v1 const Vector T v2 friend Vector T operator T s const Vector T v friend Vector T operator const Vector T v T s friend bool operator const Vector T v1 const Vector T v2 const Vector T operator- Other processing. T Length const return Sqrt LengthSquared T LengthSquared const return this this void Normalise Vector T Normalised const void Fill T .
đang nạp các trang xem trước