Projection.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020                                                                         
00021 // $Revision: 1.2 $
00022 // $Date: 2003/02/14 23:01:58 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/renderer/Projection.cpp,v $
00024                                                                         
00025                                                                         
00026 #include "Projection.h"
00027 #include "View.h"
00028 
00029 Projection::Projection()
00030 {
00031   projection_mode = PERSPECTIVE_MODE;
00032 }
00033 
00034 Projection::~Projection()
00035 {
00036 
00037 }
00038 
00039 int
00040 Projection::update(void) {
00041 
00042   float midU, midV, dopU, dopV, dopN, shU, shV, F, B;
00043   float diffU, diffV;
00044   midU = (vpwindow[0] + vpwindow[1])/2;
00045   midV = (vpwindow[2] + vpwindow[3])/2;
00046   dopN = -cop[2];
00047   dopU = midU - cop[0];
00048   dopV = midV - cop[1];
00049 
00050   diffU = vpwindow[1]-vpwindow[0];
00051   diffV = vpwindow[3]-vpwindow[2];      
00052   
00053   shU = dopU/dopN;
00054   shV = dopV/dopN;
00055   F = planedist[0];
00056   B = planedist[2];
00057   if (F < 0) F = -F; // WARNING MESSAGES !!!
00058   if (B < 0) B = -B;
00059   
00060   if (projection_mode == PARALLEL_MODE) {
00061       
00062       if (F == -B)
00063           B = F;
00064 
00065       TMat.Set(   2.0/diffU,        0.0,          0.0,    0.0,
00066                         0.0,   2.0/diffV,         0.0,    0.0,
00067                 2*shU/diffV, 2*shV/diffV,      1/(F+B),    0.0,
00068                 -2*midU/diffU, -2*midV/diffV, -F/(F+B),    1.0);
00069 
00070   } else { // perspective projection
00071       float a,b,c,e,f,g,h;
00072       float diffU, diffV;// prpN;
00073 
00074       diffU = vpwindow[1]-vpwindow[0];
00075       diffV = vpwindow[3]-vpwindow[2];      
00076       dopN = -dopN; // dopN'
00077       
00078       if (dopN > 0) dopN = -dopN; // WARNING MESSAGE// WARNING MESSAGE
00079       a = 2*dopN/(diffU * (dopN - B));
00080       b = 2*dopN/(diffV * (dopN - B));
00081       c = -1.0/(dopN - B);
00082 
00083       float zMin = (dopN + F)*c;
00084       if (zMin >= 0) {  // WARNING MESSAGE
00085           F = -1.0e-8-dopN;
00086           zMin = -1.0e8;
00087       }
00088       e = 1/(1+zMin);
00089       f = -zMin * e;
00090       
00091       g = cop[0] - shU * cop[2];
00092       h = cop[1] - shV * cop[2];
00093   
00094       TMat.Set(     a,   0.0,         0.0,    0.0,
00095                   0.0,     b,         0.0,    0.0,
00096                 a*shU, b*shV,         e*c,     -c,
00097                  -a*g,  -b*h, e*c*dopN+f, -c*dopN);  // dopN = -cop[2]!
00098 
00099   }
00100   return 0;
00101 }
00102 
00103 FACE &
00104 Projection::transform(FACE &input)
00105 {
00106   MYPOINT *point;
00107   
00108   // transform all the points by the transformation matrix
00109   // remember that in previos pipeline all points were unmarked
00110   FOR_EACH(point, input.pointList) {
00111     point->Transform(&TMat);
00112     if (projection_mode == PERSPECTIVE_MODE) {
00113         float wVal = point->p[3];
00114       if (wVal == 0) {
00115         opserr << "Some Point in local coord sys at same level as eye\n";
00116         return input;
00117       }
00118       else { // we will homo x and y coord, but leave z as was befor we came in
00119         point->p[0] = point->p[0]/wVal;
00120         point->p[1] = point->p[1]/wVal;
00121         point->p[2] = point->p[2]/wVal;
00122         point->p[3] = 1.0;
00123       }
00124     }
00125   }
00126   
00127   return input;
00128 }
00129   
00130   
00131 MYPOINT *
00132 Projection::transformP(MYPOINT *input)
00133 {
00134     if (input == 0)
00135         return 0;
00136     
00137     input->Transform(&TMat);
00138 
00139     if (projection_mode == PERSPECTIVE_MODE) {
00140         float wVal = input->p[3];
00141         if (wVal == 0) { // point at eye position ignore delete it
00142             delete input;
00143             opserr << "HELP\n";
00144             return 0;
00145         } else { // we will homo x and y coord, but leave z as was befor we came in
00146             input->p[0] = input->p[0]/wVal;
00147             input->p[1] = input->p[1]/wVal;
00148             input->p[2] = input->p[2]/wVal;
00149             input->p[3] = 1.0;
00150         }       
00151     }
00152     return input;
00153 }

Generated on Mon Oct 23 15:05:27 2006 for OpenSees by doxygen 1.5.0