{"id":1900,"date":"2011-01-08T10:16:45","date_gmt":"2011-01-07T23:16:45","guid":{"rendered":"http:\/\/www.vectorstorm.org\/?p=1900"},"modified":"2011-01-08T10:18:49","modified_gmt":"2011-01-07T23:18:49","slug":"code-simplification","status":"publish","type":"post","link":"https:\/\/www.vectorstorm.com.au\/2011\/01\/08\/code-simplification\/","title":{"rendered":"Code simplification"},"content":{"rendered":"

Old:
\n<\/p>\n

\r\n\tfloat hw = width * 0.5f;\r\n\tfloat hh = height * 0.5f;\r\n\t\/\/ draw dark background\r\n\tvsDisplayList *list = new vsDisplayList(512);\r\n\tvsVector3D va[4] = \r\n\t{\r\n\t\tvsVector2D(-hw,-hh),\r\n\t\tvsVector2D(hw,-hh),\r\n\t\tvsVector2D(-hw,hh),\r\n\t\tvsVector2D(hw,hh)\r\n\t};\r\n\tint ts[4] =\r\n\t{\r\n\t\t0,1,2,3\r\n\t};\r\n\tint ls[5] =\r\n\t{\r\n\t\t0,1,3,2,0\r\n\t};\r\n\tlist->SetColor(vsColor(0.0f,0.0f,0.0f,0.9f));\r\n\tlist->VertexArray(va,4);\r\n\tlist->TriangleStrip(ts,4);\r\n\tlist->SetColor( vsColor::White );\r\n\tlist->LineStrip(ls,5);\r\n\tlist->ClearVertexArray();\r\n\tvsFragment *fragment = new vsFragment;\r\n\tfragment->SetDisplayList(list);\r\n\tfragment->SetMaterial( \"White\" );\r\n\tAddFragment( fragment );\r\n<\/pre>\n

<\/tt>
\nNew:
\n<\/p>\n

\r\n\tvsBox2D box( width, height );\r\n\tbox.Recenter();\r\n\tAddFragment( vsMakeSolidBox2D( box, \"TestimonyButton\" ) );\r\n\tAddFragment( vsMakeOutlineBox2D( box, \"White\" ) );\r\n<\/pre>\n

<\/tt><\/p>\n

This is much nicer, innit? :)<\/p>\n

Certainly it’s a lot shorter. Both create an identical box with an identical white outline. This is just using the new “vsMakeSolidBox2D()” set of functions which were recently added to VS_Primitive.h. I really ought to have more utility functions like these; they make it an awful lot faster to quickly prototype things!<\/p>\n","protected":false},"excerpt":{"rendered":"

Old: float hw = width * 0.5f; float hh = height * 0.5f; \/\/ draw dark background vsDisplayList *list = new vsDisplayList(512); vsVector3D va[4] = { vsVector2D(-hw,-hh), vsVector2D(hw,-hh), vsVector2D(-hw,hh), vsVector2D(hw,hh) }; int ts[4] = { 0,1,2,3 }; int ls[5] = { 0,1,3,2,0 }; list->SetColor(vsColor(0.0f,0.0f,0.0f,0.9f)); list->VertexArray(va,4); list->TriangleStrip(ts,4); list->SetColor( vsColor::White ); list->LineStrip(ls,5); list->ClearVertexArray(); vsFragment *fragment = new…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[33,3],"tags":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/po9WK-uE","_links":{"self":[{"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/posts\/1900"}],"collection":[{"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/comments?post=1900"}],"version-history":[{"count":0,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/posts\/1900\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/media?parent=1900"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/categories?post=1900"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/tags?post=1900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}