void CubeMesh::innerSetCoords( const vector< double >& v) { if ( v.size() < 6 ) return; x0_ = v[0]; y0_ = v[1]; z0_ = v[2]; x1_ = v[3]; y1_ = v[4]; z1_ = v[5]; bool temp = preserveNumEntries_; if ( v.size() >= 9 ) { dx_ = v[6]; dy_ = v[7]; dz_ = v[8]; preserveNumEntries_ = 0; } else { preserveNumEntries_ = 1; } updateCoords(); preserveNumEntries_ = temp; }
//=========================================================================== void CellDivision::updateCoords(int curr_dim, vector<int>& curr_coord) //=========================================================================== { ++curr_coord[curr_dim]; if (curr_coord[curr_dim] == ncells_[curr_dim]) { if (curr_dim == dim_ - 1) return; curr_coord[curr_dim] = 0; updateCoords(curr_dim + 1, curr_coord); } else { coords_.push_back(curr_coord); updateCoords(0, curr_coord); } return; }
void GSurface::regeneratePath(int ns, int nt){ updateCoords(); calculateCoefficients(); double delta_s = 1.0 / (ns - 1); double delta_t = 1.0 / (nt - 1); createDeltaMatrices(delta_s, delta_t); createForwardDiffMatrices(); _curves.clear(); for (int i = 0; i < ns; i++) { makeCurve(nt, _DDx[0][0], _DDx[0][1], _DDx[0][2], _DDx[0][3], _DDy[0][0], _DDy[0][1], _DDy[0][2], _DDy[0][3], _DDz[0][0], _DDz[0][1], _DDz[0][2], _DDz[0][3] ); UpdateForwardDiffMatrices(); } createForwardDiffMatrices(); _DDx = Transformation(_DDx).transpose().m(); _DDy = Transformation(_DDy).transpose().m(); _DDz = Transformation(_DDz).transpose().m(); for (int i = 0; i < nt; i++) { makeCurve(ns, _DDx[0][0], _DDx[0][1], _DDx[0][2], _DDx[0][3], _DDy[0][0], _DDy[0][1], _DDy[0][2], _DDy[0][3], _DDz[0][0], _DDz[0][1], _DDz[0][2], _DDz[0][3] ); UpdateForwardDiffMatrices(); } }
void CylMesh::setDiffLength( const Eref& e, double v ) { vector< double > childConcs; getChildConcs( e, childConcs ); diffLength_ = v; updateCoords( e, childConcs ); }
void GroupTextureController::notifyChangeDataSelector(DataPtr _data, bool _changeOnlySelection) { mParentData = _data; if (mParentData != nullptr && mParentData->getType()->getName() != mParentTypeName) mParentData = nullptr; std::string texture; PropertyPtr property = PropertyUtility::getPropertyByName("Group", "Texture"); if (property != nullptr) { texture = property->getValue(); if (!property->eventChangeProperty.exist(this, &GroupTextureController::notifyChangeProperty)) property->eventChangeProperty.connect(this, &GroupTextureController::notifyChangeProperty); } std::string coord; property = PropertyUtility::getPropertyByName("Group", "Size"); if (property != nullptr) { coord = property->getValue(); if (!property->eventChangeProperty.exist(this, &GroupTextureController::notifyChangeProperty)) property->eventChangeProperty.connect(this, &GroupTextureController::notifyChangeProperty); } mControl->setTextureValue(texture); updateCoords(coord); }
void CylMesh::setR1( const Eref& e, double v ) { vector< double > childConcs; getChildConcs( e, childConcs ); r1_ = v; updateCoords( e, childConcs ); }
void Being::setPosition(const Vector &pos) { Actor::setPosition(pos); updateCoords(); if (mText) mText->adviseXY(getPixelX(), getSpeechTextYPosition()); }
void OrientThread::run() { //qDebug() << "OrientThread::run"; QTimer timer; connect(&timer, SIGNAL(timeout()), this, SLOT(updateCoords())); timer.start(50); exec(); }
//=========================================================================== void CellDivision::makeCoords() //=========================================================================== { coords_.clear(); vector<int> curr_coord(dim_, 0); coords_.push_back(curr_coord); int curr_dim = 0; // Using recursion to fill up the "index coordinates" updateCoords(curr_dim, curr_coord); return; }
SkyPoint SkyObject::recomputeCoords( const KStarsDateTime &dt, const GeoLocation *geo ) { //store current position SkyPoint original( ra(), dec() ); // compute coords for new time jd KSNumbers num( dt.djd() ); if ( isSolarSystem() && geo ) { dms LST = geo->GSTtoLST( dt.gst() ); updateCoords( &num, true, geo->lat(), &LST ); } else { updateCoords( &num ); } //the coordinates for the date dt: SkyPoint sp = SkyPoint( ra(), dec() ); // restore original coords setRA( original.ra()->Hours() ); setDec( original.dec()->Degrees() ); return sp; }
void GroupTextureController::notifyChangeProperty(PropertyPtr _sender) { if (!mActivated || !PropertyUtility::isDataSelected(_sender->getOwner())) return; if (_sender->getOwner()->getType()->getName() == "Group") { if (_sender->getType()->getName() == "Texture") mControl->setTextureValue(_sender->getValue()); else if (_sender->getType()->getName() == "Size") updateCoords(_sender->getValue()); } }
void Being::setPosition(const Vector &pos) { mPos = pos; // Update pixel coordinates (convert once, for performance reasons) mPx = (int) pos.x; mPy = (int) pos.y; updateCoords(); if (mText) mText->adviseXY(mPx, mPy - getHeight() - mText->getHeight() - 6); }
void QgsGeorefDataPoint::moveTo( const QPoint &p, bool isMapPlugin ) { if ( isMapPlugin ) { QgsPoint pnt = mGCPSourceItem->toMapCoordinates( p ); mPixelCoords = pnt; } else { QgsPoint pnt = mGCPDestinationItem->toMapCoordinates( p ); mMapCoords = pnt; } mGCPSourceItem->update(); mGCPDestinationItem->update(); updateCoords(); }
void Being::showName() { delete mDispName; mDispName = 0; std::string mDisplayName(mName); Being* player = static_cast<Being*>(this); if (player) { if (config.getBoolValue("showgender")) { if (getGender() == GENDER_FEMALE) mDisplayName += " \u2640"; else if (getGender() == GENDER_MALE) mDisplayName += " \u2642"; } // Display the IP when under tmw-Athena (GM only). if (Net::getNetworkType() == ServerInfo::TMWATHENA && local_player && local_player->getShowIp() && player->getIp()) { mDisplayName += strprintf(" %s", ipToString(player->getIp())); } } if (getType() == MONSTER) { if (config.getBoolValue("showMonstersTakedDamage")) { mDisplayName += ", " + toString(getDamageTaken()); } } gcn::Font *font = 0; if (local_player && local_player->getTarget() == this && getType() != MONSTER) { font = boldFont; } mDispName = new FlashText(mDisplayName, getPixelX(), getPixelY(), gcn::Graphics::CENTER, mNameColor, font); updateCoords(); }
void CylMesh::innerSetCoords( const Eref& e, const vector< double >& v ) { vector< double > childConcs; getChildConcs( e, childConcs ); x0_ = v[0]; y0_ = v[1]; z0_ = v[2]; x1_ = v[3]; y1_ = v[4]; z1_ = v[5]; r0_ = v[6]; r1_ = v[7]; diffLength_ = v[8]; updateCoords( e, childConcs ); }
void IndexTextureController::notifyChangeDataSelector(DataPtr _data, bool _changeOnlySelection) { mParentData = _data; if (mParentData != nullptr && mParentData->getType()->getName() != mParentTypeName) mParentData = nullptr; std::string texture; PropertyPtr property = PropertyUtility::getPropertyByName("Group", "Texture"); if (property != nullptr) { texture = property->getValue(); if (!property->eventChangeProperty.exist(this, &IndexTextureController::notifyChangeProperty)) property->eventChangeProperty.connect(this, &IndexTextureController::notifyChangeProperty); } std::string coord; property = PropertyUtility::getPropertyByName("Group", "Size"); if (property != nullptr) { coord = property->getValue(); if (!property->eventChangeProperty.exist(this, &IndexTextureController::notifyChangeProperty)) property->eventChangeProperty.connect(this, &IndexTextureController::notifyChangeProperty); } if (mParentData != nullptr) { for (Data::VectorData::const_iterator child = mParentData->getChilds().begin(); child != mParentData->getChilds().end(); child ++) { property = (*child)->getProperty("Point"); if (!property->eventChangeProperty.exist(this, &IndexTextureController::notifyChangeProperty)) property->eventChangeProperty.connect(this, &IndexTextureController::notifyChangeProperty); } } mControl->setTextureValue(texture); updateCoords(coord); }
////////////////////////////////////////////////////////////////// // Class stuff. ////////////////////////////////////////////////////////////////// CubeMesh::CubeMesh() : isToroid_( 0 ), preserveNumEntries_( 1 ), alwaysDiffuse_( false ), x0_( 0.0 ), y0_( 0.0 ), z0_( 0.0 ), x1_( 1.0 ), y1_( 1.0 ), z1_( 1.0 ), dx_( 1.0 ), dy_( 1.0 ), dz_( 1.0 ), nx_( 1 ), ny_( 1 ), nz_( 1 ), m2s_( 1, 0 ), s2m_( 1, 0 ) { updateCoords(); }
void StarObject::JITupdate() { static KStarsData *data = KStarsData::Instance(); if ( updateNumID != data->updateNumID() ) { // TODO: This can be optimized and reorganized further in a better manner. // Maybe we should do this only for stars, since this is really a slow step only for stars Q_ASSERT( std::isfinite( lastPrecessJD ) ); if( ( lastPrecessJD - data->updateNum()->getJD() ) >= 0.0005 // TODO: Make this 0.0005 a constant / define it || ( lastPrecessJD - data->updateNum()->getJD() ) <= -0.0005 || Options::alwaysRecomputeCoordinates() || ( Options::useRelativistic() && checkBendLight() ) ) { // Short circuit right here, if recomputing coordinates is not required. NOTE: POTENTIALLY DANGEROUS updateCoords( data->updateNum() ); } updateNumID = data->updateNumID(); } EquatorialToHorizontal( data->lst(), data->geo()->lat() ); updateID = data->updateID(); }
void CubeMesh::setZ1( double v ) { z1_ = v; updateCoords(); }
int CScreenSetup::exec(CMenuTarget* parent, const std::string &action) { if (!m) { selected = 0; x_coord[0] = startX; x_coord[1] = endX; y_coord[0] = startY; y_coord[1] = endY; if (!channel_id) { color_bak = frameBuffer->getBorderColor(); frameBuffer->getBorder(x_coord_bak[0], y_coord_bak[0], x_coord_bak[1], y_coord_bak[1]); } updateCoords(); frameBuffer->setBorder(x_coord[0], y_coord[0], x_coord[1], y_coord[1]); frameBuffer->setBorderColor(channel_id ? 0x44444444 : 0x88888888); frameBuffer->paintIcon(NEUTRINO_ICON_BORDER_UL, 0, 0); frameBuffer->paintIcon(NEUTRINO_ICON_BORDER_LR, screenwidth - 1 - 96, screenheight - 1 - 96 ); m = new CMenuWidget(channel_id ? LOCALE_VIDEOMENU_MASKSETUP : LOCALE_VIDEOMENU_SCREENSETUP, NEUTRINO_ICON_SETTINGS, w_max (40, 10)); m->addItem(new CMenuForwarder(LOCALE_SCREENSETUP_UPPERLEFT, true, coord[0], this, "ul", CRCInput::RC_red)); m->addItem(new CMenuForwarder(LOCALE_SCREENSETUP_LOWERRIGHT, true, coord[1], this, "lr", CRCInput::RC_green)); if (channel_id) m->addItem(new CMenuForwarder(LOCALE_SCREENSETUP_REMOVE, true, NULL, this, "rm", CRCInput::RC_yellow)); m->addKey(CRCInput::RC_home, this, "ex"); m->addKey(CRCInput::RC_timeout, this, "ti"); m->addKey(CRCInput::RC_ok, this, "ok"); m->addKey(CRCInput::RC_up, this, "u"); m->addKey(CRCInput::RC_down, this, "d"); m->addKey(CRCInput::RC_left, this, "l"); m->addKey(CRCInput::RC_right, this, "r"); m->addKey(CRCInput::RC_setup, this, "se"); m->setSelected(selected); m->exec(parent, ""); delete m; m = NULL; hide(); return menu_return::RETURN_REPAINT; } if (action == "ex" || action == "ti") { if (action == "ex" && ((startX != x_coord[0] ) || ( endX != x_coord[1] ) || ( startY != y_coord[0] ) || ( endY != y_coord[1] ) ) && (ShowMsg(LOCALE_VIDEOMENU_SCREENSETUP, LOCALE_MESSAGEBOX_DISCARD, CMessageBox::mbrYes, CMessageBox::mbYes | CMessageBox::mbCancel) == CMessageBox::mbrCancel)) return menu_return::RETURN_NONE; loadBorder(channel_id); return (action == "ex") ? menu_return::RETURN_EXIT : menu_return::RETURN_EXIT_ALL; } if (action == "ok") { startX = x_coord[0]; endX = x_coord[1]; startY = y_coord[0]; endY = y_coord[1]; if (channel_id) { borderFrame b; b.sx = startX; b.sy = startY; b.ex = endX; b.ey = endY; borderMap[channel_id] = b; showBorder(channel_id); saveBorders(); } else { x_coord_bak[0] = x_coord[0]; y_coord_bak[0] = y_coord[0]; x_coord_bak[1] = x_coord[1]; y_coord_bak[1] = y_coord[1]; g_settings.screen_StartX_int = x_coord[0]; g_settings.screen_EndX_int = x_coord[1]; g_settings.screen_StartY_int = y_coord[0]; g_settings.screen_EndY_int = y_coord[1]; showBorder(channel_id); if(g_settings.screen_preset) { g_settings.screen_StartX_lcd = g_settings.screen_StartX_int; g_settings.screen_StartY_lcd = g_settings.screen_StartY_int; g_settings.screen_EndX_lcd = g_settings.screen_EndX_int; g_settings.screen_EndY_lcd = g_settings.screen_EndY_int; } else { g_settings.screen_StartX_crt = g_settings.screen_StartX_int; g_settings.screen_StartY_crt = g_settings.screen_StartY_int; g_settings.screen_EndX_crt = g_settings.screen_EndX_int; g_settings.screen_EndY_crt = g_settings.screen_EndY_int; } } return menu_return::RETURN_EXIT; } if (action == "se") { coord_abs = !coord_abs; updateCoords(); return menu_return::RETURN_REPAINT; } if (action == "ul") { selected = 0; return menu_return::RETURN_REPAINT; } if (action == "lr") { selected = 1; return menu_return::RETURN_REPAINT; } if (action == "rm") { if (channel_id) { startX = g_settings.screen_StartX; startY = g_settings.screen_StartY; endX = g_settings.screen_EndX; endY = g_settings.screen_EndY; resetBorder(channel_id); saveBorders(); if (g_InfoViewer) g_InfoViewer->start(); return menu_return::RETURN_EXIT; } return menu_return::RETURN_NONE; } if (action == "u" || action == "d" || action == "l" || action == "r") { if ((action == "u") && (((selected == 0) && (y_coord[0] > 0)) || ((selected == 1) && (y_coord[1] > y_coord[0] - 100)))) y_coord[selected]--; else if ((action == "d") && (((selected == 0) && (y_coord[0] < y_coord[1] - 100)) || ((selected == 1) && (y_coord[1] < screenheight)))) y_coord[selected]++; else if ((action == "l") && (((selected == 0) && (x_coord[0] > 0)) || ((selected == 1) && (x_coord[1] > x_coord[0] - 100)))) x_coord[selected]--; else if ((action == "r") && (((selected == 0) && (x_coord[0] < x_coord[1] - 100)) || ((selected == 1) && (x_coord[1] < screenwidth)))) x_coord[selected]++; else return menu_return::RETURN_NONE; frameBuffer->setBorder(x_coord[0], y_coord[0], x_coord[1], y_coord[1]); updateCoords(); return menu_return::RETURN_REPAINT; } return menu_return::RETURN_NONE; }
int main(void) { //Initialize SDL if(SDL_Init(SDL_INIT_VIDEO) < 0) { return 1; } //Create the window, OpenGL context SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_Window* window = SDL_CreateWindow("TestSDL", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_OPENGL); if(!window) { SDL_Quit(); return 1; } SDL_GL_CreateContext(window); //Make sure we have a recent version of OpenGL GLenum glewError = glewInit(); if(glewError != GLEW_OK) { SDL_Quit(); return 1; } if(!GLEW_VERSION_1_5) { SDL_Quit(); return 1; } int tileW = 64; int tileH = 64; GLuint empty = glTexImageTGAFile("t3.tga", &tileW, &tileH ); GLuint cube = glTexImageTGAFile("t2.tga", &tileW, &tileW); GLuint ch1 = glTexImageTGAFile("char1.tga", &tileW, &tileH ); GLuint ch2 = glTexImageTGAFile("char2.tga", &tileW, &tileH ); GLuint ch3 = glTexImageTGAFile("char3.tga", &tileW, &tileH ); GLuint ch4 = glTexImageTGAFile("char4.tga", &tileW, &tileH ); GLuint ch5 = glTexImageTGAFile("char5.tga", &tileW, &tileH ); GLuint ch6 = glTexImageTGAFile("char6.tga", &tileW, &tileH ); GLuint ch7 = glTexImageTGAFile("char7.tga", &tileW, &tileH ); GLuint ch8 = glTexImageTGAFile("char8.tga", &tileW, &tileH ); //initialize player struct entity player; player.xPos = 0; player.yPos = 0; //struct coords crd; struct polygon pg; //bounding box for player pg.p1.xComp = 33.0; pg.p1.yComp = 1.0; pg.p2.xComp = 28.0; pg.p2.yComp = 0.0; pg.p3.xComp = 37.0; pg.p3.yComp = 0.0; pg.p4.xComp = 30.0; pg.p4.yComp = -1.0; player.pol = assemblePolygon(pg); player.zpos = 0; player.zVel = 0; player.isJumping = 0; player.stack = 0; player.image = &ch1; /*int tileMap[12][12] = {{1,1,1,1,1,2,2,1,1,1,1,1}, {1,1,1,1,1,2,2,1,1,1,1,1}, {1,1,1,1,1,2,2,1,1,1,1,1}, {1,1,1,1,1,2,2,1,1,1,1,1}, {1,1,1,1,1,2,2,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,2,2,1,1,1,1,1}, {1,1,1,1,1,2,2,1,1,1,1,1}, {1,1,1,1,1,2,2,1,1,1,1,1}, {1,1,1,1,1,2,2,1,1,1,1,1}}; int tileMapHeight[12][12] = {{2,2,2,2,3,1,1,4,3,2,2,2}, {2,1,1,1,2,1,1,2,1,1,1,2}, {2,1,1,1,2,1,1,2,1,1,1,2}, {2,1,1,1,2,1,1,2,1,1,1,2}, {2,1,1,1,2,1,1,2,1,1,1,2}, {2,1,1,1,2,2,2,2,1,1,1,2}, {2,1,1,1,1,1,1,1,1,1,1,2}, {2,1,1,1,2,2,2,2,1,1,1,2}, {2,1,1,1,2,1,1,2,1,1,1,2}, {2,1,1,1,2,1,1,2,1,1,1,2}, {2,1,1,1,2,1,1,2,1,1,1,2}, {2,2,2,2,2,1,1,2,2,2,2,2}}; */ struct chunk map = generateChunk(); int **tileMap = map.chunkBase; int **tileMapHeight = map.chunkBlocks; int mapHeight = 100; //sizeof(tileMap)/sizeof(tileMap[0]); int mapWidth = 100; // sizeof(tileMap[0])/sizeof(tileMap[0][0]); struct Tile tiles[(mapWidth * mapHeight)]; // may need to be 2d array int tileType; int tileHeight; int count =0; for(int i = 0; i< mapHeight; i++) { for(int j = mapWidth-1; j>= 0; j--) { tileType = tileMap[i][j]; tileHeight = tileMapHeight[i][j]; struct Tile t; t.stack = tileHeight; t.num = tileType; float xp = (j * tileXScaleCalc / 2) + (i * tileXScaleCalc / 2); float yp = (i * tileYScaleCalc / 2) - (j * tileYScaleCalc / 2); t.xPos = xp; t.yPos = yp; struct polygon pg; pg.p1.xComp = xp + 32.0; pg.p1.yComp = yp - 16.0; pg.p2.xComp = xp; pg.p2.yComp = yp - 32.0; pg.p3.xComp = xp + 30.0; pg.p3.yComp = yp - 48.0; pg.p4.xComp = xp + 62.0; pg.p4.yComp = yp - 32.0; t.pol = assemblePolygon(pg); if(tileType == 0) { t.image = ∅ t.xScale = tileXScale; t.yScale = tileYScale; } else if(tileType == 1) { t.image = &cube; t.xScale = tileXScale; t.yScale = tileXScale; } tiles[count] = t; count++; } } unsigned char kbPrevState[SDL_NUM_SCANCODES] = {0}; //The current frame's keyboard state const unsigned char* kbState = NULL; //Keep a pointer to SDL's internal keyboard state kbState = SDL_GetKeyboardState(NULL); glViewport( 0, 0, 800, 600 ); glMatrixMode(GL_PROJECTION); glOrtho( 0, 800, 600, 0, 0, 1 ); glEnable( GL_TEXTURE_2D ); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //lighting //glEnable(GL_LIGHTING); int shouldExit = 0; //change to int float xoffset = 0; float yoffset = 0; //int x; //int y; //start position. if player is colliding with a tile, move him till he doest updateCoords(350, -10, &player); int colindex = 0; while(checkCollision(player.pol, tiles,(mapWidth * mapHeight) , &colindex)) { updateCoords(1.5, 0, &player); xoffset += 1.5; } int ticksPerFrame = 1000 / 60; int prevTick = SDL_GetTicks(); int ticksPerPhysics = 1000 / 100; int prevPhysicsTick = prevTick; int mx, my; //testing, move to outside of loop int castEnable = 0; int shaddow; while(!shouldExit) { //kbState is updated by the message pump. Copy over the old state before the pump! memcpy(kbPrevState, kbState, sizeof(kbPrevState)); //Handle OS message pump SDL_Event event; while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: return 0; } } int tick = SDL_GetTicks(); do { SDL_Delay((int) fmax( 0, ticksPerFrame - (tick - prevTick) )); tick = SDL_GetTicks(); } while( ticksPerFrame - (tick - prevTick) > 0 ); prevTick = tick; const unsigned char* keys = SDL_GetKeyboardState(NULL); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); while( tick > prevPhysicsTick + ticksPerPhysics ) { SDL_GetMouseState(&mx, &my); mx -= player.pol.p1.xComp - xoffset; my -= player.pol.p1.yComp - player.zpos + screenScale - yoffset + 50; double angle = -(atan2(my, mx) * 180 * 3.14159265)/10; if(angle < 0) { angle += 360; } if(angle < 25) { player.image = &ch2; } else if(angle < 55) { player.image = &ch8; } else if(angle < 120) { player.image = &ch1; } else if(angle < 170) { player.image = &ch7; } else if(angle < 195) { player.image = &ch3; } else if(angle < 230) { player.image = &ch6; } else if(angle < 300) { player.image = &ch4; } else { player.image = &ch5; } //printf("mouse x = %i mouse y = %i angle = %f \n", mx, my, angle); // Update physics if(!checkCollision(player.pol, tiles,(mapWidth * mapHeight), &colindex) ) { player.stack = 0; colindex = 0; } if(keys[SDL_SCANCODE_SPACE] ) { playerJump(&player); //printf("jump"); //player.image = &ch3; } if(keys[SDL_SCANCODE_O] ) { castEnable = 1; } if(keys[SDL_SCANCODE_P] ) { castEnable = 0; } if(keys[SDL_SCANCODE_K] ) { shaddow = 1; } if(keys[SDL_SCANCODE_L] ) { shaddow = 0; } if(keys[SDL_SCANCODE_A] ) { xoffset -= 1.5; updateCoords(-1.5, 0, &player); if(checkCollision(player.pol, tiles,(mapWidth * mapHeight), &colindex) ) { if(player.zpos > tiles[colindex].stack * 10) { player.stack = tiles[colindex].stack; } else if(player.stack < tiles[colindex].stack) { //player.stack = 0; updateCoords(1.5, 0, &player); xoffset += 1.5; } } } if(keys[SDL_SCANCODE_D] ) { xoffset += 1.5; updateCoords(1.5, 0, &player); if(checkCollision(player.pol, tiles, (mapWidth * mapHeight), &colindex) ) { if(player.zpos > tiles[colindex].stack * 10) { player.stack = tiles[colindex].stack; } else if(player.stack < tiles[colindex].stack) { //player.stack = 0; updateCoords(-1.5, 0, &player); xoffset -= 1.5; } } } if(keys[SDL_SCANCODE_W] ) { yoffset -= 1.5 ; updateCoords(0, -1.5, &player); if(checkCollision(player.pol, tiles, (mapWidth * mapHeight), &colindex) ) { if(player.zpos > tiles[colindex].stack * 10) { player.stack = tiles[colindex].stack; } else if(player.stack < tiles[colindex].stack) { //player.stack = 0; yoffset += 1.5 ; updateCoords(0, 1.5, &player); //player.isColliding = 0; } } } if(keys[SDL_SCANCODE_S] ) { yoffset += 1.5; updateCoords(0, 1.5, &player); if(checkCollision(player.pol, tiles, (mapWidth * mapHeight), &colindex) ) { if(player.zpos > tiles[colindex].stack * 10) { player.stack = tiles[colindex].stack; } else if(player.stack < tiles[colindex].stack) { //player.stack = 0; updateCoords(0, -1.5, &player); yoffset -= 1.5; } } } playerTick(&player); prevPhysicsTick += ticksPerPhysics; } //draw base layer for(int z = 0; z < (mapWidth * mapHeight); z++) { if( tiles[z].xPos > xoffset && tiles[z].xPos < xoffset +750 && tiles[z].yPos > yoffset -250 && tiles[z].yPos < yoffset +270) { glDrawSprite(*tiles[z].image, tiles[z].xPos - xoffset, tiles[z].yPos+screenScale - yoffset, tiles[z].xScale, tiles[z].yScale ); } } //cast rays; optimise when to recalculate //This is debug code glLineWidth(.1); glColor3f(1.0f, 0.0f, 0.0f); if(castEnable) { for(int z = 0; z < (mapWidth * mapHeight); z++) { if(tiles[z].stack > 1) { if( tiles[z].xPos > xoffset && tiles[z].xPos < xoffset +750 && tiles[z].yPos > yoffset -250 && tiles[z].yPos < yoffset +270) { glBegin(GL_LINES); glVertex2f(player.pol.p1.xComp - xoffset, player.pol.p1.yComp - yoffset + screenScale + 64 - player.zpos) ; glVertex2f(tiles[z].pol.p1.xComp - xoffset, tiles[z].pol.p1.yComp +screenScale - yoffset + 64); glVertex2f(player.pol.p1.xComp - xoffset, player.pol.p1.yComp - yoffset + screenScale + 64 - player.zpos) ; glVertex2f(tiles[z].pol.p2.xComp - xoffset, tiles[z].pol.p2.yComp +screenScale - yoffset + 64); glVertex2f(player.pol.p1.xComp - xoffset, player.pol.p1.yComp - yoffset + screenScale + 64 - player.zpos) ; glVertex2f(tiles[z].pol.p3.xComp - xoffset, tiles[z].pol.p3.yComp +screenScale - yoffset + 64); glVertex2f(player.pol.p1.xComp - xoffset, player.pol.p1.yComp - yoffset + screenScale + 64 - player.zpos) ; glVertex2f(tiles[z].pol.p4.xComp - xoffset, tiles[z].pol.p4.yComp +screenScale - yoffset + 64); glEnd(); } } } } //cast shaddows //This is debug code if(shaddow) { int z = 999; while(tiles[z].stack <= 2) { z--; } glShadeModel(GL_SMOOTH); glBegin(GL_TRIANGLES); glColor4f(0.1, 0.2, 0.3, .0); glVertex3f(tiles[z].pol.p1.xComp - xoffset, tiles[z].pol.p1.yComp +screenScale - yoffset + 64, 0); glColor4f(0.4, 0.5, 0.6, .0); glVertex3f(tiles[z].pol.p2.xComp - xoffset, tiles[z].pol.p2.yComp +screenScale - yoffset + 64, 0); glColor4f(0.7, 0.8, 0.9, 1); glVertex3f(player.pol.p1.xComp - xoffset, player.pol.p1.yComp - yoffset + screenScale + 64 - player.zpos, 0); glEnd(); for(z = 0; z < (mapWidth * mapHeight); z++) { if(tiles[z].stack > 1) { if( tiles[z].xPos > xoffset && tiles[z].xPos < xoffset +750 && tiles[z].yPos > yoffset -250 && tiles[z].yPos < yoffset +270) { glShadeModel(GL_SMOOTH); //glBegin(GL_TRIANGLES); glBegin( GL_TRIANGLE_STRIP ); glColor4f(0.4, 0.5, 0.6, .0); glVertex3f(tiles[z].pol.p1.xComp - xoffset, tiles[z].pol.p1.yComp +screenScale - yoffset + 64, 0); glColor4f(0.4, 0.5, 0.6, .0); glVertex3f(tiles[z].pol.p2.xComp - xoffset, tiles[z].pol.p2.yComp +screenScale - yoffset + 64, 0); glColor4f(0.7, 0.8, 0.9, .6); glVertex3f(player.pol.p1.xComp - xoffset, player.pol.p1.yComp - yoffset + screenScale + 64 - player.zpos, 0); glColor4f(0.4, 0.5, 0.6, .0); glVertex3f(tiles[z].pol.p2.xComp - xoffset, tiles[z].pol.p2.yComp +screenScale - yoffset + 64, 0); glColor4f(0.4, 0.5, 0.6, .0); glVertex3f(tiles[z].pol.p3.xComp - xoffset, tiles[z].pol.p3.yComp +screenScale - yoffset + 64, 0); glColor4f(0.7, 0.8, 0.9, .6); glVertex3f(player.pol.p1.xComp - xoffset, player.pol.p1.yComp - yoffset + screenScale + 64 - player.zpos, 0); glColor4f(0.4, 0.5, 0.6, .0); glVertex3f(tiles[z].pol.p3.xComp - xoffset, tiles[z].pol.p3.yComp +screenScale - yoffset + 64, 0); glColor4f(0.4, 0.5, 0.6, .0); glVertex3f(tiles[z].pol.p4.xComp - xoffset, tiles[z].pol.p4.yComp +screenScale - yoffset + 64, 0); glColor4f(0.7, 0.8, 0.9, .6); glVertex3f(player.pol.p1.xComp - xoffset, player.pol.p1.yComp - yoffset + screenScale + 64 - player.zpos, 0); glColor4f(0.4, 0.5, 0.6, .0); glVertex3f(tiles[z].pol.p1.xComp - xoffset, tiles[z].pol.p1.yComp +screenScale - yoffset + 64, 0); glColor4f(0.4, 0.5, 0.6, .0); glVertex3f(tiles[z].pol.p2.xComp - xoffset, tiles[z].pol.p2.yComp +screenScale - yoffset + 64, 0); glColor4f(0.7, 0.8, 0.9, .6); glVertex3f(player.pol.p1.xComp - xoffset, player.pol.p1.yComp - yoffset + screenScale + 64 - player.zpos, 0); glEnd(); } } } } //############################################################################## here be dragons. //draw things behind and under player. for(int z = 0; z < (mapWidth * mapHeight); z++) { if(tiles[z].stack > 1) { if(player.pol.p1.yComp <= tiles[z].yPos - 16 - 14) { //do nothing } else { for(int ix = 1; ix < tiles[z].stack; ix++) { if( tiles[z].xPos > xoffset && tiles[z].xPos < xoffset +750 && tiles[z].yPos > yoffset -250 && tiles[z].yPos < yoffset +270 ) { glDrawSprite(*tiles[z].image, tiles[z].xPos - xoffset , tiles[z].yPos+screenScale -(ix * 16) - yoffset, tiles[z].xScale, tiles[z].yScale ); } } } if(player.stack >= tiles[z].stack -2) { for(int ix = 1; ix < tiles[z].stack; ix++) { if( tiles[z].xPos > xoffset && tiles[z].xPos < xoffset +750 && tiles[z].yPos > yoffset -250 && tiles[z].yPos < yoffset +270 ) { glDrawSprite(*tiles[z].image, tiles[z].xPos - xoffset , tiles[z].yPos+screenScale -(ix * 16) - yoffset, tiles[z].xScale, tiles[z].yScale ); } } } } } //draw player glDrawSprite(*player.image, player.pol.p1.xComp -30 - xoffset, player.pol.p1.yComp - player.zpos + screenScale - yoffset, 64, 64 ); //draw things in front of player for(int z = 0; z < (mapWidth * mapHeight); z++) { if(tiles[z].stack > 1) { if(player.pol.p1.yComp <= tiles[z].yPos - 16 - 14 ) { for(int ix = 1; ix < tiles[z].stack; ix++) { if( tiles[z].xPos > xoffset && tiles[z].xPos < xoffset +750 && tiles[z].yPos > yoffset -250 && tiles[z].yPos < yoffset +270 ) { if(tiles[z].stack > player.stack && ix >= player.stack) { glDrawSprite(*tiles[z].image, tiles[z].xPos - xoffset , tiles[z].yPos+screenScale -(ix * 16) - yoffset, tiles[z].xScale, tiles[z].yScale ); } } } if(z == colindex && tiles[z].stack == player.stack) { glDrawSprite(*player.image, player.pol.p1.xComp -30 - xoffset, player.pol.p1.yComp - player.zpos + screenScale - yoffset, 64, 64 ); } } } } //############################################################################## /* glLineWidth(2.5); glColor3f(1.0f, 0.0f, 0.0f); glBegin(GL_LINES); glVertex2f(10, 10); glVertex2f(20, 20); glEnd(); */ SDL_GL_SwapWindow(window); //glFlush(); } SDL_Quit(); return 0; }
void CubeMesh::setZ0( double v ) { z0_ = v; updateCoords(); }
ImodvImage::ImodvImage(QWidget *parent, bool fillBut, const char *name) : DialogFrame(parent, fillBut ? 3 : 2, 1, buttonLabels, buttonTips, true, ImodPrefs->getRoundedStyle(), "3dmodv Image View", "", name) { mCtrlPressed = false; // Make view checkboxes mViewXBox = diaCheckBox("View X image", this, mLayout); mViewXBox->setChecked(sFlags & IMODV_DRAW_CX); connect(mViewXBox, SIGNAL(toggled(bool)), this, SLOT(viewXToggled(bool))); mViewYBox = diaCheckBox("View Y image", this, mLayout); mViewYBox->setChecked(sFlags & IMODV_DRAW_CY); connect(mViewYBox, SIGNAL(toggled(bool)), this, SLOT(viewYToggled(bool))); mViewZBox = diaCheckBox("View Z image", this, mLayout); mViewZBox->setChecked(sFlags & IMODV_DRAW_CZ); connect(mViewZBox, SIGNAL(toggled(bool)), this, SLOT(viewZToggled(bool))); mViewXBox->setToolTip("Display YZ plane at current X"); mViewYBox->setToolTip("Display XZ plane at current Y"); mViewZBox->setToolTip("Display XY plane at current Z"); // Make multisliders mSliders = new MultiSlider(this, 10, sliderLabels); mSliders->setRange(IIS_X_COORD, 1, Imodv->vi->xsize); mSliders->setRange(IIS_X_SIZE, 1, Imodv->vi->xsize); if (sLastYsize < 0) { sXdrawSize = Imodv->vi->xsize; sYdrawSize = Imodv->vi->ysize; sZdrawSize = Imodv->vi->zsize; sLastYsize = Imodv->vi->ysize; } updateCoords(); mSliders->setValue(IIS_X_SIZE, sXdrawSize); mSliders->setValue(IIS_Y_SIZE, sYdrawSize); mSliders->setValue(IIS_Z_SIZE, sZdrawSize); mSliders->setRange(IIS_SLICES, 1, 64); mSliders->setValue(IIS_SLICES, sNumSlices); mSliders->setRange(IIS_TRANSPARENCY, 0, 100); mSliders->setValue(IIS_TRANSPARENCY, sImageTrans); mSliders->setValue(IIS_BLACK, sBlackLevel); mSliders->setValue(IIS_WHITE, sWhiteLevel); mLayout->addLayout(mSliders->getLayout()); (mSliders->getLayout())->setSpacing(4); connect(mSliders, SIGNAL(sliderChanged(int, int, bool)), this, SLOT(sliderMoved(int, int, bool))); mSliders->getSlider(IIS_X_COORD)->setToolTip("Set current image X coordinate"); mSliders->getSlider(IIS_Y_COORD)->setToolTip("Set current image Y coordinate"); mSliders->getSlider(IIS_Z_COORD)->setToolTip("Set current image Z coordinate"); mSliders->getSlider(IIS_X_SIZE)->setToolTip("Set image size to display in X"); mSliders->getSlider(IIS_Y_SIZE)->setToolTip("Set image size to display in Y"); mSliders->getSlider(IIS_Z_SIZE)->setToolTip("Set image size to display in Z"); mSliders->getSlider(IIS_SLICES)->setToolTip("Set number of slices to display"); mSliders->getSlider(IIS_TRANSPARENCY)->setToolTip("Set percent transparency"); mSliders->getSlider(IIS_BLACK)->setToolTip("Set minimum black level of contrast ramp"); mSliders->getSlider(IIS_WHITE)->setToolTip("Set maximum white level of contrast ramp"); QPushButton *copyBut = diaPushButton("Use 3dmod Black/White", this, mLayout); copyBut->setToolTip("Set black and white levels from sliders in 3dmod Info window"); connect(copyBut, SIGNAL(clicked()), this, SLOT(copyBWclicked())); // Make false color checkbox mFalseBox = diaCheckBox("False color", this, mLayout); mFalseBox->setChecked(sFalsecolor); connect(mFalseBox, SIGNAL(toggled(bool)), this, SLOT(falseToggled(bool))); mFalseBox->setToolTip("Display image in false color"); if (Imodv->vi->colormapImage) { mFalseBox->setEnabled(false); copyBut->setEnabled(false); mSliders->getSlider(IIS_SLICES)->setEnabled(false); mSliders->getSlider(IIS_BLACK)->setEnabled(false); mSliders->getSlider(IIS_WHITE)->setEnabled(false); } connect(this, SIGNAL(actionClicked(int)), this, SLOT(buttonPressed(int))); }
void CubeMesh::setNz( unsigned int v ) { nz_ = v; updateCoords(); }
void CubeMesh::setDz( double v ) { dz_ = v; updateCoords(); }
void CubeMesh::setDy( double v ) { dy_ = v; updateCoords(); }
void CubeMesh::setX1( double v ) { x1_ = v; updateCoords(); }
void CubeMesh::setY1( double v ) { y1_ = v; updateCoords(); }
OrientThread::OrientThread(QObject *parent) : QThread(parent) { updateCoords(); }
void CubeMesh::setDx( double v ) { dx_ = v; updateCoords(); }