FaceGen 3 SDKs Reference
Loading...
Searching...
No Matches
vect2.cpp
1//
2// Copyright (c) Singular Inversions Inc. 1998.
3//
4// File: vect2.cpp
5// Description: FR2Vect2TC class definitions
6// Authors: Andrew Beatty
7// Created: Aug 11, 1998
8//
9
10#include "stdafx.h"
11
12#include "vect2.hpp"
13
14namespace Fg {
15
16// Returns the vector rotated counter-clockwise around the Z axis (rhr)
17// by theta radians. Since we want to define it for float and double but
18// not for int, we must define it twice, once for each instantiation:
19//
20template<>
21const FR2Vect2DC FR2Vect2DC::rotate(
22
23 double theta)
24 const
25{
26 double cosine=cos(theta),
27 sine=sin(theta);
28 FR2Vect2TC retval;
29
30 retval.x1 = x1 * cosine - x2 * sine;
31 retval.x2 = x2 * cosine + x1 * sine;
32
33 return(retval);
34}
35
36template<>
37const FR2Vect2FC FR2Vect2FC::rotate(
38
39 float theta)
40 const
41{
42 float cosine = (float)cos(theta),
43 sine = (float)sin(theta);
44 FR2Vect2TC retval;
45
46 retval.x1 = x1 * cosine - x2 * sine;
47 retval.x2 = x2 * cosine + x1 * sine;
48
49 return(retval);
50}
51
52//***********************************************************************
53// Stream Operators
54//***********************************************************************
55
56std::ostream& operator<<(std::ostream& s,FR2Vect2IC vec)
57{
58 return s << "(" << vec.x1 << "," << vec.x2 << ")";
59}
60
61std::ostream& operator<<(std::ostream& s,FR2Vect2FC vec)
62{
63 std::ios::fmtflags oldFlag = s.setf(std::ios::fixed|std::ios::showpos|std::ios::right);
64 std::streamsize oldPrec = s.precision(4);
65 s << "(" << vec.x1 << "," << vec.x2 << ")";
66 s.setf(oldFlag);
67 s.precision(oldPrec);
68 return s;
69}
70
71std::ostream& operator<<(std::ostream& s,FR2Vect2DC vec)
72{
73 std::ios::fmtflags oldFlag = s.setf(std::ios::fixed|std::ios::showpos|std::ios::right);
74 std::streamsize oldPrec = s.precision(4);
75 s << "(" << vec.x1 << "," << vec.x2 << ")";
76 s.setf(oldFlag);
77 s.precision(oldPrec);
78 return s;
79}
80
81}