00001
00055 #define _EXPORT_CCL_
00056
00057 #include "CigiViewDefV1.h"
00058 #include "CigiSwapping.h"
00059 #include "CigiExceptions.h"
00060
00061 #include <memory.h>
00062
00063
00064 #ifdef CIGI_LITTLE_ENDIAN
00065 #define CIGI_SCOPY2 CigiSwap2
00066 #define CIGI_SCOPY4 CigiSwap4
00067 #define CIGI_SCOPY8 CigiSwap8
00068 #else
00069 #define CIGI_SCOPY2 CigiCopy2
00070 #define CIGI_SCOPY4 CigiCopy4
00071 #define CIGI_SCOPY8 CigiCopy8
00072 #endif
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 CigiViewDefV1::CigiViewDefV1()
00085 {
00086
00087 PacketID = CIGI_VIEW_DEF_PACKET_ID_V1;
00088 PacketSize = CIGI_VIEW_DEF_PACKET_SIZE_V1;
00089 Version = 1;
00090 MinorVersion = 0;
00091
00092 ViewID = 0;
00093 GroupID = 0;
00094 FOVNearEn = true;
00095 FOVFarEn = true;
00096 FOVLeftEn = true;
00097 FOVRightEn = true;
00098 FOVTopEn = true;
00099 FOVBottomEn = true;
00100 MirrorMode = MirrorNone;
00101 PixelReplicateMode = ReplicateNone;
00102 ProjectionType = Perspective;
00103 Reorder = false;
00104 ViewType = 0;
00105 TrackerAssigned = false;
00106 FOVNear = 0.0;
00107 FOVFar = 0.0;
00108 FOVLeft = 0.0;
00109 FOVRight = 0.0;
00110 FOVTop = 0.0;
00111 FOVBottom = 0.0;
00112
00113 }
00114
00115
00116
00117
00118 CigiViewDefV1::~CigiViewDefV1()
00119 {
00120
00121 }
00122
00123
00124
00125
00126
00127
00128
00129
00130 int CigiViewDefV1::Pack(CigiBasePacket * Base, Cigi_uint8 * Buff, void *Spec) const
00131 {
00132 double DBuf[6];
00133
00134 Cigi_uint8 *tBuf = (Cigi_uint8 *)DBuf;
00135
00136 PackPointer CDta;
00137
00138 CigiBaseViewDef * Data = ( CigiBaseViewDef *)Base;
00139
00140 CDta.d = DBuf;
00141
00142 *CDta.c++ = PacketID;
00143 *CDta.c++ = PacketSize;
00144
00145 Cigi_uint8 HDta = 0;
00146 if(Data->ViewID < 32)
00147 HDta = (Cigi_uint8)(Data->ViewID << 3);
00148 else
00149 HDta = (Cigi_uint8)0xf8;
00150
00151 if(Data->GroupID < 8)
00152 HDta |= (Cigi_uint8)Data->GroupID;
00153 else
00154 HDta |= 7;
00155
00156 *CDta.c++ = HDta;
00157
00158 HDta = (Data->ViewType << 5) & 0xe0;
00159 HDta |= (Cigi_uint8)((Data->PixelReplicateMode << 2) & 0x1c);
00160 HDta |= (Cigi_uint8)(Data->MirrorMode & 0x03);
00161
00162 *CDta.c++ = HDta;
00163
00164 HDta = 0;
00165 if(Data->TrackerAssigned)
00166 HDta = 0x80;
00167
00168 *CDta.c++ = HDta;
00169 *CDta.c++ = 0;
00170 *CDta.s++ = 0;
00171
00172 CIGI_SCOPY4(CDta.f++, &Data->FOVNear);
00173 CIGI_SCOPY4(CDta.f++, &Data->FOVFar);
00174 CIGI_SCOPY4(CDta.f++, &Data->FOVLeft);
00175 CIGI_SCOPY4(CDta.f++, &Data->FOVRight);
00176 CIGI_SCOPY4(CDta.f++, &Data->FOVTop);
00177 CIGI_SCOPY4(CDta.f++, &Data->FOVBottom);
00178
00179 memcpy(Buff,tBuf,CIGI_VIEW_DEF_PACKET_SIZE_V1);
00180
00181 return(PacketSize);
00182
00183 }
00184
00185
00186
00187
00188 int CigiViewDefV1::Unpack(Cigi_uint8 * Buff, bool Swap, void *Spec)
00189 {
00190 double DBuf[6];
00191
00192 Cigi_uint8 *tBuf = (Cigi_uint8 *)DBuf;
00193
00194 PackPointer CDta;
00195
00196 memcpy(tBuf,Buff,CIGI_VIEW_DEF_PACKET_SIZE_V1);
00197
00198 CDta.d = DBuf;
00199
00200 CDta.c += 2;
00201
00202 Cigi_uint8 HDta = *CDta.c++;
00203
00204 ViewID = (Cigi_uint8)((HDta >> 3) & 0x1f);
00205 GroupID = (Cigi_uint8)(HDta & 0x07);
00206
00207 HDta = *CDta.c++;
00208
00209 ViewType = (Cigi_uint8)((HDta >> 5) & 0x07);
00210 PixelReplicateMode = (PixelReplicateModeGrp)((HDta >> 2) & 0x07);
00211 MirrorMode = (MirrorModeGrp)(HDta & 0x03);
00212
00213 HDta = *CDta.c ++ & 0x80;
00214
00215 TrackerAssigned = (HDta == 0) ? false : true;
00216
00217 CDta.c += 3;
00218
00219 CIGI_SCOPY4(&FOVNear, CDta.f++);
00220 CIGI_SCOPY4(&FOVFar, CDta.f++);
00221 CIGI_SCOPY4(&FOVLeft, CDta.f++);
00222 CIGI_SCOPY4(&FOVRight, CDta.f++);
00223 CIGI_SCOPY4(&FOVTop, CDta.f++);
00224 CIGI_SCOPY4(&FOVBottom, CDta.f++);
00225
00226 return(PacketSize);
00227
00228 }
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239 int CigiViewDefV1::SetViewID(const Cigi_uint8 ViewIDIn, bool bndchk)
00240 {
00241
00242 #ifndef CIGI_NO_BND_CHK
00243 if(bndchk && ((ViewIDIn < 0)||(ViewIDIn > 31)))
00244 {
00245 #ifndef CIGI_NO_EXCEPT
00246 throw CigiValueOutOfRangeException("ViewID",(Cigi_uint16)ViewIDIn,0,31);
00247 #endif
00248 return(CIGI_ERROR_VALUE_OUT_OF_RANGE);
00249 }
00250 #endif
00251
00252 ViewID = (Cigi_uint16)ViewIDIn;
00253 return(CIGI_SUCCESS);
00254
00255 }
00256
00257
00258
00259
00260
00261 int CigiViewDefV1::SetGroupID(const Cigi_uint8 GroupIDIn, bool bndchk)
00262 {
00263
00264 #ifndef CIGI_NO_BND_CHK
00265 if(bndchk && ((GroupIDIn < 0)||(GroupIDIn > 7)))
00266 {
00267 #ifndef CIGI_NO_EXCEPT
00268 throw CigiValueOutOfRangeException("GroupID",(Cigi_uint16)GroupIDIn,0,7);
00269 #endif
00270 return(CIGI_ERROR_VALUE_OUT_OF_RANGE);
00271 }
00272 #endif
00273
00274 GroupID = GroupIDIn;
00275 return(CIGI_SUCCESS);
00276
00277 }
00278