Changeset 1273
 Timestamp:
 Apr 22, 2012, 3:04:03 PM (9 years ago)
 Location:
 trunk/orbital
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/orbital/mesh.h
r1271 r1273 20 20 m_vert_cursor(0), m_quadidx_cursor(0), m_triidx_cursor(0) 21 21 {} 22 23 void SendCommand(char const *command) 24 { 25 vec4 v4; 26 vec3 v3; 27 float f1, f2, f3, f4, f5; 28 29 for (char const *p = command; p && *p; ) 30 { 31 #define CASE(str) if (!strncmp(p, str, strlen(str)) \ 32 && (p[strlen(str)] < 'a'  p[strlen(str)] > 'z') \ 33 && (p += strlen(str))) 34 CASE("scb") { p = GetArg(p, v4); SetCurColor2(v4); } 35 else CASE("sc") { p = GetArg(p, v4); SetCurColor(v4); } 36 else CASE("fl") { Flush(); } 37 else CASE("tx") { p = GetArg(p, f1); Translate(vec3(f1, 0, 0)); } 38 else CASE("ty") { p = GetArg(p, f1); Translate(vec3(0, f1, 0)); } 39 else CASE("tz") { p = GetArg(p, f1); Translate(vec3(0, 0, f1)); } 40 else CASE("t") { p = GetArg(p, v3); Translate(v3); } 41 else CASE("rx") { p = GetArg(p, f1); RotateX(f1); } 42 else CASE("ry") { p = GetArg(p, f1); RotateY(f1); } 43 else CASE("rz") { p = GetArg(p, f1); RotateZ(f1); } 44 else CASE("tax") { p = GetArg(p, f1, f2, f3); TaperX(f1, f2, f3); } 45 else CASE("tay") { p = GetArg(p, f1, f2, f3); TaperY(f1, f2, f3); } 46 else CASE("taz") { p = GetArg(p, f1, f2, f3); TaperZ(f1, f2, f3); } 47 else CASE("sx") { p = GetArg(p, f1); Scale(vec3(f1, 1, 1)); } 48 else CASE("sy") { p = GetArg(p, f1); Scale(vec3(1, f1, 1)); } 49 else CASE("sz") { p = GetArg(p, f1); Scale(vec3(1, 1, f1)); } 50 else CASE("s") { p = GetArg(p, v3); Scale(v3); } 51 else CASE("mx") { MirrorX(); } 52 else CASE("my") { MirrorY(); } 53 else CASE("mz") { MirrorZ(); } 54 else CASE("ac") { /* TODO */ } 55 else CASE("ab") { p = GetArg(p, v3); AppendBox(v3); } 56 else CASE("ascb") { p = GetArg(p, v3, f1); AppendSmoothChamfBox(v3, f1); } 57 else CASE("afcb") { p = GetArg(p, v3, f1); AppendFlatChamfBox(v3, f1); } 58 else CASE("asph") { p = GetArg(p, v3, f1); AppendSphere(v3, f1); } 59 else CASE("as") { p = GetArg(p, f1, f2, f3, f4, f5); AppendStar((int)f1, f2, f4, (int)f5, (int)f5); } 60 else CASE("aes") { /* TODO */ } 61 else CASE("ad") { /* TODO */ } 62 else CASE("at") { /* TODO */ } 63 else CASE("aq") { /* TODO */ } 64 else CASE("acg") { /* TODO */ } 65 else CASE("irb") { MeshConvert(); } 66 else CASE("frb") { /* TODO */ } 67 #undef CASE 68 69 /* Skip all remaining letters */ 70 while (*p && *p >= 'a' && *p <= 'z') 71 p++; 72 /* ... and skip everything until next letter */ 73 while (*p && (*p < 'a'  *p > 'z')) 74 p++; 75 } 76 } 77 78 static char const *GetArg(char const *p, float &f) 79 { 80 float sign = 1.0f; 81 f = 0.0f; 82 /* 1) Skip commas until the first valid character, 2) read all 83 * the minus signs, 3) read all the digits, 4) skip all the dots, 84 * if any, 5) read all the remaining digits, if any. */ 85 for ( ; *p == ','; p++) 86 ; 87 for ( ; *p == ''; p++) 88 sign = sign; 89 for ( ; *p >= '0' && *p <= '9'; p++) 90 f = f * 10.f + (*p  '0'); 91 for ( ; *p == '.'; p++) 92 ; 93 for (float div = 10.f; *p >= '0' && *p <= '9'; div *= 10.f) 94 f += (*p++  '0') / div; 95 f *= sign; 96 return p; 97 } 98 99 static char const *GetArg(char const *p, float &f1, float &f2) 100 { 101 return GetArg(GetArg(p, f1), f2); 102 } 103 104 static char const *GetArg(char const *p, float &f1, float &f2, float &f3) 105 { 106 return GetArg(GetArg(p, f1, f2), f3); 107 } 108 109 static char const *GetArg(char const *p, float &f1, float &f2, 110 float &f3, float &f4) 111 { 112 return GetArg(GetArg(p, f1, f2, f3), f4); 113 } 114 115 static char const *GetArg(char const *p, float &f1, float &f2, float &f3, 116 float &f4, float &f5) 117 { 118 return GetArg(GetArg(p, f1, f2, f3, f4), f5); 119 } 120 121 static char const *GetArg(char const *p, vec3 &v) 122 { 123 return GetArg(p, v.x, v.y, v.z); 124 } 125 126 static char const *GetArg(char const *p, vec3 &v, float &f) 127 { 128 return GetArg(p, v.x, v.y, v.z, f); 129 } 130 131 static char const *GetArg(char const *p, vec4 &v) 132 { 133 return GetArg(p, v.x, v.y, v.z, v.w); 134 } 22 135 23 136 void Flush() … … 402 515 } 403 516 404 void AppendBox(vec3 const &size )405 { 406 AppendBox(size, 0.f, false);517 void AppendBox(vec3 const &size, float chamf = 0.f) 518 { 519 AppendBox(size, chamf, false); 407 520 } 408 521 
trunk/orbital/orbital.cpp
r1271 r1273 28 28 Orbital::Orbital() 29 29 { 30 m.SetCurColor(vec4(1.0, 1.0, 0.0, 1.0)); 31 m.AppendSphere(vec3(2.0, 1.6, 2.0), 24); 32 m.Translate(vec3(0.0, 1.0, 0.0)); 33 m.Flush(); 30 m.SendCommand("sc1,1,0,1,asph20,16,20,24"); 31 m.SendCommand("t0,0,30,fl"); 34 32 35 m.SetCurColor(vec4(1.0, 0.0, 1.0, 1.0)); 36 m.AppendFlatChamfBox(vec3(1.0, 1.0, 1.0), 0.1); 37 m.RotateX(45.0); 38 m.RotateZ(45.0); 39 m.Translate(vec3(0.0, 1.0, 0.0)); 40 m.Flush(); 33 m.SendCommand("sc1,0,1,1,afcb10,10,10,2,rx45,rz45"); 34 m.SendCommand("t20,20,0,fl"); 35 36 m.SendCommand("sc0,0,0.3,1,afcb30,30,30,5,ry45,rx45,afcb30,30,30,5"); 37 m.SendCommand("t40,40,0,fl"); 38 39 m.SendCommand("sc0.1,0.1,0,1,ab6,6,15,ty2,sc1,1,1,1,afcb4,5,16,0.4,tx4,mx,fl,sc0.2,0.7,0,1,afcb8,7,10,0.4,tz4"); 41 40 42 41 m_angle = 0; … … 53 52 mat4 anim = mat4::rotate(m_angle, vec3(0, 1, 0)) 54 53 * mat4::rotate(m_angle * 0.25, vec3(0, 0, 1)); 55 mat4 model = mat4::translate(vec3(0, 0, 4.5)); 54 mat4 model = mat4::translate(vec3(0, 0, 4.5)) 55 * mat4::scale(vec3(0.025)); 56 56 mat4 view = mat4::lookat(vec3(0, 2, 0), vec3(0, 0, 4), vec3(0, 1, 0)); 57 57 mat4 proj = mat4::perspective(45.0f, 640.0f, 480.0f, 0.1f, 10.0f); … … 68 68 if (!m_ready) 69 69 { 70 m. MeshConvert();70 m.SendCommand("irb"); 71 71 72 72 /* FIXME: this object never cleans up */
Note: See TracChangeset
for help on using the changeset viewer.