Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:18

0001 // ~/o/sysrap/tests/SGLM_test.sh
0002 
0003 #include <functional>
0004 #include "ssys.h"
0005 #include "SGLM.h"
0006 
0007 struct test_Assignment
0008 {
0009     glm::tmat4x4<double> md  ;
0010     glm::tmat4x4<float>  mf  ;
0011 
0012     test_Assignment()
0013        :
0014        md(SGLM::DemoMatrix<double>(1.)),
0015        mf(SGLM::DemoMatrix<float>(2.f))
0016     {
0017         std::cout << "SGLM::DemoMatrix<double> md " << std::endl << SGLM::Present_<double>(md) << std::endl ;
0018         std::cout << "SGLM::DemoMatrix<float>  mf"  << std::endl << SGLM::Present_<float>(mf) << std::endl ;
0019     }
0020     static int Widening()
0021     {
0022         test_Assignment t ;
0023         t.md = t.mf ;
0024         std::cout << "SGLM::DemoMatrix<double> t.md (after t.md = t.mf    widening mf values into md)  " << std::endl << SGLM::Present_<double>(t.md) << std::endl ;
0025         return 0 ;
0026     }
0027     static int Narrowing()
0028     {
0029         test_Assignment t ;
0030         t.mf = t.md ;
0031         std::cout << "SGLM::DemoMatrix<float> t.mf (after t.mf = t.md    narrowing md values into mf)  " << std::endl << SGLM::Present_<float>(t.mf) << std::endl ;
0032         return 0 ;
0033     }
0034 };
0035 
0036 
0037 struct SGLM_test
0038 {
0039     static int Dump();
0040     static int descBasis();
0041     static int descProjection();
0042     static int command();
0043     static int VIZMASK();
0044     static int UP();
0045 
0046     static int Main();
0047 };
0048 
0049 
0050 int SGLM_test::Dump()
0051 {
0052     // setenv("WH", "1024,768", true );
0053     // setenv("CE", "0,0,0,100", true) ;
0054     // setenv("EYE", "-1,-1,0", true );
0055     // NB it is too late for setenv to influence SGLM as the static initialization would have happened already :
0056     // must use static methods to change the inputs that OR export envvars in the invoking script to configure defaults
0057     // SGLM::SetWH(1024,768);
0058 
0059     SGLM sglm ;
0060     sglm.dump();
0061     return 0 ;
0062 }
0063 
0064 int SGLM_test::descBasis()
0065 {
0066     SGLM gm ;
0067     std::cout << gm.descBasis();
0068 
0069     float near_abs = 7.f ;
0070     float far_abs = 700.f ;
0071     gm.set_near_abs(near_abs);
0072     gm.set_far_abs(far_abs);
0073 
0074     std::cout << gm.descBasis();
0075 
0076     assert( gm.get_near_abs() == near_abs );
0077     assert( gm.get_far_abs() == far_abs );
0078 
0079     return 0 ;
0080 }
0081 
0082 
0083 int SGLM_test::descProjection()
0084 {
0085     SGLM gm ;
0086 
0087     float near_abs = 7.f ;
0088     float far_abs = 700.f ;
0089     gm.set_near_abs(near_abs);
0090     gm.set_far_abs(far_abs);
0091 
0092     gm.update();
0093 
0094     std::cout << gm.descProjection();
0095     std::cout << gm.desc();
0096     std::cout << gm.desc_MV_P_MVP_ce_corners() ;
0097 
0098     //assert( gm.get_near_abs() == near_abs );
0099     //assert( gm.get_far_abs() == far_abs );
0100 
0101     return 0 ;
0102 }
0103 
0104 
0105 
0106 
0107 
0108 
0109 int SGLM_test::command()
0110 {
0111     SGLM gm ;
0112     SCMD* cm = (SCMD*)&gm ;
0113 
0114     const char* cmd = "--ce 0,0,0,10 --eye 0,10,1 --look 0,1,1 --up 1,0,0 --zoom 5 --tmin 0.01 --tmax 1000" ;
0115     //const char* cmd = "--ce 0,0,0,10 --tmin 0.5 --tmax 5" ;
0116 
0117     int rc = cm->command(cmd);
0118     std::cout
0119         << " rc " << rc
0120         << std::endl
0121         ;
0122 
0123     std::cout << gm.desc() ;
0124     return 0 ;
0125 }
0126 
0127 
0128 int SGLM_test::VIZMASK()
0129 {
0130     SGLM gm ;
0131     std::cout
0132         << "gm.vizmask "
0133         << gm.vizmask
0134         << "\n"
0135         //<< SBitSet
0136         ;
0137 
0138     return 0 ;
0139 }
0140 
0141 int SGLM_test::UP()
0142 {
0143     std::cout
0144         << " SGLM::UP.x "
0145         <<   SGLM::UP.x
0146         << " SGLM::UP.y "
0147         <<   SGLM::UP.y
0148         << " SGLM::UP.z "
0149         <<   SGLM::UP.z
0150         << " SGLM::UP.w "
0151         <<   SGLM::UP.w
0152         << "\n"
0153         ;
0154 
0155     SGLM gm ;
0156 
0157     std::cout
0158         << " gm.UP.x "
0159         <<   gm.UP.x
0160         << " gm.UP.y "
0161         <<   gm.UP.y
0162         << " gm.UP.z "
0163         <<   gm.UP.z
0164         << " gm.UP.w "
0165         <<   gm.UP.w
0166         << "\n"
0167         ;
0168 
0169     return 0 ;
0170 }
0171 
0172 
0173 
0174 
0175 int SGLM_test::Main()
0176 {
0177     const char* TEST = ssys::getenvvar("TEST", "Dump") ;
0178     int rc = 0 ;
0179     if(strcmp(TEST, "Dump")==0 )           rc += Dump();
0180     if(strcmp(TEST, "descBasis")==0 )      rc += descBasis();
0181     if(strcmp(TEST, "descProjection")==0 ) rc += descProjection();
0182     if(strcmp(TEST, "command")==0 )        rc += command();
0183     if(strcmp(TEST, "VIZMASK")==0 )        rc += VIZMASK();
0184     if(strcmp(TEST, "Widening")==0 )       rc += test_Assignment::Widening();
0185     if(strcmp(TEST, "Narrowing")==0 )      rc += test_Assignment::Narrowing();
0186     if(strcmp(TEST, "UP")==0 )             rc += UP();
0187 
0188     return rc ;
0189 }
0190 
0191 int main(){ return SGLM_test::Main()  ; }
0192 
0193