00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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;
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 {
00071 float a,b,c,e,f,g,h;
00072 float diffU, diffV;
00073
00074 diffU = vpwindow[1]-vpwindow[0];
00075 diffV = vpwindow[3]-vpwindow[2];
00076 dopN = -dopN;
00077
00078 if (dopN > 0) dopN = -dopN;
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) {
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);
00098
00099 }
00100 return 0;
00101 }
00102
00103 FACE &
00104 Projection::transform(FACE &input)
00105 {
00106 MYPOINT *point;
00107
00108
00109
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 {
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) {
00142 delete input;
00143 opserr << "HELP\n";
00144 return 0;
00145 } else {
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 }