Changeset 2152 for trunk/tutorial/05_easymesh.cpp
 Timestamp:
 Dec 19, 2012, 9:49:58 PM (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/tutorial/05_easymesh.cpp
r2151 r2152 21 21 { 22 22 public: 23 void AddPiece(int x, int y, int h, int dx, int dy, int dh)24 {25 m_mesh.OpenBrace();26 for (int j = 0; j < y; ++j)27 for (int i = 0; i < x; ++i)28 {29 m_mesh.OpenBrace();30 m_mesh.Compile("ad12,2.2,0 ty.1 ac12,.2,2.4,2.2,0,1 ty.8 ac12,1.7,2.4,2.4,0,1 ty2.5");31 m_mesh.Translate(vec3(i * 8.f, (h  1) * 3.2f, j * 8.f));32 m_mesh.CloseBrace();33 }34 m_mesh.OpenBrace();35 m_mesh.AppendFlatChamfBox(vec3(x * 8.f, h * 3.2f, y * 8.f), .1f);36 m_mesh.Translate(vec3((x  1) * 4.f, (h  1) * 1.6f, (y  1) * 4.f));37 m_mesh.CloseBrace();38 m_mesh.Translate(vec3(dx * 8.f, dh * 3.2f, dy * 8.f));39 40 m_mesh.CloseBrace();41 }42 43 23 EasyMeshTutorial() 44 24 { 25 m_gears.Push(EasyMesh(), mat4(1.0f), 0.0f); 26 m_gears.Push(EasyMesh(), mat4(1.0f), 0.0f); 27 m_gears.Push(EasyMesh(), mat4(1.0f), 180.0f / 18); 28 m_gears.Push(EasyMesh(), mat4(1.0f), 180.0f / 18); 29 m_gears.Push(EasyMesh(), mat4(1.0f), 180.0f / 18); 30 31 m_gears[0].m1.Compile("sc#f9f scb#f9f acg 12 10 5 5 20 20 5 5 0.1 0"); 32 m_gears[1].m1.Compile("sc#ff9 scb#ff9 acg 54 10 95 95 90 90 5 5 0.1 0"); 33 m_gears[2].m1.Compile("sc#9ff scb#9ff acg 18 10 5 5 30 30 5 5 0.1 0"); 34 m_gears[3].m1.Compile("sc#9ff scb#9ff acg 18 10 5 5 30 30 5 5 0.1 0"); 35 m_gears[4].m1.Compile("sc#9ff scb#9ff acg 18 10 5 5 30 30 5 5 0.1 0"); 36 45 37 m_angle = 0; 46 47 //m_mesh.Compile("sc#ffb scb#ffb acg 12 10 30 30 5 5 0.1 0");48 m_mesh.Compile("sc#ffb scb#ffb acg 12 10 30 30 5 5 0.1 0");49 50 #if 051 m_mesh.Compile("sc#8d3 [ato40 10 40 rx20 ry130 tx30]");52 53 m_mesh.OpenBrace();54 m_mesh.Compile("sc#800 [asph10 25 25 25]");55 m_mesh.Compile("ty50");56 m_mesh.RadialJitter(0.2f);57 m_mesh.Compile("ty50 tx40");58 m_mesh.CloseBrace();59 #endif60 61 #if 062 //m_mesh.Compile("sc#94e scb#649 [asph3 7 7 7 tx6 tz9]");63 //m_mesh.Compile("sc#49e scb#469 [asph31 7 7 7 tx6 tz9]");64 m_mesh.Compile("sc#1c1 scb#1c1");65 AddPiece(16, 16, 1, 8, 8, 4);66 67 /* Flat white LOL */68 m_mesh.Compile("sc#ccc scb#ccc");69 70 AddPiece(1, 4, 1, 7, 7, 3);71 AddPiece(2, 1, 1, 6, 4, 3);72 73 AddPiece(1, 4, 1, 3, 7, 3);74 AddPiece(2, 1, 1, 2, 7, 3);75 AddPiece(2, 1, 1, 2, 4, 3);76 AddPiece(1, 2, 1, 1, 6, 3);77 78 AddPiece(1, 4, 1, 1, 7, 3);79 AddPiece(2, 1, 1, 2, 4, 3);80 81 /* High red LOL */82 m_mesh.Compile("sc#e33 scb#e33");83 84 AddPiece(3, 1, 3, 3, 4, 3);85 AddPiece(1, 1, 3, 5, 4, 0);86 AddPiece(1, 1, 3, 5, 4, 3);87 AddPiece(1, 1, 3, 5, 4, 6);88 89 AddPiece(3, 1, 3, 1, 4, 3);90 AddPiece(1, 1, 3, 1, 4, 0);91 AddPiece(1, 1, 3, 1, 4, 3);92 AddPiece(1, 1, 3, 1, 4, 0);93 AddPiece(1, 1, 3, 1, 4, 3);94 AddPiece(3, 1, 3, 1, 4, 6);95 96 AddPiece(3, 1, 3, 5, 4, 3);97 AddPiece(1, 1, 3, 3, 4, 0);98 AddPiece(1, 1, 3, 3, 4, 3);99 AddPiece(1, 1, 3, 3, 4, 6);100 101 /* Some random crap */102 m_mesh.Compile("sc#e0e scb#e0e");103 AddPiece(1, 1, 1, 1, 0, 2);104 m_mesh.Compile("sc#0ee scb#0ee");105 AddPiece(2, 1, 1, 1, 0, 1);106 m_mesh.Compile("sc#e94 scb#e94");107 AddPiece(1, 1, 1, 0, 0, 0);108 m_mesh.Compile("sc#94e scb#94e");109 AddPiece(2, 1, 1, 0, 0, 1);110 m_mesh.Compile("sc#9e4 scb#9e4");111 AddPiece(1, 2, 3, 1, 1, 2);112 m_mesh.Compile("sc#49e scb#49e");113 AddPiece(2, 3, 1, 0, 1, 2);114 m_mesh.Compile("sc#4e9 scb#4e9");115 AddPiece(6, 2, 1, 2, 0, 3);116 m_mesh.Compile("sc#e49 scb#e49");117 AddPiece(6, 2, 1, 2, 2, 3);118 #endif119 120 /* Center everything  is it needed? */121 // m_mesh.Compile("tx4 tz4");122 38 123 39 m_camera = new Camera(vec3(0.f, 600.f, 0.f), … … 126 42 m_camera>SetPerspective(70.f, 960.f, 600.f, .1f, 1000.f); 127 43 m_camera>SetTarget(vec3(0.f, 10.f, 0.f)); 128 m_camera>SetPosition(vec3(1 00.f, 60.f, 0.f));44 m_camera>SetPosition(vec3(150.f, 100.f, 0.f)); 129 45 Ticker::Ref(m_camera); 130 46 131 47 m_ready = false; 48 } 49 50 ~EasyMeshTutorial() 51 { 52 Ticker::Unref(m_camera); 132 53 } 133 54 … … 136 57 WorldEntity::TickGame(seconds); 137 58 138 m_angle += seconds * 80.0f; 59 m_angle += seconds * 70.0f; 60 m_mat = mat4::rotate(10.0f, vec3(0, 0, 1)) 61 * mat4::rotate(m_angle, vec3(0, 1, 0)); 139 62 140 mat4 anim = mat4::rotate(m_angle, vec3(0, 1, 0)); 141 mat4 model = mat4::translate(vec3(0, 0, 0)); 63 m_gears[0].m3 += seconds * 150.0f; 64 m_gears[1].m3 += seconds * 150.0f * 2 / 9; 65 m_gears[2].m3 += seconds * 150.0f * 2 / 3; 66 m_gears[3].m3 += seconds * 150.0f * 2 / 3; 67 m_gears[4].m3 += seconds * 150.0f * 2 / 3; 142 68 143 m_matrix = model * anim; 69 m_gears[0].m2 = mat4::translate(vec3(0, 0, 0)) 70 * mat4::rotate(m_gears[0].m3, vec3(0, 1, 0)); 71 m_gears[1].m2 = mat4::translate(vec3(0, 0, 0)) 72 * mat4::rotate(m_gears[1].m3, vec3(0, 1, 0)); 73 m_gears[2].m2 = mat4::translate(vec3(0, 0, 55)) 74 * mat4::rotate(m_gears[2].m3, vec3(0, 1, 0)); 75 m_gears[3].m2 = mat4::translate(vec3(55 * lol::sqrt(3.f) * 0.5f, 0, 55 * 0.5f)) 76 * mat4::rotate(m_gears[3].m3, vec3(0, 1, 0)); 77 m_gears[4].m2 = mat4::translate(vec3(55 * lol::sqrt(3.f) * 0.5f, 0, 55 * 0.5f)) 78 * mat4::rotate(m_gears[4].m3, vec3(0, 1, 0)); 144 79 } 145 80 … … 150 85 if (!m_ready) 151 86 { 152 m_mesh.MeshConvert(); 87 for (int i = 0; i < m_gears.Count(); i++) 88 m_gears[i].m1.MeshConvert(); 153 89 m_ready = true; 154 90 } … … 156 92 Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f)); 157 93 158 m_mesh.Render(m_matrix); 159 m_mesh.Render(mat4::translate(vec3(65, 0, 65) * lol::sqrt(0.5)) * mat4::rotate(m_angle, vec3(0, 1, 0))); 160 m_mesh.Render(mat4::translate(vec3(0, 0, 65)) * mat4::rotate(m_angle, vec3(0, 1, 0))); 161 m_mesh.Render(mat4::translate(vec3(65, 0, 65)) * mat4::rotate(m_angle, vec3(0, 1, 0))); 94 for (int i = 0; i < m_gears.Count(); i++) 95 m_gears[i].m1.Render(m_mat * m_gears[i].m2); 162 96 } 163 97 164 98 private: 99 Array<EasyMesh, mat4, float> m_gears; 165 100 float m_angle; 166 mat4 m_matrix; 167 EasyMesh m_mesh; 101 mat4 m_mat; 168 102 Camera *m_camera; 169 103
Note: See TracChangeset
for help on using the changeset viewer.