Alphabetical Class Index  Class Hierarchy   File Members   Compound Members   File List  

HW3DStream.h
00001 //
00002 // Copyright (c) 2005 by Tech Soft 3D, LLC.
00003 // The information contained herein is confidential and proprietary to
00004 // Tech Soft 3D, LLC., and considered a trade secret as defined under
00005 // civil and criminal statutes.  Tech Soft 3D shall pursue its civil
00006 // and criminal remedies in the event of unauthorized use or misappropriation
00007 // of its trade secrets.  Use of this information by anyone other than
00008 // authorized employees of Tech Soft 3D, LLC. is granted only under a
00009 // written non-disclosure agreement, expressly prescribing the scope and
00010 // manner of such use.
00011 //
00012 // $Id$
00013 //
00014 
00015 
00016 #ifndef _HDWFSTREAM_H
00017 #define _HDWFSTREAM_H
00018 
00019 #include "hc.h"
00020 #include "HStream.h"
00021 
00022 
00023 class HW3DPoint 
00024 { 
00025 public:
00026     float       x;  
00027     float       y;  
00028     float       z;  
00029 
00031     HW3DPoint() : x(0), y(0), z(0) {}
00033     HW3DPoint(float X, float Y, float Z=0.0f) : x(X), y(Y), z(Z) {}
00035     HW3DPoint(HW3DPoint const *p) { x = p->x; y = p->y; z = p->z;};
00037     HW3DPoint(const HW3DPoint & p) { x = p.x; y = p.y; z = p.z; };
00038 
00040     void Set(float X,float Y,float Z = 0.0f) { x = X; y = Y; z = Z; };
00042     void Set(HW3DPoint * p) { x = p->x; y = p->y; z = p->z; };
00044     void Set(HW3DPoint const * p) { x = p->x; y = p->y; z = p->z; };
00046     void Set(HW3DPoint & p) { x = p.x; y = p.y; z = p.z; };
00048     void Set(const HW3DPoint & p) { x = p.x; y = p.y; z = p.z; };
00049 };
00050 
00051 class HW3DCamera {
00052 public:
00053     bool        is_valid;       
00054     HW3DPoint   position;       
00055     HW3DPoint   target;         
00056     HW3DPoint   up_vector;      
00057     float       field_width;    
00058     float       field_height;   
00059     char        projection[128];
00060 };
00061 
00062 class HW3DStream_Initial_View : public HTK_Camera 
00063 {
00064 public:
00065     HW3DStream_Initial_View(HW3DCamera * initial_view) : HTK_Camera(TKE_View), m_pInitialCamera(initial_view) {;}
00066 
00067     TK_Status Interpret(BStreamFileToolkit & /*tk*/, ID_Key /*key*/, int /*variant*/)
00068     {
00069         if(!m_pInitialCamera)
00070             return TK_Normal;
00071 
00072         m_settings[0] = m_pInitialCamera->position.x; 
00073         m_settings[1] = m_pInitialCamera->position.y; 
00074         m_settings[2] = m_pInitialCamera->position.z;
00075 
00076         m_settings[3] = m_pInitialCamera->target.x; 
00077         m_settings[4] = m_pInitialCamera->target.y; 
00078         m_settings[5] = m_pInitialCamera->target.z;
00079 
00080         m_settings[6] = m_pInitialCamera->up_vector.x; 
00081         m_settings[7] = m_pInitialCamera->up_vector.y; 
00082         m_settings[8] = m_pInitialCamera->up_vector.z;
00083 
00084         m_settings[9]  = m_pInitialCamera->field_width; 
00085         m_settings[10] = m_pInitialCamera->field_height;
00086 
00087         if(m_pInitialCamera->projection[0] == 'p')
00088             m_projection = TKO_Camera_Perspective;
00089         else
00090             m_projection = TKO_Camera_Orthographic;
00091 
00092         SetView("default");
00093 
00094         return TK_Normal;
00095     }
00096 
00097 
00098     TK_Status Execute(BStreamFileToolkit & /*tk*/) alter
00099     {
00100         TK_Status status=TK_Normal;
00101 
00102         if (!strcmp(GetView(),"default"))
00103         {
00104             m_pInitialCamera->is_valid = true;
00105 
00106             m_pInitialCamera->position.Set(m_settings[0],m_settings[1],m_settings[2]);
00107             m_pInitialCamera->target.Set(m_settings[3],m_settings[4],m_settings[5]);
00108             m_pInitialCamera->up_vector.Set(m_settings[6],m_settings[7],m_settings[8]);
00109             m_pInitialCamera->field_width = m_settings[9];
00110             m_pInitialCamera->field_height = m_settings[10];
00111 
00112             switch ((int) m_projection) {
00113 
00114                 case TKO_Camera_Orthographic:   
00115                     strcpy_s (m_pInitialCamera->projection, "orthographic");    
00116                     break;
00117                 
00118                 case TKO_Camera_Perspective:    
00119                     strcpy_s (m_pInitialCamera->projection, "perspective"); 
00120                     break;
00121                 
00122                 default: 
00123                     strcpy_s (m_pInitialCamera->projection, "stretched"); 
00124                     break;
00125             }
00126 
00127         }
00128 
00129         return (status);
00130     };
00131 
00132 private:
00133     HW3DCamera * m_pInitialCamera;
00134 
00135 };
00136 #if 0
00137 // Translate all the TKE_Image's to W3DE_Image
00138 class HW3DStream_Image_Converter : public HTK_Image
00139 {
00140 private:
00141     HW3DStream_Image_Converter(const HW3DStream_Image_Converter&);
00142     HW3DStream_Image_Converter& operator=(const HW3DStream_Image_Converter&);
00143 
00144 public:
00145 
00146     HW3DStream_Image_Converter ()
00147     { 
00148         m_opcode = W3DE_Image;
00149         m_size[0] = m_size[1] = 0; 
00150     }
00151     
00152     ~HW3DStream_Image_Converter()
00153     {
00154         delete [] m_name;
00155     }
00156 
00157     TK_Status   Write (BStreamFileToolkit & tk) alter
00158     {
00159         TK_Status status = TK_Normal;
00160 
00161         switch (m_stage) {
00162         case 0: {
00163             if ((status = PutOpcode (tk)) != TK_Normal)
00164                 return status;
00165             m_stage++;
00166                 }
00167 
00168         case 1: {
00169 
00170             if (m_name_length > 0) {
00171                 unsigned char byte = (unsigned char)m_name_length;
00172                 // need handling for string > 255 ?
00173                 if ((status = PutData (tk, byte)) != TK_Normal)
00174                     return status;
00175             }
00176             m_stage++;
00177                 }
00178 
00179         case 2: {
00180             if (m_name_length > 0) {
00181                 if ((status = PutData (tk, m_name, m_name_length)) != TK_Normal)
00182                     return status;
00183             }
00184             m_stage++;
00185                 }
00186         case 3:
00187             {
00188                 if ((status = PutData(tk, m_size[0])) != TK_Normal)
00189                     return status;
00190                 if ((status = PutData(tk, m_size[1])) != TK_Normal)
00191                     return status;
00192                 if ((status = PutData(tk, 24)) != TK_Normal)
00193                     return status;
00194                 m_stage++;
00195 
00196             }
00197 
00198         case 4: {
00199             if (Tagging (tk))
00200                 status = Tag (tk);
00201 
00202             m_stage = -1;
00203                 }   break;
00204 
00205         default:
00206             return tk.Error();
00207         }
00208 
00209         return status;
00210     }
00211 };
00212 #endif
00213 
00214 bool HW3D_Read_W3D_File(DWFInputStream * input_stream, 
00215                                         void * pModelSection, 
00216                                         HW3DCamera * ret_initial_camera,
00217                                         bool importMetaData);
00218 
00219 
00220 bool generate_object_definitions(std::map<HC_KEY, int> const & tk_map,
00221                                         HC_KEY key, 
00222                                         void * arg1,
00223                                         void * arg2
00224                                         );
00225 #define W3D_READ_BUFFER_SIZE 16*1024
00226 
00227 #endif  // _HDWFSTREAM_H
00228 
00229