static void push_index(ClmExpNode *node) { char index_str[64]; ClmSymbol *var = clm_scope_find(data.scope, node->indExp.id); switch (var->type) { case CLM_TYPE_INT: load_var_location(var, index_str, 4, NULL); asm_push(index_str); asm_push_const_i((int)var->type); break; case CLM_TYPE_FLOAT: load_var_location(var, index_str, 4, NULL); asm_push_f(index_str); asm_push_const_i((int)var->type); break; case CLM_TYPE_MATRIX: push_matrix(node); break; case CLM_TYPE_STRING: // uhh break; default: // shouldn't get here... break; } }
bool GLView::scr2world_z0(Vector2<double>& pos, Vector2<int> const& scr) const { push_matrix(); initialize_matrix(); set_perspective_matrix(); double model[16], proj[16]; int view[4]; glGetDoublev(GL_MODELVIEW_MATRIX, model); glGetDoublev(GL_PROJECTION_MATRIX, proj); glGetIntegerv(GL_VIEWPORT, view); Vector3<double> v; // マウス座標に対応するカメラのznear面上のワールド座標 gluUnProject(GLdouble(scr.x), GLdouble(scr.y), 0.0, model, proj, view, &v.x, &v.y, &v.z); // 透視射影の場合(正射影の場合は単純に(v.x, v.y)) if ((0.0<v.z && v.z<eye_.z) || (eye_.z<v.z && v.z<0.0)) { // 視線の先がz=0平面に交わる場合 double const denom = eye_.z-v.z; pos.set((eye_.z*v.x-v.z*eye_.x)/denom, (eye_.z*v.y-v.z*eye_.y)/denom); pop_matrix(); return true; } else { // 交わらない場合 pos.set(v.x-eye_.x, v.y-eye_.y); pop_matrix(); return false; } }
void draw_clock(int x, int y, int w, int h, GR_WINDOW_ID pmap, GR_GC_ID gc, GR_WINDOW_ID window) { int i; GrSetGCForeground(gc, GrGetSysColor(GR_COLOR_WINDOW)); GrFillRect(pmap, gc, 0, 0, w, h); tick(); push_matrix(); translate(x + w / 2.0 - .5, y + h / 2.0 - .5); scale_xy((w - 1) / 28.0, (h - 1) / 28.0); if (type() == ROUND_CLOCK) { GrSetGCForeground(gc, BLACK); begin_polygon(); circle(0, 0, 14, pmap, gc, w, h); end_polygon(pmap, gc); GrSetGCForeground(gc, BLACK); begin_loop(); circle(0, 0, 14, pmap, gc, w, h); end_loop(pmap, gc); } //draw the shadows push_matrix(); translate(0.60, 0.60); draw_clock_hands(LTGRAY, LTGRAY, pmap, gc); pop_matrix(); //draw the tick marks push_matrix(); GrSetGCForeground(gc, BLACK); for (i = 0; i < 12; i++) { if (6 == i) rect(-0.5, 9, 1, 2, pmap, gc); else if (3 == i || 0 == i || 9 == i) rect(-0.5, 9.5, 1, 1, pmap, gc); else rect(-0.25, 9.5, .5, 1, pmap, gc); rotate(-30); } pop_matrix(); //draw the hands draw_clock_hands(GRAY, BLACK, pmap, gc); pop_matrix(); GrCopyArea(window, gc, 0, 0, w, h, pmap, 0, 0, MWROP_SRCCOPY); }
static void drawhand(double ang, const float v[][2], GR_COLOR fill, GR_COLOR line, GR_WINDOW_ID pmap, GR_GC_ID gc) { int i; push_matrix(); rotate(ang); GrSetGCForeground(gc, fill); begin_polygon(); for (i = 0; i < 4; i++) vertex(v[i][0], v[i][1]); end_polygon(pmap, gc); GrSetGCForeground(gc, line); begin_loop(); for (i = 0; i < 4; i++) vertex(v[i][0], v[i][1]); end_loop(pmap, gc); pop_matrix(); }
std::vector<unsigned char> CEntityWriter::SaveEntity(CSerializationEntity& pRoot) { std::vector<unsigned char> data; // save mesh information. long magic = 0; // static mesh is being saved. if (pRoot.m_Bones.size() > 0 ) { magic = 1; // animated mesh is being saved. } push_long(data, magic); push_matrix(data, pRoot.m_Pos); assert(pRoot.m_EntityName.size()> 0); const char * cStr = pRoot.m_EntityName.c_str(); push_string(data, pRoot.m_EntityName); push_float(data, pRoot.globalScale); // save mesh information std::vector<CRenderable_Export > v = pRoot.m_ExportShapes; long num_renderables = v.size(); push_long(data, num_renderables); for (int i= 0 ; i < num_renderables ; i ++ ) { const CRenderable_Export& pRenderable = v[i]; push_long(data, pRenderable.m_UsedBones.size() ); append(pRenderable.m_UsedBones, data); push_long(data, pRenderable.m_Geometries.size() ); for (int geomIndex = 0; geomIndex < pRenderable.m_Geometries.size() ; geomIndex ++ ) { const CRenderable_AbstractGeometry& pGeometry = pRenderable.m_Geometries[geomIndex]; push_long(data, pGeometry.m_VertexBuffers.size()); for (unsigned int j = 0 ; j < pGeometry.m_VertexBuffers.size() ; j ++ ) { std::vector<unsigned char> vertexes; const CRenderable_AbstractVertexBuffer& pBuffer = pGeometry.m_VertexBuffers[j]; vertexes = SaveVertexes(pBuffer); long size = vertexes.size(); push_long(data, size); append(vertexes, data); } push_long(data, pGeometry.m_IndexBuffers.size()); for (unsigned int j = 0 ; j < pGeometry.m_IndexBuffers.size() ; j ++ ) { std::vector<unsigned char> indexes; const CRenderable_AbstractIndexBuffer& pIndex = pGeometry.m_IndexBuffers[j]; indexes = SaveIndexes(pIndex); long size = indexes.size(); push_long(data, size); append(indexes, data); } push_long(data, pGeometry.m_RenderCalls.size()); for (unsigned int j = 0 ; j < pGeometry.m_RenderCalls.size() ; j ++ ) { std::vector<unsigned char> calls; const CRenderable_AbstractRenderCall& pCall = pGeometry.m_RenderCalls[j]; calls = SaveRenderCalls(pCall); long size = calls.size(); push_long(data, size); append(calls, data); } } push_long(data, pRenderable.m_ExportMaterial.m_Name.size()); for (unsigned int i = 0 ; i < pRenderable.m_ExportMaterial.m_Name.size() ; i ++ ) { data.push_back(pRenderable.m_ExportMaterial.m_Name[i]); } } // save static bone information push_long(data, pRoot.m_Bones.size()); std::vector<CBoneSerialized>& bonez = pRoot.m_Bones; std::vector<CBoneSerialized>::iterator it = bonez.begin(); while (it != pRoot.m_Bones.end()) { /* CBoneSerialized* m_pParent; std::list<CBoneSerialized*> m_ChildrenPtr; CMatrix m_InitialMatrix; CMatrix m_InvBoneSkinMatrix; CMatrix m_FinalMatrix; CVector m_Pos; long m_Index; std::string m_ID; std::list<CMatrix> m_AnimationMatrices; */ long parentIndex = -1; if ((*it).m_pParent >= 0) { parentIndex = bonez[(*it).m_pParent].m_Index; } push_long(data, parentIndex); std::vector<unsigned char> matrixVector; matrixVector.resize(sizeof(CMatrix)); memcpy(&matrixVector[0] , &(*it).m_InitialMatrix, sizeof(CMatrix)); data.insert(data.end() , matrixVector.begin(), matrixVector.end()); memcpy(&matrixVector[0] ,&(*it).m_InvBoneSkinMatrix, sizeof(CMatrix)); data.insert(data.end() , matrixVector.begin(), matrixVector.end()); push_long(data,(*it).m_Index); push_long(data,(*it).m_ID.size()); assert( (*it).m_ID.size() < 100 ) ; CBoneSerialized& pBone = (*it); data.insert(data.end(), pBone.m_ID.begin(), pBone.m_ID.end()); //data.insert(data.end() ,(*it)->m_ID.begin() , (*it)->m_ID.end()); /*push_long(data, (*it)->m_MatrixMapping.size() ); for (int i = 0 ; i < (*it)->m_MatrixMapping.size() ; i ++ ) { data.push_back( (*it)->m_MatrixMapping[i].first ); data.push_back( (*it)->m_MatrixMapping[i].second ); }*/ //PrintBone(*it); it++; } return data; }