void Window::saveWindowState() { // Saving X, Y and Width and Height for resizables in the config if (!mWindowName.empty() && mWindowName != "window") { config.setValue(mWindowName + "WinX", getX()); config.setValue(mWindowName + "WinY", getY()); if (mSaveVisible) config.setValue(mWindowName + "Visible", isVisible()); if (mStickyButton) config.setValue(mWindowName + "Sticky", isSticky()); if (mGrip) { if (getMinWidth() > getWidth()) setWidth(getMinWidth()); else if (getMaxWidth() < getWidth()) setWidth(getMaxWidth()); if (getMinHeight() > getHeight()) setHeight(getMinHeight()); else if (getMaxHeight() < getHeight()) setHeight(getMaxHeight()); config.setValue(mWindowName + "WinWidth", getWidth()); config.setValue(mWindowName + "WinHeight", getHeight()); } } }
void Map::determineCellTileForMap() { for (int x = 0; x < getMaxHeight(); x++) { for (int y = 0; y < getMaxWidth(); y++) { determineCellTile(getCell(x, y)); } } }
void Window::setContentSize(int width, int height) { width = width + 2 * getPadding(); height = height + getPadding() + getTitleBarHeight(); if (getMinWidth() > width) width = getMinWidth(); else if (getMaxWidth() < width) width = getMaxWidth(); if (getMinHeight() > height) height = getMinHeight(); else if (getMaxHeight() < height) height = getMaxHeight(); setSize(width, height); }
void Creature::set(const btTransform & at) { btTransform offset; offset.setIdentity(); double avg_distance = 0.0; double max_height = getMaxHeight(); for (int i = 0; i < getNumberOfBodyParts(); ++i) { avg_distance += (getBodyPart(i).getSizeX() + getBodyPart(i).getSizeY() + getBodyPart(i).getSizeZ()) / 3.0; } avg_distance *= 2; avg_distance /= getNumberOfBodyParts(); offset.setOrigin(btVector3(0.0, avg_distance, 0.0)); float circle_fraction = 2 * M_PI / getNumberOfBodyParts(); float next_fraction = 0.0; for (int i = 0; i < getNumberOfBodyParts(); ++i) { offset.setIdentity(); if (getBodyPart(i).isRoot()) { offset.setOrigin(btVector3(0, max_height, 0)); } else { offset.setOrigin(btVector3(cos(next_fraction) * avg_distance, max_height, sin(next_fraction) * avg_distance)); } getBodyPart(i).set(at * offset); next_fraction += circle_fraction; } for (int i = 0; i < getNumberOfConstraints(); ++i) { getConstraint(i).set(*this); } calculateMaxTorque(); }
void Window::setDefaultSize(int defaultX, int defaultY, int defaultWidth, int defaultHeight) { if (getMinWidth() > defaultWidth) defaultWidth = getMinWidth(); else if (getMaxWidth() < defaultWidth) defaultWidth = getMaxWidth(); if (getMinHeight() > defaultHeight) defaultHeight = getMinHeight(); else if (getMaxHeight() < defaultHeight) defaultHeight = getMaxHeight(); mDefaultX = defaultX; mDefaultY = defaultY; mDefaultWidth = defaultWidth; mDefaultHeight = defaultHeight; }
void Popup::setContentSize(int width, int height) { width += 2 * getPadding(); height += 2 * getPadding(); if (getMinWidth() > width) width = getMinWidth(); else if (getMaxWidth() < width) width = getMaxWidth(); if (getMinHeight() > height) height = getMinHeight(); else if (getMaxHeight() < height) height = getMaxHeight(); setSize(width, height); mRedraw = true; }
Box* Tile::getTileBoundingVolume(const G3MRenderContext *rc) { if (_tileBoundingVolume == NULL) { const Planet* planet = rc->getPlanet(); const double minHeight = getMinHeight() * _verticalExaggeration; const double maxHeight = getMaxHeight() * _verticalExaggeration; const Vector3D v0 = planet->toCartesian( _sector._center, maxHeight ); const Vector3D v1 = planet->toCartesian( _sector.getNE(), minHeight ); const Vector3D v2 = planet->toCartesian( _sector.getNW(), minHeight ); const Vector3D v3 = planet->toCartesian( _sector.getSE(), minHeight ); const Vector3D v4 = planet->toCartesian( _sector.getSW(), minHeight ); double lowerX = v0._x; if (v1._x < lowerX) { lowerX = v1._x; } if (v2._x < lowerX) { lowerX = v2._x; } if (v3._x < lowerX) { lowerX = v3._x; } if (v4._x < lowerX) { lowerX = v4._x; } double upperX = v0._x; if (v1._x > upperX) { upperX = v1._x; } if (v2._x > upperX) { upperX = v2._x; } if (v3._x > upperX) { upperX = v3._x; } if (v4._x > upperX) { upperX = v4._x; } double lowerY = v0._y; if (v1._y < lowerY) { lowerY = v1._y; } if (v2._y < lowerY) { lowerY = v2._y; } if (v3._y < lowerY) { lowerY = v3._y; } if (v4._y < lowerY) { lowerY = v4._y; } double upperY = v0._y; if (v1._y > upperY) { upperY = v1._y; } if (v2._y > upperY) { upperY = v2._y; } if (v3._y > upperY) { upperY = v3._y; } if (v4._y > upperY) { upperY = v4._y; } double lowerZ = v0._z; if (v1._z < lowerZ) { lowerZ = v1._z; } if (v2._z < lowerZ) { lowerZ = v2._z; } if (v3._z < lowerZ) { lowerZ = v3._z; } if (v4._z < lowerZ) { lowerZ = v4._z; } double upperZ = v0._z; if (v1._z > upperZ) { upperZ = v1._z; } if (v2._z > upperZ) { upperZ = v2._z; } if (v3._z > upperZ) { upperZ = v3._z; } if (v4._z > upperZ) { upperZ = v4._z; } _tileBoundingVolume = new Box(Vector3D(lowerX, lowerY, lowerZ), Vector3D(upperX, upperY, upperZ)); } return _tileBoundingVolume; }
void MyGLWindow::paintGL() { float r=(float)rand()/(float)RAND_MAX; float g=(float)rand()/(float)RAND_MAX; float b=(float)rand()/(float)RAND_MAX; // set the clear colour glClearColor(r,g,b,1); // clear screen glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // setup fragment shader variables glUseProgram(_program); GLint unif_resolution, unif_time, unif_tex0; unif_time = glGetUniformLocation(_program, "time"); float deltaTimeS = getDeltaTimeS(); glUniform1f(unif_time, deltaTimeS); unif_resolution = glGetUniformLocation(_program, "resolution"); glUniform2f(unif_resolution, getMaxWidth(), getMaxHeight()); unif_tex0 = glGetUniformLocation(_program, "tex0"); if (unif_tex0 != -1) { if (_texture0 != 0) { glUniform1i(unif_tex0, 0); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, _texture0); } } /* Describe our vertices array to OpenGL */ glBindBuffer(GL_ARRAY_BUFFER, _vbo_quad); glVertexAttribPointer( _attribute_coord2d, // attribute 2, // number of elements per vertex, here (x,y) GL_FLOAT, // the type of each element GL_FALSE, // take our values as-is 0, // no extra data between each position 0 // offset of first element ); glEnableVertexAttribArray(_attribute_coord2d); /* Push each element in buffer_vertices to the vertex shader */ glDrawArrays(GL_TRIANGLES, 0, 6); glDisableVertexAttribArray(_attribute_coord2d); // Swap back buffer to front swapBuffers(); }
void UISelector::updateScroll() { if(mSelectedIndex < 0) return; int scroll = mSelectedIndex - getMaxHeight() + 2; if (scroll < 0) scroll = 0; setScrollY(-scroll); }
//initializes the framebuffer void info_ennowelbers_proxyframebuffer_driver::initFB() { if(fbuffer==NULL) { //IOLog("StartFramebuffer %d %d\n",width,height); //lookahead: there is a framebuffer->thisclassuserclient->userspace path to get the screen capture //but the framebuffer memory is not a valid image (it contains more than the normal raw image data) //therefore we init a buffer to copy the image into. However, we're getting //a memory footprint of twice maxresolution*3, or at least near that scale //(i assume it's even worse, actually... just keep reading my comments) unsigned int size=getMaxWidth()*getMaxHeight()*3; buffer=IOBufferMemoryDescriptor::withCapacity(size, kIODirectionInOut); //IOLog("buffer=%d\n",buffer); //yes, i'm not using IOKit's matching system here, i simply instanciate on my own. //yes, that's NOT the way they want ist, but //now i can control easily whether the framebuffer gets instanciated or not. //and all nessecary dictionary keys are documented. fbuffer=new info_ennowelbers_proxyframebuffer_fbuffer(); OSDictionary *dict=OSDictionary::withCapacity(5); OSString *bundle=OSString::withCString("info.ennowelbers.syphon.framebuffer"); OSString *classname=OSString::withCString("info_ennowelbers_syphon_proxyframebuffer_fbuffer"); OSNumber *debug=OSNumber::withNumber(65535, 32); OSString *provider=OSString::withCString("info_ennowelbers_syphon_proxyframebuffer_driver"); OSString *userclient=OSString::withCString("IOFramebufferUserClient"); dict->setObject("CFBundleIdentifier", bundle); dict->setObject("IOClass", classname); dict->setObject("IOKitDebug", debug); dict->setObject("IOProviderClass", provider); dict->setObject("IOUserClientClass", userclient); bundle->release(); classname->release(); debug->release(); provider->release(); userclient->release(); fbuffer->init(dict); IOLog("EWProxyFrameBuffer: fbuffer retain count: %d\n",fbuffer->getRetainCount()); dict->release(); //i forgot why i did this, maybe to ensure that //iokit does not mess up with me... //however this is kernel development, trying will keep you rebooting. requestProbe(0); //attach the framebuffer to this. fbuffer->attach(this); SInt32 score; fbuffer->probe(this, &score); fbuffer->start(this); } }
bool Snake::colisionWall(){ SnakePart* head = getHead(); if( head->direction() == LEFT && head->x() - partSize < 0) return true; if(head->direction() == RIGHT && head->x() + partSize > getMaxWidth()) return true; if(head->direction() == DOWN && head->y() + 2*partSize > getMaxHeight()) return true; if(head->direction() == UP && head->y() - partSize < 0) return true; return false; }
void Window::loadWindowState() { const std::string &name = mWindowName; assert(!name.empty()); setPosition((int) config.getValue(name + "WinX", mDefaultX), (int) config.getValue(name + "WinY", mDefaultY)); if (mSaveVisible) setVisible((bool) config.getValue(name + "Visible", mDefaultVisible)); if (mStickyButton) setSticky((bool) config.getValue(name + "Sticky", isSticky())); if (mGrip) { int width = (int) config.getValue(name + "WinWidth", mDefaultWidth); int height = (int) config.getValue(name + "WinHeight", mDefaultHeight); if (getMinWidth() > width) width = getMinWidth(); else if (getMaxWidth() < width) width = getMaxWidth(); if (getMinHeight() > height) height = getMinHeight(); else if (getMaxHeight() < height) height = getMaxHeight(); setSize(width, height); } else { setSize(mDefaultWidth, mDefaultHeight); } // Check if the window is off screen... checkIfIsOffScreen(); }
void Window::setDefaultSize(int defaultWidth, int defaultHeight, ImageRect::ImagePosition position, int offsetX, int offsetY) { if (getMinWidth() > defaultWidth) defaultWidth = getMinWidth(); else if (getMaxWidth() < defaultWidth) defaultWidth = getMaxWidth(); if (getMinHeight() > defaultHeight) defaultHeight = getMinHeight(); else if (getMaxHeight() < defaultHeight) defaultHeight = getMaxHeight(); int posX = 0, posY = 0; getRelativeOffset(position, posX, posY, defaultWidth, defaultHeight, 0, 0); mDefaultWidth = defaultWidth; mDefaultHeight = defaultHeight; mDefaultPosition = position; mDefaultOffsetX = posX - offsetX; mDefaultOffsetY = posY - offsetY; }
void TransparentScrollBarH::updatePosition() { auto scrollButton = qobject_cast<TransparentScrollButtonH*>(getScrollButton()); const auto ratio = calcScrollBarRatio(); if (ratio < 0) { scrollButton->hide(); hide(); return; } if (!L::is_show_with_small_content && ratio >= 1) { scrollButton->hide(); hide(); return; } else { scrollButton->show(); show(); if (!scrollButton->isVisible()) { fadeIn(); } } const auto button_width = calcButtonWidth(); scrollButton->setFixedSize(button_width, scrollButton->height()); const auto scrollBar = getDefaultScrollBar(); const auto val = scrollBar->value(); const auto max = scrollBar->maximum(); const auto y = pos().y() + (height() - scrollButton->getMaxHeight()) / 2; if (max == 0) { scrollButton->move(pos().x(), y); return; } const auto maxX = width() - scrollButton->width(); const auto x = (maxX * val) / max + pos().x(); scrollButton->move(x, y); }
bool info_ennowelbers_proxyframebuffer_driver::start(IOService *provider) { bool res=super::start(provider); if(res) { //in order to get a framebuffer up and working, we need to correctly configure powermanagement. //we're setting up three power states: off, on and usable. PMinit(); getProvider()->joinPMtree(this); static IOPMPowerState myPowerStates[3]; myPowerStates[0].version=1; myPowerStates[0].capabilityFlags=0; myPowerStates[0].outputPowerCharacter=0; myPowerStates[0].inputPowerRequirement=0; myPowerStates[1].version=1; myPowerStates[1].capabilityFlags=0; myPowerStates[1].outputPowerCharacter=0; myPowerStates[1].inputPowerRequirement=IOPMPowerOn; myPowerStates[2].version=1; myPowerStates[2].capabilityFlags=IOPMDeviceUsable; myPowerStates[2].outputPowerCharacter=IOPMPowerOn; myPowerStates[2].inputPowerRequirement=IOPMPowerOn; registerPowerDriver(this, myPowerStates, 3); //and we're switching to power state USABLE changePowerStateTo(2); //you need to to this AFTER setting power configuration. //at least that's what i recall registerService(); IOLog("EWProxyFrameBuffer: start with maximum resolution %dx%d\n",getMaxWidth(),getMaxHeight()); if(shouldInitFB()) { IOLog("EWProxyFrameBuffer: Initializing Framebuffer. Unload from this point is impossible.\n"); initFB(); } else { IOLog("EWProxyFrameBuffer: Framebuffer initialization deactivated.\n"); } //StartFramebuffer(640, 480); } //IOLog("Starting\n"); return res; }
void UIComponent::renderChar(int x, int y, char c) { if(mParent == NULL) { WINDOW *wnd = getWindow(); if(wnd != NULL) { mvwaddch(wnd, y + getY(), x + getX(), c); } } else { if(x > getMaxWidth() || y > getMaxHeight()) { return; } mParent->renderChar(x + getX(), y + getY(), c); } }
bool VegetationPresenceDefinition::collectInstances(vector<VegetationInstance> *result, const VegetationModelDefinition &model, double xmin, double zmin, double xmax, double zmax, bool outcomers) const { if (outcomers) { // Expand the area to include outcoming instances double max_radius = getMaxHeight(); xmin -= max_radius; zmin -= max_radius; xmax += max_radius; zmax += max_radius; } int added = 0; auto generator = noise->getGenerator(); double interval_value = interval->getValue(); double xstart = xmin - fmod(xmin, interval_value); double zstart = zmin - fmod(zmin, interval_value); for (double x = xstart; x < xmax; x += interval_value) { for (double z = zstart; z < zmax; z += interval_value) { double detail = interval_value * 0.1; double noise_presence = generator->get2d(detail, x * 0.1, z * 0.1); if (noise_presence > 0.0) { double size = 0.1 + 0.2 * fabs(generator->get2d(detail, z * 10.0, x * 10.0)) * (noise_presence * 0.5 + 0.5); double angle = 3.0 * generator->get2d(detail, -x * 20.0, z * 20.0); // TODO balanced distribution double xo = x + fabs(generator->get2d(detail, x * 12.0, -z * 12.0)); double zo = z + fabs(generator->get2d(detail, -x * 27.0, -z * 27.0)); if (xo >= xmin and xo < xmax and zo >= zmin and zo < zmax) { double y = getScenery()->getTerrain()->getInterpolatedHeight(xo, zo, true, true); result->push_back(VegetationInstance(model, Vector3(xo, y, zo), size, angle)); added++; } } } } return added > 0; }
int main() { int width; char* bayer[] = {"RG","BG","GR","GB"}; char* controls[MAX_CONTROL] = {"Exposure", "Gain", "Gamma", "WB_R", "WB_B", "Brightness", "USB Traffic"}; int height; int i; char c; bool bresult; int time1,time2; int count=0; char buf[128]={0}; int CamNum=0; ///long exposure, exp_min, exp_max, exp_step, exp_flag, exp_default; //long gain, gain_min, gain_max,gain_step, gain_flag, gain_default; IplImage *pRgb; int numDevices = getNumberOfConnectedCameras(); if(numDevices <= 0) { printf("no camera connected, press any key to exit\n"); getchar(); return -1; } else printf("attached cameras:\n"); for(i = 0; i < numDevices; i++) printf("%d %s\n",i, getCameraModel(i)); printf("\nselect one to privew\n"); scanf("%d", &CamNum); bresult = openCamera(CamNum); if(!bresult) { printf("OpenCamera error,are you root?,press any key to exit\n"); getchar(); return -1; } printf("%s information\n",getCameraModel(CamNum)); int iMaxWidth, iMaxHeight; iMaxWidth = getMaxWidth(); iMaxHeight = getMaxHeight(); printf("resolution:%dX%d\n", iMaxWidth, iMaxHeight); if(isColorCam()) printf("Color Camera: bayer pattern:%s\n",bayer[getColorBayer()]); else printf("Mono camera\n"); for( i = 0; i < MAX_CONTROL; i++) { if(isAvailable((Control_TYPE)i)) printf("%s support:Yes\n", controls[i]); else printf("%s support:No\n", controls[i]); } printf("\nPlease input the <width height bin image_type> with one space, ie. 640 480 2 0. use max resolution if input is 0. Press ESC when video window is focused to quit capture\n"); int bin = 1, Image_type; scanf("%d %d %d %d", &width, &height, &bin, &Image_type); if(width == 0 || height == 0) { width = iMaxWidth; height = iMaxHeight; } initCamera(); //this must be called before camera operation. and it only need init once printf("sensor temperature:%02f\n", getSensorTemp()); // IMG_TYPE image_type; while(!setImageFormat(width, height, bin, (IMG_TYPE)Image_type))//IMG_RAW8 { printf("Set format error, please check the width and height\n ASI120's data size(width*height) must be integer multiple of 1024\n"); printf("Please input the width and height again£¬ie. 640 480\n"); scanf("%d %d %d %d", &width, &height, &bin, &Image_type); } printf("\nset image format %d %d %d %d success, start privew, press ESC to stop \n", width, height, bin, Image_type); if(Image_type == IMG_RAW16) pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_16U, 1); else if(Image_type == IMG_RGB24) pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_8U, 3); else pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_8U, 1); setValue(CONTROL_EXPOSURE, 100*1000, false); //ms//auto setValue(CONTROL_GAIN,getMin(CONTROL_GAIN), false); setValue(CONTROL_BANDWIDTHOVERLOAD, getMin(CONTROL_BANDWIDTHOVERLOAD), false); //low transfer speed setValue(CONTROL_WB_B, 90, false); setValue(CONTROL_WB_R, 48, false); setAutoPara(getMax(CONTROL_GAIN)/2,10,150); //max auto gain and exposure and target brightness // EnableDarkSubtract("dark.bmp"); //dark subtract will be disabled when exposure set auto and exposure below 500ms startCapture(); //start privew bDisplay = 1; #ifdef _LIN pthread_t thread_display; pthread_create(&thread_display, NULL, Display, (void*)pRgb); #elif defined _WINDOWS HANDLE thread_setgainexp; thread_setgainexp = (HANDLE)_beginthread(Display, NULL, (void*)pRgb); #endif time1 = GetTickCount(); int iStrLen = 0, iTextX = 40, iTextY = 60; void* retval; // int time0, iWaitMs = -1; // bool bGetImg; while(bMain) { // time0 = GetTickCount(); getImageData((unsigned char*)pRgb->imageData, pRgb->imageSize, 200); // bGetImg = getImageData((unsigned char*)pRgb->imageData, pRgb->imageSize, iWaitMs); time2 = GetTickCount(); // printf("waitMs%d, deltaMs%d, %d\n", iWaitMs, time2 - time0, bGetImg); count++; if(time2-time1 > 1000 ) { sprintf(buf, "fps:%d dropped frames:%lu ImageType:%d",count, getDroppedFrames(), (int)getImgType()); count = 0; time1=GetTickCount(); printf(buf); printf("\n"); } if(Image_type != IMG_RGB24 && Image_type != IMG_RAW16) { iStrLen = strlen(buf); CvRect rect = cvRect(iTextX, iTextY - 15, iStrLen* 11, 20); cvSetImageROI(pRgb , rect); cvSet(pRgb, CV_RGB(180, 180, 180)); cvResetImageROI(pRgb); } cvText(pRgb, buf, iTextX,iTextY ); if(bChangeFormat) { bChangeFormat = 0; bDisplay = false; pthread_join(thread_display, &retval); cvReleaseImage(&pRgb); stopCapture(); switch(change) { case change_imagetype: Image_type++; if(Image_type > 3) Image_type = 0; break; case change_bin: if(bin == 1) { bin = 2; width/=2; height/=2; } else { bin = 1; width*=2; height*=2; } break; case change_size_smaller: if(width > 320 && height > 240) { width/= 2; height/= 2; } break; case change_size_bigger: if(width*2*bin <= iMaxWidth && height*2*bin <= iMaxHeight) { width*= 2; height*= 2; } break; } setImageFormat(width, height, bin, (IMG_TYPE)Image_type); if(Image_type == IMG_RAW16) pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_16U, 1); else if(Image_type == IMG_RGB24) pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_8U, 3); else pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_8U, 1); bDisplay = 1; pthread_create(&thread_display, NULL, Display, (void*)pRgb); startCapture(); //start privew } } END: if(bDisplay) { bDisplay = 0; #ifdef _LIN pthread_join(thread_display, &retval); #elif defined _WINDOWS Sleep(50); #endif } stopCapture(); closeCamera(); cvReleaseImage(&pRgb); printf("main function over\n"); return 1; }
bool Physics3DTerrainDemo::init() { if (!Physics3DTestDemo::init()) return false; Terrain::DetailMap r("TerrainTest/dirt.jpg"),g("TerrainTest/Grass2.jpg",10),b("TerrainTest/road.jpg"),a("TerrainTest/GreenSkin.jpg",20); Terrain::TerrainData data("TerrainTest/heightmap129.jpg","TerrainTest/alphamap.png",r,g,b,a,Size(32,32), 20.0f, 1.0f); auto terrain = Terrain::create(data,Terrain::CrackFixedType::SKIRT); terrain->setMaxDetailMapAmount(4); terrain->setCameraMask(2); terrain->setDrawWire(false); terrain->setSkirtHeightRatio(3); terrain->setLODDistance(64,128,192); terrain->setCameraMask((unsigned short)CameraFlag::USER1); //create terrain Physics3DRigidBodyDes rbDes; rbDes.mass = 0.0f; std::vector<float> heidata = terrain->getHeightData(); auto size = terrain->getTerrainSize(); rbDes.shape = Physics3DShape::createHeightfield(size.width, size.height, &heidata[0], 1.0f, terrain->getMinHeight(), terrain->getMaxHeight(), true, false, true); auto rigidBody = Physics3DRigidBody::create(&rbDes); auto component = Physics3DComponent::create(rigidBody); terrain->addComponent(component); this->addChild(terrain); component->syncNodeToPhysics(); component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE); //create several spheres rbDes.mass = 1.f; rbDes.shape = Physics3DShape::createSphere(0.5f); float start_x = START_POS_X - ARRAY_SIZE_X/2 + 5.0f; float start_y = START_POS_Y + 20.0f; float start_z = START_POS_Z - ARRAY_SIZE_Z/2; for (int k=0;k<ARRAY_SIZE_Y;k++) { for (int i=0;i<ARRAY_SIZE_X;i++) { for(int j = 0;j<ARRAY_SIZE_Z;j++) { float x = 1.0*i + start_x; float y = 5.0+1.0*k + start_y; float z = 1.0*j + start_z; auto sprite = PhysicsSprite3D::create("Sprite3DTest/sphere.c3b", &rbDes); sprite->setTexture("Sprite3DTest/plane.png"); sprite->setCameraMask((unsigned short)CameraFlag::USER1); sprite->setScale(1.0f / sprite->getContentSize().width); sprite->setPosition3D(Vec3(x, y, z)); this->addChild(sprite); sprite->syncNodeToPhysics(); sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); } } } //create mesh std::vector<Vec3> trianglesList = Bundle3D::getTrianglesList("Sprite3DTest/boss.c3b"); rbDes.mass = 0.0f; rbDes.shape = Physics3DShape::createMesh(&trianglesList[0], (int)trianglesList.size() / 3); rigidBody = Physics3DRigidBody::create(&rbDes); component = Physics3DComponent::create(rigidBody); auto sprite = Sprite3D::create("Sprite3DTest/boss.c3b"); sprite->addComponent(component); sprite->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f)); sprite->setPosition3D(Vec3(0.0f, 15.0f, 0.0f)); sprite->setCameraMask(2); this->addChild(sprite); std::vector<std::pair<Physics3DShape*, Mat4> > shapeList; { Mat4 localTrans; auto bodyshape = Physics3DShape::createBox(Vec3(2.0f, 4.0f, 2.0f)); Mat4::createTranslation(0.0f, 2.0f, 0.0f, &localTrans); shapeList.push_back(std::make_pair(bodyshape, localTrans)); auto headshape = Physics3DShape::createSphere(1.5f); Mat4::createTranslation(0.6f, 5.0f, -1.5f, &localTrans); shapeList.push_back(std::make_pair(headshape, localTrans)); auto lhandshape = Physics3DShape::createBox(Vec3(1.0f, 3.0f, 1.0f)); Mat4::createRotation(Vec3(1.0f, 0.0f, 0.0f), CC_DEGREES_TO_RADIANS(15.0f), &localTrans); localTrans.m[12] = -1.5f; localTrans.m[13] = 2.5f; localTrans.m[14] = -2.5f; shapeList.push_back(std::make_pair(lhandshape, localTrans)); auto rhandshape = Physics3DShape::createBox(Vec3(1.0f, 3.0f, 1.0f)); Mat4::createRotation(Vec3(1.0f, 0.0f, 0.0f), CC_DEGREES_TO_RADIANS(-15.0f), &localTrans); localTrans.m[12] = 2.0f; localTrans.m[13] = 2.5f; localTrans.m[14] = 1.f; shapeList.push_back(std::make_pair(rhandshape, localTrans)); rbDes.mass = 10.0f; rbDes.shape = Physics3DShape::createCompoundShape(shapeList); rigidBody = Physics3DRigidBody::create(&rbDes); component = Physics3DComponent::create(rigidBody); auto sprite = Sprite3D::create("Sprite3DTest/orc.c3b"); sprite->addComponent(component); sprite->setRotation3D(Vec3(0.0f, 180.0f, 0.0f)); sprite->setPosition3D(Vec3(-5.0f, 20.0f, 0.0f)); sprite->setScale(0.4f); sprite->setCameraMask(2); this->addChild(sprite); } physicsScene->setPhysics3DDebugCamera(_camera); return true; }
bool HelloWorld::init() { if ( !Layer::init() ) { return false; } auto visibleSize = Director::getInstance()->getVisibleSize(); auto origin = Director::getInstance()->getVisibleOrigin(); camera = Camera::createPerspective(30, (float)visibleSize.width / visibleSize.height, 1.0, 1000); camera->setBackgroundBrush(CameraBackgroundBrush::createColorBrush(Color4F(0.0f, 1.0f, 1.0f, 0.5f), 1.0f)); camera->setPosition3D(Vec3(0.0f, 50.0f, 100.0f)); camera->lookAt(Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0, 1.0, 0.0)); camera->setCameraFlag(CameraFlag::USER2); this->addChild(camera); /** //Create Plane Physics3DRigidBodyDes rbd_plan; rbd_plan.mass = 0.0f; rbd_plan.shape = Physics3DShape::createBox(Vec3(500, 5.0f, 500)); auto physics_rbd_plan = Physics3DRigidBody::create(&rbd_plan); physics_rbd_plan->setFriction(20); auto component_plan = Physics3DComponent::create(physics_rbd_plan); _plan = Sprite3D::create("box.c3t"); _plan->setTexture("plane.png"); _plan->setScale(30.0f); _plan->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0)); _plan->setScaleX(500); _plan->setScaleY(5); _plan->setScaleZ(500); _plan->setPositionZ(0); _plan->setPositionY(0); _plan->setPositionX(0); _plan->setGlobalZOrder(-1); _plan->addComponent(component_plan); component_plan->syncNodeToPhysics(); component_plan->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE); _plan->setCameraMask((unsigned short)CameraFlag::USER2); this->addChild(_plan, 1); **/ Terrain::DetailMap r("dirt.jpg"); Terrain::TerrainData data("heightmap16.jpg", "alphamap.png", r, r, r, r, Size(32, 32), 5.0f, 1.0f); auto _terrain = Terrain::create(data, Terrain::CrackFixedType::SKIRT); _terrain->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0)); _terrain->setPositionZ(0); _terrain->setPositionY(0); _terrain->setPositionX(0); _terrain->setLODDistance(64, 128, 192); _terrain->setDrawWire(false); _terrain->setMaxDetailMapAmount(4); _terrain->setSkirtHeightRatio(2); _terrain->setCameraMask((unsigned short)CameraFlag::USER2); //create terrain std::vector<float> heidata = _terrain->getHeightData(); auto size = _terrain->getTerrainSize(); Physics3DColliderDes colliderDes; colliderDes.shape = Physics3DShape::createHeightfield(size.width, size.height, &heidata[0], 1.0f, _terrain->getMinHeight(), _terrain->getMaxHeight(), true, false, true); auto collider = Physics3DCollider::create(&colliderDes); auto component = Physics3DComponent::create(collider); _terrain->addComponent(component); component->syncNodeToPhysics(); component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE); this->addChild(_terrain); //////////////////////////////////////////////// car Physics3DRigidBodyDes rbd_cabine; rbd_cabine.disableSleep = true; rbd_cabine.mass = 500.0f; rbd_cabine.shape = Physics3DShape::createBox(Vec3(4, 2.0f, 8)); physics_rbd_cabine = Physics3DRigidBody::create(&rbd_cabine); auto cabine_component = Physics3DComponent::create(physics_rbd_cabine); car_cabine = Sprite3D::create("T-90.c3t"); car_cabine->setTexture("Main Body 2.png"); car_cabine->setScale(3); //car_cabine->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0)); car_cabine->setPositionX(0); car_cabine->setPositionY(10); car_cabine->setPositionZ(0); car_cabine->setGlobalZOrder(-1); car_cabine->addComponent(cabine_component); cabine_component->syncNodeToPhysics(); cabine_component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); car_cabine->setCameraMask((unsigned short)CameraFlag::USER2); this->addChild(car_cabine, 1); Physics3DRigidBodyDes rbd_wheel1; rbd_wheel1.disableSleep = true; rbd_wheel1.mass = 15.0f; //rbd_wheel1.shape = Physics3DShape::createCylinder(3, 1); rbd_wheel1.shape = Physics3DShape::createSphere(1.5); auto physics_rbd_wheel1 = Physics3DRigidBody::create(&rbd_wheel1); auto wheel1_component = Physics3DComponent::create(physics_rbd_wheel1); wheel1 = Sprite3D::create(); //wheel1->setTexture("Gun.png"); //wheel1->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0)); wheel1->setPositionX(0); wheel1->setPositionY(10); wheel1->setPositionZ(0); wheel1->setGlobalZOrder(-1); wheel1->addComponent(wheel1_component); wheel1_component->syncNodeToPhysics(); wheel1_component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); wheel1->setCameraMask((unsigned short)CameraFlag::USER2); this->addChild(wheel1, 1); Physics3DRigidBodyDes rbd_wheel2; rbd_wheel2.disableSleep = true; rbd_wheel2.mass = 15.0f; //rbd_wheel2.shape = Physics3DShape::createCylinder(3, 1); rbd_wheel2.shape = Physics3DShape::createSphere(1.5); auto physics_rbd_wheel2 = Physics3DRigidBody::create(&rbd_wheel2); auto wheel2_component = Physics3DComponent::create(physics_rbd_wheel2); wheel2 = Sprite3D::create(); //wheel2->setTexture("Gun.png"); //wheel2->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0)); wheel2->setPositionX(0); wheel2->setPositionY(10); wheel2->setPositionZ(0); wheel2->setGlobalZOrder(-1); wheel2->addComponent(wheel2_component); wheel2_component->syncNodeToPhysics(); wheel2_component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); wheel2->setCameraMask((unsigned short)CameraFlag::USER2); this->addChild(wheel2, 1); Physics3DRigidBodyDes rbd_wheel3; rbd_wheel3.disableSleep = true; rbd_wheel3.mass = 15.0f; rbd_wheel3.shape = Physics3DShape::createSphere(1.5); //rbd_wheel3.shape = Physics3DShape::createCylinder(3, 1); physics_rbd_wheel3 = Physics3DRigidBody::create(&rbd_wheel3); auto wheel3_component = Physics3DComponent::create(physics_rbd_wheel3); wheel3 = Sprite3D::create(); //wheel3->setTexture("Gun.png"); //wheel3->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0)); wheel3->setPositionX(0); wheel3->setPositionY(10); wheel3->setPositionZ(0); wheel3->setGlobalZOrder(-1); wheel3->addComponent(wheel3_component); wheel3_component->syncNodeToPhysics(); wheel3_component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); wheel3->setCameraMask((unsigned short)CameraFlag::USER2); this->addChild(wheel3, 1); Physics3DRigidBodyDes rbd_wheel4; rbd_wheel4.disableSleep = true; rbd_wheel4.mass = 15.0f; //rbd_wheel4.shape = Physics3DShape::createCylinder(3, 1); rbd_wheel4.shape = Physics3DShape::createSphere(1.5); physics_rbd_wheel4 = Physics3DRigidBody::create(&rbd_wheel4); auto wheel4_component = Physics3DComponent::create(physics_rbd_wheel4); wheel4 = Sprite3D::create(); //wheel3->setTexture("Gun.png"); //wheel4->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0)); wheel4->setPositionX(0); wheel4->setPositionY(10); wheel4->setPositionZ(0); wheel4->setGlobalZOrder(-1); wheel4->addComponent(wheel4_component); wheel4_component->syncNodeToPhysics(); wheel4_component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); wheel4->setCameraMask((unsigned short)CameraFlag::USER2); this->addChild(wheel4, 1); Physics3DRigidBodyDes rbd_wheel_bar; rbd_wheel_bar.disableSleep = true; rbd_wheel_bar.mass = 400.0f; rbd_wheel_bar.shape = Physics3DShape::createBox(Vec3(2, 2.0f, 6)); physics_rbd_wheel_bar = Physics3DRigidBody::create(&rbd_wheel_bar); auto car_wheel_bar_component = Physics3DComponent::create(physics_rbd_wheel_bar); car_wheel_bar = Sprite3D::create(); //car_wheel_bar->setTexture("Gun.png"); car_wheel_bar->setScale(0.01); car_wheel_bar->setPositionX(0); car_wheel_bar->setPositionY(10); car_wheel_bar->setPositionZ(0); //car_wheel_bar->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0)); car_wheel_bar->setGlobalZOrder(-1); car_wheel_bar->addComponent(car_wheel_bar_component); car_wheel_bar_component->syncNodeToPhysics(); car_wheel_bar_component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); car_wheel_bar->setCameraMask((unsigned short)CameraFlag::USER2); this->addChild(car_wheel_bar, 1); auto constraint = Physics3DHingeConstraint::create(physics_rbd_cabine, physics_rbd_wheel1, Vec3(0.0f, 0.0, 6.0f), Vec3(0.f, -3.0f, 0.f), Vec3(1.0f, 0.0, 0.0f), Vec3(0.f, 1.0f, 0.f)); psychics_scene->getPhysics3DWorld()->addPhysics3DConstraint(constraint); auto constraint2 = Physics3DHingeConstraint::create(physics_rbd_cabine, physics_rbd_wheel2, Vec3(0.0f, 0.0, 6.0f), Vec3(0.f, 3.0f, 0.f), Vec3(1.0f, 0.0, 0.0f), Vec3(0.f, 1.0f, 0.f)); psychics_scene->getPhysics3DWorld()->addPhysics3DConstraint(constraint2); constraint5 = Physics3DHingeConstraint::create(physics_rbd_cabine, physics_rbd_wheel_bar, Vec3(0.0f, 0.0, -6.0f), Vec3(0.f, 0.0f, 0.f), Vec3(0.0f, 1.0, 0.0f), Vec3(0.f, 1.0f, 0.f)); constraint5->setLimit(CC_DEGREES_TO_RADIANS(-0.5), CC_DEGREES_TO_RADIANS(0.5)); psychics_scene->getPhysics3DWorld()->addPhysics3DConstraint(constraint5); auto constraint3 = Physics3DHingeConstraint::create(physics_rbd_wheel_bar, physics_rbd_wheel3, Vec3(0.0f, 0.0, -3.0f), Vec3(0.f, -3.0f, 0.f), Vec3(1.0f, 0.0, 0.0f), Vec3(0.f, 1.0f, 0.f)); psychics_scene->getPhysics3DWorld()->addPhysics3DConstraint(constraint3); auto constraint4 = Physics3DHingeConstraint::create(physics_rbd_wheel_bar, physics_rbd_wheel4, Vec3(0.0f, 0.0, -3.0f), Vec3(0.f, 3.0f, 0.f), Vec3(1.0f, 0.0, 0.0f), Vec3(0.f, 1.0f, 0.f)); psychics_scene->getPhysics3DWorld()->addPhysics3DConstraint(constraint4); //add a point light auto light = PointLight::create(Vec3(0, 50, 0), Color3B(255, 255, 255), 150); addChild(light); //set the ambient light auto ambient = AmbientLight::create(Color3B(55, 55, 55)); addChild(ambient); /** Physics3DRigidBodyDes boxesrbDes; boxesrbDes.mass = 1.f; boxesrbDes.shape = Physics3DShape::createBox(Vec3(5, 5, 5)); float start_x = 10- ARRAY_SIZE_X / 2; float start_y = 0 + 5.0f; float start_z = 10 - ARRAY_SIZE_Z / 2; for (int k = 0; k<ARRAY_SIZE_Y; k++) { for (int i = 0; i<ARRAY_SIZE_X; i++) { for (int j = 0; j<ARRAY_SIZE_Z; j++) { float x = 1.0*i + start_x; float y = 5.0 + 1.0*k + start_y; float z = 1.0*j + start_z; boxesrbDes.originalTransform.setIdentity(); boxesrbDes.originalTransform.translate(x, y, z); auto sprite = PhysicsSprite3D::create("box.c3t", &boxesrbDes); sprite->setTexture("plane.png"); sprite->setCameraMask((unsigned short)CameraFlag::USER1); sprite->setScale(1.0f / sprite->getContentSize().width); this->addChild(sprite); sprite->setPosition3D(Vec3(x, y, z)); sprite->syncNodeToPhysics(); sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); } } } **/ auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesBegan = CC_CALLBACK_2(HelloWorld::onTouchesBegan, this); listener->onTouchesMoved = CC_CALLBACK_2(HelloWorld::onTouchesMoved, this); listener->onTouchesEnded = CC_CALLBACK_2(HelloWorld::onTouchesEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); //psychics_scene->setPhysics3DDebugCamera(camera); schedule(schedule_selector(HelloWorld::myupdate), .005); //this->scheduleUpdate(); return true; }
bool ZDvidDataSliceHelper::hasMaxSize(int width, int height) const { return getMaxWidth() == width && getMaxHeight() == height; }
bool TetrisEmulator::fail() { return getMaxHeight(board) > T_HEIGHT; }
void Window::loadWindowState() { const std::string &name = mWindowName; const std::string skinName = config.getValue(name + "Skin", mSkin->getFilePath()); assert(!name.empty()); if (mGrip) { int width = (int) config.getValue(name + "WinWidth", mDefaultWidth); int height = (int) config.getValue(name + "WinHeight", mDefaultHeight); if (getMinWidth() > width) width = getMinWidth(); else if (getMaxWidth() < width) width = getMaxWidth(); if (getMinHeight() > height) height = getMinHeight(); else if (getMaxHeight() < height) height = getMaxHeight(); setSize(width, height); } else { setSize(mDefaultWidth, mDefaultHeight); } int x = (int) config.getValue(name + "WinX", -1); int y = (int) config.getValue(name + "WinY", -1); if (x != -1 || y != -1) { // These two tags are deprecated. Convert them to the new system, then // remove them to avoid client coordinate confusion. config.removeValue(mWindowName + "WinX"); config.removeValue(mWindowName + "WinY"); saveRelativeLocation(x, y); } int position = (int) config.getValue(name + "Position", -1); mOffsetX = (int) config.getValue(name + "OffsetX", mDefaultOffsetX); mOffsetY = (int) config.getValue(name + "OffsetY", mDefaultOffsetY); if (position != -1) { mPosition = (ImageRect::ImagePosition) position; setLocationRelativeTo(mPosition, mOffsetX, mOffsetY); } else { setLocationRelativeTo(mDefaultPosition, mDefaultOffsetX, mDefaultOffsetY); } if (mSaveVisibility) { setVisible((bool) config.getValue(name + "Visible", mDefaultVisible)); mOldVisibility = (bool) config.getValue(name + "Hidden", false); } if (skinName.compare(mSkin->getFilePath()) != 0) { mSkin->instances--; mSkin = skinLoader->load(skinName, mDefaultSkinPath); } }
bool ZDvidDataSliceHelper::getMaxArea() const { return getMaxWidth() * getMaxHeight(); }