<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>matrix.cpp Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body bgcolor="#ffffff"> <!-- Generated by Doxygen 1.2.13.1 --> <center> <a class="qindex" href="main.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; </center> <hr><h1>matrix.cpp</h1><a href="matrix_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">/***************************************************************************</font> 00002 <font class="comment">                          matrix.cpp  -  description</font> 00003 <font class="comment">                             -------------------</font> 00004 <font class="comment">    begin                : Tue Jul 24 2002</font> 00005 <font class="comment">    copyright            : (C) 2002 by Marco Bubke</font> 00006 <font class="comment">    email                : marco@bubke.de</font> 00007 <font class="comment"> ***************************************************************************/</font> 00008  00009 <font class="comment">/***************************************************************************</font> 00010 <font class="comment"> *                                                                         *</font> 00011 <font class="comment"> *   This program is free software; you can redistribute it and/or modify  *</font> 00012 <font class="comment"> *   it under the terms of the GNU Lesser General Public License as        *</font> 00013 <font class="comment"> *   published by the Free Software Foundation; 2.1 of the License.        *</font> 00014 <font class="comment"> *                                                                         *                                                                         *</font> 00015 <font class="comment"> ***************************************************************************/</font> 00016  00017 <font class="preprocessor">#include "<a class="code" href="matrix_8h.html">matrix.h</a>"</font> 00018 <font class="preprocessor">#include "math.h"</font> 00019  00020 <font class="keyword">namespace </font>Ah { 00021  <a name="l00022"></a><a class="code" href="classAh_1_1Matrix.html#a0">00022</a> Matrix::Matrix() 00023     : ReferenceCounter(), pivotx(0), pivoty(0) 00024 { 00025     <a class="code" href="classAh_1_1Matrix.html#a8">setIdentity</a>(); 00026 } 00027  <a name="l00028"></a><a class="code" href="classAh_1_1Matrix.html#a8">00028</a> <font class="keywordtype">void</font> Matrix::setIdentity() 00029 { 00030     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[0] = 1.0; 00031     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[1] = 0.0; 00032     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[2] = 0.0; 00033     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[3] = 0.0; 00034     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[4] = 0.0; 00035     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[5] = 1.0; 00036     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[6] = 0.0; 00037     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[7] = 0.0; 00038     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[8] = 0.0; 00039     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[9] = 0.0; 00040     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[10] = 1.0; 00041     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[11] = 0.0; 00042     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[12] = 0.0; 00043     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[13] = 0.0; 00044     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[14] = 0.0; 00045     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[15] = 1.0; 00046 } 00047  <a name="l00048"></a><a class="code" href="classAh_1_1Matrix.html#a4">00048</a> <font class="keywordtype">void</font> Matrix::scale(<font class="keywordtype">float</font> x, <font class="keywordtype">float</font> y) 00049 { 00050     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[0] *= x; 00051     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[1] *= x; 00052     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[4] *= y; 00053     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[5] *= y; 00054 } 00055  <a name="l00056"></a><a class="code" href="classAh_1_1Matrix.html#a5">00056</a> <font class="keywordtype">void</font> Matrix::scale(<font class="keywordtype">float</font> factor) 00057 { 00058     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[0] *= factor; 00059     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[1] *= factor; 00060     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[4] *= factor; 00061     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[5] *= factor; 00062 } 00063  <a name="l00064"></a><a class="code" href="classAh_1_1Matrix.html#a1">00064</a> <font class="keywordtype">void</font> Matrix::move(<font class="keywordtype">float</font> x, <font class="keywordtype">float</font> y) 00065 { 00066     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[12] += -x * <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[0] + -y * <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[4]; 00067     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[13] += -x * <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[1] + -y * <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[5]; 00068 } 00069  <a name="l00070"></a><a class="code" href="classAh_1_1Matrix.html#a2">00070</a> <font class="keywordtype">void</font> Matrix::zoom(<font class="keywordtype">float</font> factor) 00071 { 00072     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[0] *= 1/factor; 00073     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[1] *= 1/factor; 00074     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[4] *= 1/factor; 00075     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[5] *= 1/factor; 00076 } 00077  <a name="l00078"></a><a class="code" href="classAh_1_1Matrix.html#a3">00078</a> <font class="keywordtype">void</font> Matrix::rotate(<font class="keywordtype">float</font> angle) 00079 { 00080     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[12] += <a class="code" href="classAh_1_1Matrix.html#o0">pivotx</a> * <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[0] + <a class="code" href="classAh_1_1Matrix.html#o1">pivoty</a> * <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[4]; 00081     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[13] += <a class="code" href="classAh_1_1Matrix.html#o0">pivotx</a> * <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[1] + <a class="code" href="classAh_1_1Matrix.html#o1">pivoty</a> * <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[5]; 00082     <font class="keywordtype">float</font> cosinus = cosf(angle); 00083     <font class="keywordtype">float</font> sinus = sinf(angle); 00084     <font class="keywordtype">float</font> tmp0 = <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[0] * cosinus + <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[4] * sinus; 00085     <font class="keywordtype">float</font> tmp1 = <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[1] * cosinus + <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[5] * sinus; 00086     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[4] = <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[0] * -sinus + <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[4] * cosinus; 00087     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[5] = <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[1] * -sinus + <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[5] * cosinus; 00088     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[0] = tmp0; 00089     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[1] = tmp1; 00090     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[12] += -<a class="code" href="classAh_1_1Matrix.html#o0">pivotx</a> * <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[0] + -<a class="code" href="classAh_1_1Matrix.html#o1">pivoty</a> * <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[4]; 00091     <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[13] += -<a class="code" href="classAh_1_1Matrix.html#o0">pivotx</a> * <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[1] + -<a class="code" href="classAh_1_1Matrix.html#o1">pivoty</a> * <a class="code" href="classAh_1_1Matrix.html#o2">matrix</a>[5]; 00092  } 00093  <a name="l00094"></a><a class="code" href="classAh_1_1Matrix.html#a6">00094</a> <font class="keywordtype">void</font> Matrix::movePivot(<font class="keywordtype">float</font> x, <font class="keywordtype">float</font> y) 00095 { 00096     <a class="code" href="classAh_1_1Matrix.html#o0">pivotx</a> += x; 00097     <a class="code" href="classAh_1_1Matrix.html#o1">pivoty</a> += y; 00098 } 00099  <a name="l00100"></a><a class="code" href="classAh_1_1Matrix.html#a7">00100</a> <font class="keywordtype">void</font> Matrix::movePivotTo(<font class="keywordtype">float</font> x, <font class="keywordtype">float</font> y) 00101 { 00102     <a class="code" href="classAh_1_1Matrix.html#o0">pivotx</a> = x; 00103     <a class="code" href="classAh_1_1Matrix.html#o1">pivoty</a> = y; 00104 } 00105  00106 <font class="comment">/*</font> 00107 <font class="comment">void Matrix::rotate(float angle)</font> 00108 <font class="comment">{</font> 00109 <font class="comment">    float cosinus = cosf(angle);</font> 00110 <font class="comment">    float sinus = sinf(angle);</font> 00111 <font class="comment">    float  tmp1 = cosinus * matrix[0] + -sinus * matrix[1];</font> 00112 <font class="comment">    matrix[1] = sinus * matrix[0] + cosinus * matrix[1];</font> 00113 <font class="comment">    matrix[0] = tmp1;</font> 00114 <font class="comment">    float tmp4 = cosinus * matrix[4] + -sinus * matrix[5];</font> 00115 <font class="comment">    matrix[5] = sinus * matrix[4] + cosinus * matrix[5];</font> 00116 <font class="comment">    matrix[4] = tmp4;</font> 00117 <font class="comment">    float tmp12 = cosinus * matrix[12] + -sinus * matrix[13];</font> 00118 <font class="comment">    matrix[13] = sinus * matrix[12] + cosinus * matrix[13];</font> 00119 <font class="comment">    matrix[12] = tmp12;</font> 00120 <font class="comment">}</font> 00121 <font class="comment"></font> 00122 <font class="comment">void Matrix::move(float x, float y)</font> 00123 <font class="comment">{</font> 00124 <font class="comment">    matrix[12] += -x * matrix[15];</font> 00125 <font class="comment">    matrix[13] += -y * matrix[15];</font> 00126 <font class="comment">}</font> 00127 <font class="comment"></font> 00128 <font class="comment">void Matrix::zoom(float zoom)</font> 00129 <font class="comment">{</font> 00130 <font class="comment">    matrix[15] *= zoom;</font> 00131 <font class="comment">}</font> 00132 <font class="comment"></font> 00133 <font class="comment">void Matrix::scale(float x, float y)</font> 00134 <font class="comment">{</font> 00135 <font class="comment">    matrix[0] *= x;</font> 00136 <font class="comment">    matrix[1] *= x;</font> 00137 <font class="comment">    matrix[4] *= y;</font> 00138 <font class="comment">    matrix[5] *= y;</font> 00139 <font class="comment">    matrix[12] *=  x;</font> 00140 <font class="comment">    matrix[13] *=  y;</font> 00141 <font class="comment">}</font> 00142 <font class="comment"></font> 00143 <font class="comment">void Matrix::scale(float factor)</font> 00144 <font class="comment">{</font> 00145 <font class="comment">    matrix[0] *= factor;</font> 00146 <font class="comment">    matrix[1] *= factor;</font> 00147 <font class="comment">    matrix[4] *= factor;</font> 00148 <font class="comment">    matrix[5] *= factor;</font> 00149 <font class="comment">    matrix[12] *= factor;</font> 00150 <font class="comment">    matrix[13] *= factor;</font> 00151 <font class="comment"></font> 00152 <font class="comment">}</font> 00153 <font class="comment">*/</font> 00154 }; </pre></div><hr><address><small>Generated on Mon Jul 29 23:48:59 2002 for Athene by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.gif" alt="doxygen" align="middle" border=0  width=110 height=53></a>1.2.13.1 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>,  &copy;&nbsp;1997-2001</small></address> </body> </html> 
