Changeset 929


Ignore:
Timestamp:
Sep 8, 2011, 10:53:45 PM (8 years ago)
Author:
sam
Message:

core: add std::ostream operators for vector and matrix classes.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/matrix.cpp

    r758 r929  
    8181}
    8282
     83template<> std::ostream &operator<<(std::ostream &stream, ivec2 const &v)
     84{
     85    return stream << "(" << v.x << ", " << v.y << ")";
     86}
     87
     88template<> std::ostream &operator<<(std::ostream &stream, ivec3 const &v)
     89{
     90    return stream << "(" << v.x << ", " << v.y << ", " << v.z << ")";
     91}
     92
     93template<> std::ostream &operator<<(std::ostream &stream, ivec4 const &v)
     94{
     95    return stream << "(" << v.x << ", " << v.y << ", "
     96                         << v.z << ", " << v.w << ")";
     97}
     98
     99template<> std::ostream &operator<<(std::ostream &stream, vec2 const &v)
     100{
     101    return stream << "(" << v.x << ", " << v.y << ")";
     102}
     103
     104template<> std::ostream &operator<<(std::ostream &stream, vec3 const &v)
     105{
     106    return stream << "(" << v.x << ", " << v.y << ", " << v.z << ")";
     107}
     108
     109template<> std::ostream &operator<<(std::ostream &stream, vec4 const &v)
     110{
     111    return stream << "(" << v.x << ", " << v.y << ", "
     112                         << v.z << ", " << v.w << ")";
     113}
     114
     115template<> std::ostream &operator<<(std::ostream &stream, mat4 const &m)
     116{
     117    stream << "((" << m[0][0] << ", " << m[1][0]
     118            << ", " << m[2][0] << ", " << m[3][0] << "), ";
     119    stream << "(" << m[0][1] << ", " << m[1][1]
     120           << ", " << m[2][1] << ", " << m[3][1] << "), ";
     121    stream << "(" << m[0][2] << ", " << m[1][2]
     122           << ", " << m[2][2] << ", " << m[3][2] << "), ";
     123    stream << "(" << m[0][3] << ", " << m[1][3]
     124           << ", " << m[2][3] << ", " << m[3][3] << "))";
     125    return stream;
     126}
     127
    83128template<> mat4 mat4::ortho(float left, float right, float bottom,
    84129                            float top, float near, float far)
  • trunk/src/matrix.h

    r866 r929  
    1818
    1919#include <cmath>
     20#include <iostream>
    2021
    2122namespace lol
     
    126127        using namespace std; \
    127128        return sqrtf((float)sqlen()); \
    128     }
     129    } \
     130    \
     131    template<typename U> \
     132    friend std::ostream &operator<<(std::ostream &stream, \
     133                                    Vec##elems<U> const &v);
    129134
    130135template <typename T> struct Vec2;
     
    232237
    233238    void printf() const;
     239
     240    template<class U>
     241    friend std::ostream &operator<<(std::ostream &stream, Mat4<U> const &m);
    234242
    235243    inline Mat4<T> operator +(Mat4<T> const val) const
Note: See TracChangeset for help on using the changeset viewer.