//=========================================== // Box2dPhysics::updatePos //=========================================== void Box2dPhysics::updatePos(const EEvent* ev) { static long entityRotationStr = internString("entityRotation"); static long entityShapeStr = internString("entityShape"); static long entityTranslationStr = internString("entityTranslation"); if (!m_init) throw PhysicsException("Instance of Box2dPhysics is not initialised", __FILE__, __LINE__); if (ev->getType() == entityTranslationStr) { const EEntityTranslation* event = static_cast<const EEntityTranslation*>(ev); b2Vec2 p = m_body->GetPosition(); // Update position float32_t x = event->newTransl_abs.x - event->oldTransl_abs.x; float32_t y = event->newTransl_abs.y - event->oldTransl_abs.y; m_body->SetTransform(b2Vec2(p.x + x / m_worldUnitsPerMetre, p.y + y / m_worldUnitsPerMetre), m_body->GetAngle()); } else if (ev->getType() == entityRotationStr) { const EEntityRotation* event = static_cast<const EEntityRotation*>(ev); float32_t a = m_body->GetAngle(); float32_t r = DEG_TO_RAD(event->newRotation_abs - event->oldRotation_abs); m_body->SetTransform(m_body->GetPosition(), a + r); } else if (ev->getType() == entityShapeStr) { const EEntityShape* event = static_cast<const EEntityShape*>(ev); unique_ptr<Shape> oldShape(dynamic_cast<Shape*>(event->oldShape.get()->clone())); unique_ptr<Shape> newShape(dynamic_cast<Shape*>(event->newShape.get()->clone())); oldShape->rotate(-event->oldRotation_abs); newShape->rotate(-event->newRotation_abs); // Update shape if (oldShape == NULL || *oldShape != *newShape) { for (unsigned int i = 0; i < m_numFixtures; ++i) m_body->DestroyFixture(m_body->GetFixtureList()); shapeToBox2dBody(*newShape, m_opts, m_body, &m_numFixtures); } } // Wake bodies /* b2Body* body = m_world.GetBodyList(); while (body != NULL) { body->SetAwake(true); body = body->GetNext(); }*/ }
void keyboard(unsigned char key , int x ,int y) { if(key == 'c') { current_point = 0; current_shape = -1; selected_point = -1; } else if (key == 'g') { generateCode(); } else if (key == 'n') { newShape(); } else if ( key == '1') { shapes_array[current_shape][2] = GL_LINES; } else if ( key == '2') { shapes_array[current_shape][2] = GL_LINE_STRIP; } else if ( key == '3') { shapes_array[current_shape][2] = GL_LINE_LOOP; } else if ( key == '4') { shapes_array[current_shape][2] = GL_POINTS; } else if ( key == '5') { shapes_array[current_shape][2] = 6 ; } glutPostRedisplay(); }
void MainWindow::addShape() { Document *doc = currentDocument(); if (doc == 0) return; Shape::Type type; if (sender() == actionAddCircle) type = Shape::Circle; else if (sender() == actionAddRectangle) type = Shape::Rectangle; else if (sender() == actionAddTriangle) type = Shape::Triangle; else return; Shape newShape(type, randomColor(), randomRect(doc->size())); doc->undoStack()->push(new AddShapeCommand(doc, newShape)); }
long shape_extractor::at(size_t i, IGeometry **ppNewGeom) { if (m_gt == esriGeometryNull) return S_FALSE; CComQIPtr<IGeometry> ipNewShape; if (m_gt == esriGeometryPoint) { HRESULT hr = newShape(m_gt, m_ipSR, m_hasZ, m_hasM, &ipNewShape); if (hr != S_OK) return showError<true>(L"create new geometry failed"), hr; CComQIPtr<IPoint> ipPoint(ipNewShape); double x, y, z, m; if (m_as_matrix) { ATLASSERT(Rf_isMatrix(m_shape)); size_t r = m_len;//INTEGER(dims)[0]; x = REAL(m_shape)[i]; y = REAL(m_shape)[i + r]; if (m_hasZ || m_hasM) { m = z = REAL(m_shape)[i + (r*2)]; if (m_hasZ && m_hasM) m = REAL(m_shape)[i + (r*3)]; } } else { x = REAL(m_parts[0])[i]; y = REAL(m_parts[1])[i]; if (m_hasZ || m_hasM) { double z, m; m = z = REAL(m_parts[2])[i]; if (m_hasZ && m_hasM) m = REAL(m_parts[3])[i]; } } ipPoint->PutCoords(x, y); if (m_hasZ) ipPoint->put_Z(z); if (m_hasM) ipPoint->put_M(m); return ipNewShape.CopyTo(ppNewGeom); } SEXP it = 0; tools::vectorGeneric geometry(m_shape); HRESULT hr = newShape(m_gt, m_ipSR, false, false, &ipNewShape); if (hr != S_OK) return showError<true>(L"create new geometry failed"), hr; it = geometry.at(i); if (Rf_isNull(it)) { ipNewShape->SetEmpty(); } else { HRESULT hr = S_FALSE; if (TYPEOF(it) == NILSXP || Rf_isNumeric(it)) hr = ipNewShape->SetEmpty(); else { std::vector<BYTE> buff; if (!tools::copy_to(it, buff)) return showError<false>(L"unknown structure"), E_FAIL; CComQIPtr<IESRIShape2> ipShape(ipNewShape); long buffSize = (long)buff.size(); hr = ipShape->ImportFromESRIShapeEx(esriShapeImportNoSwap | esriShapeImportNonTrusted, &buffSize, &buff[0]); } if (hr != S_OK) return showError<true>(L"create new geometry"), hr; } return ipNewShape.CopyTo(ppNewGeom); }