void GrassNode::Load(stringc filename,s32 frmWidth,s32 frmHeight) { IVideoDriver* driver = SceneManager->getVideoDriver(); //dimension2d<u32> Screensize = driver->getScreenSize(); fx = (float)frmWidth;// /(float)Screensize.Width; fy = (float)frmHeight;// /(float)Screensize.Height; Vertices[0] = S3DVertex(-fx,-fy,0, 0,0,0,SColor(255,255,255,255),0,1); Vertices[1] = S3DVertex( fx,-fy,0, 0,0,0,SColor(255,255,255,255),1,1); Vertices[2] = S3DVertex( fx, fy,0, 0,0,0,SColor(255,255,255,255),1,0); Vertices[3] = S3DVertex(-fx, fy,0, 0,0,0,SColor(255,255,255,255),0,0); Box.reset(Vertices[0].Pos); for (s32 i=1; i<4; ++i) Box.addInternalPoint(Vertices[i].Pos); Texture = driver->getTexture(filename); //driver->makeColorKeyTexture(Texture,position2d<s32>(0,0)); Material.setTexture(0,Texture); Material.TextureLayer[0].BilinearFilter = false; Material.MaterialType = EMT_TRANSPARENT_ALPHA_CHANNEL_REF; dimension2d<u32> size = Texture->getOriginalSize(); fWidth = (float)frmWidth/(float)size.Width; fHeight = (float)frmHeight/(float)size.Height; stepww = size.Width / frmWidth; stephh = size.Height / frmHeight; Vertices[0].TCoords.X = 0; Vertices[0].TCoords.Y = fHeight; Vertices[1].TCoords.X = fWidth; Vertices[1].TCoords.Y = fHeight; Vertices[2].TCoords.X = fWidth; Vertices[2].TCoords.Y = 0; Vertices[3].TCoords.X = 0; Vertices[3].TCoords.Y = 0; // Place Holder < ---------------------------------------- < - < - < - > amount = 4; for (unsigned int i = 0; i < amount; i++) { frames[i].preLoopFrame = 0; frames[i].startFrame = 0; frames[i].endFrame = 0; frames[i].time = 60; } // Box2d body = 0; b2BodyDef myBody; myBody.type = b2_staticBody; myBody.position.Set( 0, 0 ); myBody.angle = 0; myBody.fixedRotation = true; body = physics->world->CreateBody(&myBody); for (int j = -57; j < 13; j++) // TEMP for (int k = 0; k < 1; k++) createParticle((float)frmWidth, (float)frmHeight, b2Vec2(j,k + 0.25)); for (int j = 49; j < 100; j++) // TEMP for (int k = 0; k < 1; k++) createParticle((float)frmWidth, (float)frmHeight, b2Vec2(j,k + 0.25)); SetSpeed(80); }
void IrrDriver::renderGLSL(float dt) { BoundingBoxes.clear(); World *world = World::getWorld(); // Never NULL. Track *track = world->getTrack(); for (unsigned i = 0; i < PowerupManager::POWERUP_MAX; i++) { scene::IMesh *mesh = powerup_manager->m_all_meshes[i]; if (!mesh) continue; for (unsigned j = 0; j < mesh->getMeshBufferCount(); j++) { scene::IMeshBuffer *mb = mesh->getMeshBuffer(j); if (!mb) continue; for (unsigned k = 0; k < 4; k++) { video::ITexture *tex = mb->getMaterial().getTexture(k); if (!tex) continue; compressTexture(tex, true); } } } // Overrides video::SOverrideMaterial &overridemat = m_video_driver->getOverrideMaterial(); overridemat.EnablePasses = scene::ESNRP_SOLID | scene::ESNRP_TRANSPARENT; overridemat.EnableFlags = 0; if (m_wireframe) { overridemat.Material.Wireframe = 1; overridemat.EnableFlags |= video::EMF_WIREFRAME; } if (m_mipviz) { overridemat.Material.MaterialType = Shaders::getShader(ES_MIPVIZ); overridemat.EnableFlags |= video::EMF_MATERIAL_TYPE; overridemat.EnablePasses = scene::ESNRP_SOLID; } // Get a list of all glowing things. The driver's list contains the static ones, // here we add items, as they may disappear each frame. std::vector<GlowData> glows = m_glowing; ItemManager * const items = ItemManager::get(); const u32 itemcount = items->getNumberOfItems(); u32 i; for (i = 0; i < itemcount; i++) { Item * const item = items->getItem(i); if (!item) continue; const Item::ItemType type = item->getType(); if (type != Item::ITEM_NITRO_BIG && type != Item::ITEM_NITRO_SMALL && type != Item::ITEM_BONUS_BOX && type != Item::ITEM_BANANA && type != Item::ITEM_BUBBLEGUM) continue; LODNode * const lod = (LODNode *) item->getSceneNode(); if (!lod->isVisible()) continue; const int level = lod->getLevel(); if (level < 0) continue; scene::ISceneNode * const node = lod->getAllNodes()[level]; node->updateAbsolutePosition(); GlowData dat; dat.node = node; dat.r = 1.0f; dat.g = 1.0f; dat.b = 1.0f; const video::SColorf &c = ItemManager::getGlowColor(type); dat.r = c.getRed(); dat.g = c.getGreen(); dat.b = c.getBlue(); glows.push_back(dat); } // Start the RTT for post-processing. // We do this before beginScene() because we want to capture the glClear() // because of tracks that do not have skyboxes (generally add-on tracks) m_post_processing->begin(); RaceGUIBase *rg = world->getRaceGUI(); if (rg) rg->update(dt); if (!CVS->isDefferedEnabled()) { SColor clearColor(0, 150, 150, 150); if (World::getWorld() != NULL) clearColor = World::getWorld()->getClearColor(); glClear(GL_COLOR_BUFFER_BIT); glDepthMask(GL_TRUE); glBindFramebuffer(GL_FRAMEBUFFER, 0); glClearColor(clearColor.getRed() / 255.f, clearColor.getGreen() / 255.f, clearColor.getBlue() / 255.f, clearColor.getAlpha() / 255.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } for(unsigned int cam = 0; cam < Camera::getNumCameras(); cam++) { Camera * const camera = Camera::getCamera(cam); scene::ICameraSceneNode * const camnode = camera->getCameraSceneNode(); std::ostringstream oss; oss << "drawAll() for kart " << cam; PROFILER_PUSH_CPU_MARKER(oss.str().c_str(), (cam+1)*60, 0x00, 0x00); camera->activate(!CVS->isDefferedEnabled()); rg->preRenderCallback(camera); // adjusts start referee m_scene_manager->setActiveCamera(camnode); const core::recti &viewport = camera->getViewport(); if (World::getWorld() && World::getWorld()->getTrack()->hasShadows() && m_spherical_harmonics->has6Textures()) irr_driver->getSceneManager()->setAmbientLight(SColor(0, 0, 0, 0)); if (!CVS->isDefferedEnabled()) glEnable(GL_FRAMEBUFFER_SRGB); PROFILER_PUSH_CPU_MARKER("Update Light Info", 0xFF, 0x0, 0x0); unsigned plc = updateLightsInfo(camnode, dt); PROFILER_POP_CPU_MARKER(); PROFILER_PUSH_CPU_MARKER("UBO upload", 0x0, 0xFF, 0x0); computeMatrixesAndCameras(camnode, viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X, viewport.LowerRightCorner.Y - viewport.UpperLeftCorner.Y); uploadLightingData(); PROFILER_POP_CPU_MARKER(); renderScene(camnode, plc, glows, dt, track->hasShadows(), false); // Render bounding boxes if (irr_driver->getBoundingBoxesViz()) { Shaders::ColoredLine *line = Shaders::ColoredLine::getInstance(); line->use(); line->bindVertexArray(); line->bindBuffer(); line->setUniforms(SColor(255, 255, 0, 0)); const float *tmp = BoundingBoxes.data(); for (unsigned int i = 0; i < BoundingBoxes.size(); i += 1024 * 6) { unsigned count = MIN2((int)BoundingBoxes.size() - i, 1024 * 6); glBufferSubData(GL_ARRAY_BUFFER, 0, count * sizeof(float), &tmp[i]); glDrawArrays(GL_LINES, 0, count / 3); } } // Debug physic // Note that drawAll must be called before rendering // the bullet debug view, since otherwise the camera // is not set up properly. This is only used for // the bullet debug view. if (UserConfigParams::m_artist_debug_mode) World::getWorld()->getPhysics()->draw(); if (world != NULL && world->getPhysics() != NULL) { IrrDebugDrawer* debug_drawer = world->getPhysics()->getDebugDrawer(); if (debug_drawer != NULL && debug_drawer->debugEnabled()) { const std::map<video::SColor, std::vector<float> >& lines = debug_drawer->getLines(); std::map<video::SColor, std::vector<float> >::const_iterator it; Shaders::ColoredLine *line = Shaders::ColoredLine::getInstance(); line->use(); line->bindVertexArray(); line->bindBuffer(); for (it = lines.begin(); it != lines.end(); it++) { line->setUniforms(it->first); const std::vector<float> &vertex = it->second; const float *tmp = vertex.data(); for (unsigned int i = 0; i < vertex.size(); i += 1024 * 6) { unsigned count = MIN2((int)vertex.size() - i, 1024 * 6); glBufferSubData(GL_ARRAY_BUFFER, 0, count * sizeof(float), &tmp[i]); glDrawArrays(GL_LINES, 0, count / 3); } } glUseProgram(0); glBindVertexArray(0); } } // Render the post-processed scene if (CVS->isDefferedEnabled()) { bool isRace = StateManager::get()->getGameState() == GUIEngine::GAME; FrameBuffer *fbo = m_post_processing->render(camnode, isRace); if (irr_driver->getNormals()) irr_driver->getFBO(FBO_NORMAL_AND_DEPTHS).BlitToDefault(viewport.UpperLeftCorner.X, viewport.UpperLeftCorner.Y, viewport.LowerRightCorner.X, viewport.LowerRightCorner.Y); else if (irr_driver->getSSAOViz()) { glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(viewport.UpperLeftCorner.X, viewport.UpperLeftCorner.Y, viewport.LowerRightCorner.X, viewport.LowerRightCorner.Y); m_post_processing->renderPassThrough(m_rtts->getFBO(FBO_HALF1_R).getRTT()[0], viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X, viewport.LowerRightCorner.Y - viewport.UpperLeftCorner.Y); } else if (irr_driver->getRSM()) { glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(viewport.UpperLeftCorner.X, viewport.UpperLeftCorner.Y, viewport.LowerRightCorner.X, viewport.LowerRightCorner.Y); m_post_processing->renderPassThrough(m_rtts->getRSM().getRTT()[0], viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X, viewport.LowerRightCorner.Y - viewport.UpperLeftCorner.Y); } else if (irr_driver->getShadowViz()) { getShadowMatrices()->renderShadowsDebug(); } else { glEnable(GL_FRAMEBUFFER_SRGB); glBindFramebuffer(GL_FRAMEBUFFER, 0); if (CVS->isDefferedEnabled()) camera->activate(); m_post_processing->renderPassThrough(fbo->getRTT()[0], viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X, viewport.LowerRightCorner.Y - viewport.UpperLeftCorner.Y); glDisable(GL_FRAMEBUFFER_SRGB); } } // Save projection-view matrix for the next frame camera->setPreviousPVMatrix(m_ProjViewMatrix); PROFILER_POP_CPU_MARKER(); } // for i<world->getNumKarts() // Use full screen size float tmp[2]; tmp[0] = float(m_actual_screen_size.Width); tmp[1] = float(m_actual_screen_size.Height); glBindBuffer(GL_UNIFORM_BUFFER, SharedGPUObjects::getViewProjectionMatricesUBO()); glBufferSubData(GL_UNIFORM_BUFFER, (16 * 9) * sizeof(float), 2 * sizeof(float), tmp); glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glUseProgram(0); // Set the viewport back to the full screen for race gui m_video_driver->setViewPort(core::recti(0, 0, irr_driver->getActualScreenSize().Width, irr_driver->getActualScreenSize().Height)); for(unsigned int i=0; i<Camera::getNumCameras(); i++) { Camera *camera = Camera::getCamera(i); std::ostringstream oss; oss << "renderPlayerView() for kart " << i; PROFILER_PUSH_CPU_MARKER(oss.str().c_str(), 0x00, 0x00, (i+1)*60); rg->renderPlayerView(camera, dt); PROFILER_POP_CPU_MARKER(); } // for i<getNumKarts { ScopedGPUTimer Timer(getGPUTimer(Q_GUI)); PROFILER_PUSH_CPU_MARKER("GUIEngine", 0x75, 0x75, 0x75); // Either render the gui, or the global elements of the race gui. GUIEngine::render(dt); PROFILER_POP_CPU_MARKER(); } // Render the profiler if(UserConfigParams::m_profiler_enabled) { PROFILER_DRAW(); } #ifdef DEBUG drawDebugMeshes(); #endif PROFILER_PUSH_CPU_MARKER("EndSccene", 0x45, 0x75, 0x45); m_video_driver->endScene(); PROFILER_POP_CPU_MARKER(); getPostProcessing()->update(dt); }
//set background color void Java_zte_irrlib_scene_Scene_nativeSetClearColor( JNIEnv *env, jobject defaultObj, jint r, jint g, jint b, jint a) { backColor = SColor(a,r,g,b); }
inline void Editor::drawEditorFrame(IVideoDriver *driver){ /*for (int i = -2*EDITOR_HALF_SCREEN_SIZE; i < 2*EDITOR_HALF_SCREEN_SIZE; i += 25) { if (currentEksen == EKSEN_Z){ driver->draw3DLine(vector3df(-EDITOR_SCREEN_WIDTH, i, 0), vector3df(EDITOR_SCREEN_WIDTH, i, 0), SColor(255, 184, 184, 184)); driver->draw3DLine(vector3df(i, -EDITOR_SCREEN_WIDTH, 0), vector3df(i, EDITOR_SCREEN_WIDTH, 0), SColor(255, 184, 184, 184)); } else if(currentEksen == EKSEN_X){ driver->draw3DLine(vector3df(0, -EDITOR_SCREEN_WIDTH, i), vector3df(0, EDITOR_SCREEN_WIDTH, i), SColor(255, 184, 184, 184)); driver->draw3DLine(vector3df(0, i, -EDITOR_SCREEN_WIDTH), vector3df(0, i, EDITOR_SCREEN_WIDTH), SColor(255, 184, 184, 184)); } else if (currentEksen == EKSEN_Y){ driver->draw3DLine(vector3df(i, 0, -EDITOR_SCREEN_WIDTH), vector3df(i, 0, EDITOR_SCREEN_WIDTH), SColor(255, 184, 184, 184)); driver->draw3DLine(vector3df(-EDITOR_SCREEN_WIDTH, 0, i), vector3df(EDITOR_SCREEN_WIDTH, 0 ,i), SColor(255, 184, 184, 184)); } }*/ for (int i = -2 * EDITOR_HALF_SCREEN_SIZE; i < 2 * EDITOR_HALF_SCREEN_SIZE; i += 50) { driver->draw3DLine(vector3df(-EDITOR_SCREEN_WIDTH, i, EDITOR_SCREEN_WIDTH), vector3df(EDITOR_SCREEN_WIDTH, i, EDITOR_SCREEN_WIDTH), SColor(255, 184, 184, 184)); driver->draw3DLine(vector3df(i, -EDITOR_SCREEN_WIDTH, EDITOR_SCREEN_WIDTH), vector3df(i, EDITOR_SCREEN_WIDTH, EDITOR_SCREEN_WIDTH), SColor(255, 184, 184, 184)); driver->draw3DLine(vector3df(EDITOR_SCREEN_WIDTH, -EDITOR_SCREEN_WIDTH, i), vector3df(EDITOR_SCREEN_WIDTH, EDITOR_SCREEN_WIDTH, i), SColor(255, 184, 184, 184)); driver->draw3DLine(vector3df(EDITOR_SCREEN_WIDTH, i, -EDITOR_SCREEN_WIDTH), vector3df(EDITOR_SCREEN_WIDTH, i, EDITOR_SCREEN_WIDTH), SColor(255, 184, 184, 184)); driver->draw3DLine(vector3df(i, EDITOR_SCREEN_WIDTH, -EDITOR_SCREEN_WIDTH), vector3df(i, EDITOR_SCREEN_WIDTH, EDITOR_SCREEN_WIDTH), SColor(255, 184, 184, 184)); driver->draw3DLine(vector3df(-EDITOR_SCREEN_WIDTH, EDITOR_SCREEN_WIDTH, i), vector3df(EDITOR_SCREEN_WIDTH, EDITOR_SCREEN_WIDTH, i), SColor(255, 184, 184, 184)); driver->draw3DLine(vector3df(-EDITOR_SCREEN_WIDTH, i, -EDITOR_SCREEN_WIDTH), vector3df(EDITOR_SCREEN_WIDTH, i, -EDITOR_SCREEN_WIDTH), SColor(255, 184, 184, 184)); driver->draw3DLine(vector3df(i, -EDITOR_SCREEN_WIDTH, -EDITOR_SCREEN_WIDTH), vector3df(i, EDITOR_SCREEN_WIDTH, -EDITOR_SCREEN_WIDTH), SColor(255, 184, 184, 184)); driver->draw3DLine(vector3df(-EDITOR_SCREEN_WIDTH, -EDITOR_SCREEN_WIDTH, i), vector3df(-EDITOR_SCREEN_WIDTH, EDITOR_SCREEN_WIDTH, i), SColor(255, 184, 184, 184)); driver->draw3DLine(vector3df(-EDITOR_SCREEN_WIDTH, i, -EDITOR_SCREEN_WIDTH), vector3df(-EDITOR_SCREEN_WIDTH, i, EDITOR_SCREEN_WIDTH), SColor(255, 184, 184, 184)); driver->draw3DLine(vector3df(i, -EDITOR_SCREEN_WIDTH, -EDITOR_SCREEN_WIDTH), vector3df(i, -EDITOR_SCREEN_WIDTH, EDITOR_SCREEN_WIDTH), SColor(255, 184, 184, 184)); driver->draw3DLine(vector3df(-EDITOR_SCREEN_WIDTH, -EDITOR_SCREEN_WIDTH, i), vector3df(EDITOR_SCREEN_WIDTH, -EDITOR_SCREEN_WIDTH, i), SColor(255, 184, 184, 184)); } }
// Der Algorithmus von Bruton für Wellenlängen im sichtbaren Licht, λ ∈ [380, 780] nm SColor colorFromWavelength( f64 lambda, f64 gamma) { // Der Algorithmus von Dan Bruton [1] zur Berechnung von rgb-Werten aus Wellenlängen λ ∈ [380, 780] // er teilt das sichtbare Spektrum zunächst in Intervalle auf, // innerhalb derer jeweils nur einer der rgb-Parameter linear verändert wird. // Es folgt eine Adjustierung zur Dämpfung der Intensität an den Sichtbarkeitsgrenzen // und schließlich eine γ-Korrektur. // Sei also λ eine sichtbare Wellenlänge, ausgedrückt in der Einheit Nanometer (nm): // λ ∈ [380, 780]. Weiter sei γ > 0 eine feste Zahl (γ = 0.8 bei Bruton). // Wir setzen zunächst: // setze λ ∈ [380, 780] if (lambda < 380.0) lambda = 380.0; if (lambda > 780.0) lambda = 780.0; // Fallunterscheidung f64 r,g,b; if ((lambda >= 380.0) && (lambda < 440.0)) { r = (440.0-lambda)/(440.0-380.0); g = 0.0; b = 1.0; } else if ((lambda >= 440.0) && (lambda < 490.0)) { r = 0.0; g = (lambda-440.0)/(490.0-440.0); b = 1.0; } else if ((lambda >= 490.0) && (lambda < 510.0)) { r = 0.0; g = 1.0; b = (510.0-lambda)/(510.0-490.0); } else if ((lambda >= 510.0) && (lambda < 580.0)) { r = (lambda-510.0)/(580.0-510.0); g = 1.0; b = 0.0; } else if ((lambda >= 580.0) && (lambda < 645.0)) { r = 1.0; g = (645.0-lambda)/(645.0-580.0); b = 0.0; } else // if ((lambda >= 645.0) && (lambda <= 780.0)) { r = 1.0; g = 0.0; b = 0.0; } // Reduzierung der Intensität an den Rändern double f; if ((lambda >= 380.0) && (lambda < 420.0)) { f = 0.3 + 0.7*(lambda-380.0)/(420.0-380.0); } else if ((lambda >= 420.0) && (lambda <= 700.0)) { f = 1.0; } else // if ((lambda > 700.0) && (lambda <= 780.0)) { f = 0.3 + 0.7*(780.0-lambda)/(780.0-700.0); } // eigentliche Korrektur if (f!=1.0) { r *= f; g *= f; b *= f; } // Gamma Korrektur if (gamma!=1.0) { r = pow(r, gamma); g = pow(g, gamma); b = pow(b, gamma); } // Clamping to [0,255] r *= 255.0; g *= 255.0; b *= 255.0; // hoffentlicht optimiert der compiler dies mit mmx und sse befehlen if (r<0.0) r=0.0; if (g<0.0) g=0.0; if (b<0.0) b=0.0; if (r>255.0) r=255.0; if (g>255.0) g=255.0; if (b>255.0) b=255.0; // return ARGB 32bit color (Alpha = 'opaque' = 'nicht transparent' = '255') return SColor(255,(u32)r, (u32)g, (u32)b ); }
// ---------------------------------------------------------------------------- void RoadCrossSectionWndw::buttonClicked(u32 id) { path icons = Editor::getEditor()->getIconsLoc(); switch (id) { case SYM_ON_OFF: m_sym_mode = !m_sym_mode; if (m_sym_mode) { m_sym->setImage(Editor::loadImg(icons + "symm_on.png")); m_sym->setToolTipText(_(L"Click to turn off symmetry")); } else { m_sym->setImage(Editor::loadImg(icons + "symm_off.png")); m_sym->setToolTipText(_(L"Click to turn on symmetry")); } for (u32 j = 0; j < 2; j++) { for (u32 i = 0; i < m_node_num / 4; i++) { m_nodes[i + j * 3 * m_node_num / 4]->getMaterial(0).DiffuseColor = SColor(255, m_sym_mode ? 0 : 255, 0, m_sym_mode ? 255 : 0); m_nodes[i + j * 3 * m_node_num / 4]->getMaterial(0).AmbientColor = SColor(255, m_sym_mode ? 0 : 255, 0, m_sym_mode ? 255 : 0); } } return; case POINT_M: setPointNum(m_node_num - 4); return; case POINT_P: setPointNum(m_node_num + 4); return; case GRID_ON_OFF: if (!m_grid_on) { m_grid_on = true; m_gof->setImage(Editor::loadImg(icons + "grid-on_align-off.png")); } // grid on else { if (!m_allign) { m_allign = true; m_gof->setImage(Editor::loadImg(icons + "grid-on_align-on.png")); m_gof->setToolTipText(_(L"Grid off alignment off")); } else { m_allign = false; m_grid_on = false; m_gof->setImage(Editor::loadImg(icons + "grid-off_align-off.png")); m_gof->setToolTipText(_(L"Grid on alignment off")); } // allign on } // !grid on return; case GRID_M: m_grid *= 2; if (m_grid > 1) m_grid = 1; return; case GRID_P: m_grid /= 2; if (m_grid < 0.0625) m_grid = 0.0625; return; default: return; } // switch (id) } // buttonClicked
it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 3-DPhysicsSim is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "PathDrawableObject.h" SColor PathDrawableObject::color = SColor(255, 255, 255, 255); int PathDrawableObject::numFrames = 3; //int PathDrawableObject::maxNumLines = 0; PathDrawableObject::PathDrawableObject(bool _drawPath) { drawPath = _drawPath; pathVertices.set_used(0); pathIndicies.set_used(0); currentIndex = 0; currentFrame = 0; } void PathDrawableObject::ShowObjectPath()
void Button::Draw(irr::video::IVideoDriver* driver) { //if button is an item (bronze ore, bronze dagger, etc) if (q_BotRight.X) { //render sprite iSlot.item.loadSprite(driver, i_TopLeft); //if selected, draw a rectangle on it if (selected) { driver->draw2DRectangle(video::SColor(100, 255, 255, 0), rect<s32>(i_TopLeft.X, i_TopLeft.Y, i_BotRight.X, i_BotRight.Y), 0); } //render the qty of the item in the slot //char quantity = iSlot.qty; std::string s = std::to_string(iSlot.qty); stringw test = s.c_str(); m_font->draw(test, irr::core::rect<s32>(q_TopLeft.X, q_TopLeft.Y, q_BotRight.X, q_BotRight.Y), SColor(255, 255, 0, 0), true, true); } //if button is a button (buy, sell, craft, etc) else { buttonImage.Draw(driver); //if (text.size() > 0) //{ //m_font->draw(text, irr::core::rect<s32>(q_TopLeft.X, q_TopLeft.Y, q_BotRight.X, q_BotRight.Y), SColor(255, 255, 0, 0), true, true); //} } }
//------------------------------------------------------------------------------------- void Interface::Desenha(void) { if (navePrincipal == NULL) return; //mostra o life dos inimigos list<void *>::Iterator lista; Objeto *atual = (Objeto *) central->PrimeiroObjeto(&lista); while (atual != NULL) { if (atual->Mensagem(QUEM_VOCE, NULL) == INIMIGO) { //pego a posição do inimigo na tela position2d<s32> pos = central->Device()->getSceneManager()->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(atual->Posicao()); central->Device()->getVideoDriver()->draw2DRectangle(SColor(100, 255, 255, 0), Retangulo((s32) (pos.X - (atual->Life() / 2)), (s32) (pos.Y - 30), (s32) (pos.X +(atual->Life() / 2)), (s32) (pos.Y - 20))); } atual = (Objeto *) central->ProximoObjeto(&lista); } //desenho o cockpit no caso da camera interna if (((Camera *) (central->QualCamera()))->QualModo() == DE_DENTRO) central->Device()->getVideoDriver()->draw2DImage(cockpit, position2d<s32>(ConverteX(0), ConverteY(0)), rect<s32>(0, 0, 800, 600), NULL, SColor(255, 255, 255, 255), true); if (transicaoLife == 0) { delete transparenciaLife; transparenciaLife = new Fader(CLARO_ESCURO_CLARO, 100, 100, 100, 100, 255); } int life, lifePotencial; if (transicaoLife <= (3 * TEMPO_TRANSICAO) / 4) //mostra o life verdadeiro { life = (int) navePrincipal->Life(); lifePotencial = (int) navePrincipal->LifePotencial(); } else //faz uma pequena transição { float t = (TEMPO_TRANSICAO - transicaoLife) / (TEMPO_TRANSICAO / 4); life = (int) ((float) (t * lifeAnterior + (1 - t) * navePrincipal->Life())); lifePotencial = (int) ((float) (t * lifePotencialAnterior + (1 - t) * navePrincipal->LifePotencial())); } int tmp = transparenciaLife->Atualiza(); central->Device()->getVideoDriver()->draw2DRectangle(SColor(tmp, 255, 0, 0), Retangulo(10, 10, lifePotencial, 25)); central->Device()->getVideoDriver()->draw2DRectangle(SColor(tmp, 255, 255, 0), Retangulo(10, 10, life, 25)); //desenho os alvos for (int i = 0; i < fase->QuantosInimigosRestam(); i += 2) { central->Device()->getVideoDriver()->draw2DImage(alvo, position2d<s32>(ConverteX(630), ConverteY(10 + (60 * (i / 2)))), rect<s32>(0, 0, alvo->getOriginalSize().Height, alvo->getOriginalSize().Width), NULL, SColor(120, 255, 255, 255), true); if (i + 1 < fase->QuantosInimigosRestam()) central->Device()->getVideoDriver()->draw2DImage(alvo, position2d<s32>(ConverteX(700), ConverteY(10 + (60 * (i / 2)))), rect<s32>(0, 0, alvo->getOriginalSize().Height, alvo->getOriginalSize().Width), NULL, SColor(120, 255, 255, 255), true); } // desenho os logos // primeiro o básico int basico = navePrincipal->QualTipoTiroBasico(); central->Device()->getVideoDriver()->draw2DImage(EscolheLogo(basico), position2d<s32>(ConverteX(10), ConverteY(540)), rect<s32>(0, 0, logoLaser->getOriginalSize().Height, logoLaser->getOriginalSize().Width), NULL, SColor(120 + (135 * navePrincipal->QualTempoBonus(basico) / TEMPO_BONUS), 255, 255, 255), true); // agora os outros int quantosForam = 1; for (int i = 0; i < QTD_TIPOS_TIROS; i++) { if (i != basico && navePrincipal->QualTempoBonus(i) > 0) //desenho esse { central->Device()->getVideoDriver()->draw2DImage(EscolheLogo(i), position2d<s32>(ConverteX(10 + (60 * quantosForam)), ConverteY(540)), rect<s32>(0, 0, EscolheLogo(i)->getOriginalSize().Height, EscolheLogo(i)->getOriginalSize().Width), NULL, SColor((255 * navePrincipal->QualTempoBonus(i)) / TEMPO_BONUS, 255, 255, 255), true); quantosForam++; } } }
// ---------------------------------------------------------------------------- Terrain::Terrain(ISceneNode* parent, ISceneManager* mgr, s32 id, FILE* fp) :ISceneNode(parent, mgr, id) { m_visible = true; m_valid = true; setAutomaticCulling(EAC_OFF); fread(&m_x, sizeof(f32), 1, fp); fread(&m_z, sizeof(f32), 1, fp); if (m_x < 1 || m_z < 1 || m_x > 500 || m_z > 500) { m_valid = false; return; } fread(&m_nx, sizeof(u32), 1, fp); fread(&m_nz, sizeof(u32), 1, fp); if (m_nx > 400 || m_nz > 400) { m_valid = false; return; } m_bounding_box = aabbox3d<f32>(0, 0, 0, m_x, 0, m_z); m_tile_num_x = 10; m_tile_num_z = 10; m_mesh.vertex_count = m_nx * m_nz; m_mesh.vertices = new S3DVertex2TCoords[m_mesh.vertex_count]; m_mesh.quad_count = (m_nx - 1) * (m_nz - 1); m_mesh.indices = new u16[m_mesh.quad_count * 6]; for (u32 j = 0; j < m_nz; j++) for (u32 i = 0; i < m_nx; i++) { m_mesh.vertices[j * m_nx + i].Pos = vector3df(m_x / m_nx * i, 0, m_z / m_nz *j); fread(&m_mesh.vertices[j * m_nx + i].Pos.Y, sizeof(f32), 1, fp); m_mesh.vertices[j * m_nx + i].Color = SColor(255, 255, 255, 255); m_mesh.vertices[j * m_nx + i].TCoords = vector2df(i / (float)m_nx * m_tile_num_x, j / (float)m_nz * m_tile_num_z); m_mesh.vertices[j * m_nx + i].TCoords2 = vector2df(i / (float)m_nx, j / (float)m_nz); } createIndexList(m_mesh.indices, m_nx, m_nz); recalculateNormals(); m_highlight_mesh.vertices = 0; m_highlight_mesh.indices = 0; initMaterials(); u32 x, y; fread(&x, sizeof(u32), 1, fp); fread(&y, sizeof(u32), 1, fp); if (x != SPIMG_X || y != SPIMG_Y) { std::cerr << "Warning: splatting image size incorrect!\n"; } fread(m_material.getTexture(1)->lock(ETLM_WRITE_ONLY), sizeof(u8), 4 * SPIMG_X*SPIMG_Y, fp); m_material.getTexture(1)->unlock(); m_material.getTexture(1)->regenerateMipMapLevels(); m_highlight_visible = false; ITexture* tex; Editor::readTexSt(fp, &tex); m_material.setTexture(2,tex); Editor::readTexSt(fp, &tex); m_material.setTexture(3, tex); Editor::readTexSt(fp, &tex); m_material.setTexture(4, tex); Editor::readTexSt(fp, &tex); m_material.setTexture(5, tex); } // Terrain - fp
//! Creates a normal map from a height map texture. //! \param amplitude: Constant value by which the height information is multiplied. void CNullDriver::makeNormalMapTexture(ITexture* texture, f32 amplitude) const { if (!texture) return; if (texture->getColorFormat() != ECF_A1R5G5B5 && texture->getColorFormat() != ECF_A8R8G8B8 ) { Printer::log("Error: Unsupported texture color format for making normal map.", ELL_ERROR); return; } dimension2d<u32> dim = texture->getSize(); amplitude = amplitude / 255.0f; f32 vh = dim.Height / (f32)dim.Width; f32 hh = dim.Width / (f32)dim.Height; if (texture->getColorFormat() == ECF_A8R8G8B8) { // ECF_A8R8G8B8 version s32 *p = (s32*)texture->lock(); if (!p) { Printer::log("Could not lock texture for making normal map.", ELL_ERROR); return; } // copy texture u32 pitch = texture->getPitch() / 4; s32* in = new s32[dim.Height * pitch]; memcpy(in, p, dim.Height * pitch * 4); for (s32 x=0; x < s32(pitch); ++x) for (s32 y=0; y < s32(dim.Height); ++y) { // TODO: this could be optimized really a lot vector3df h1((x-1)*hh, nml32(x-1, y, pitch, dim.Height, in)*amplitude, y*vh); vector3df h2((x+1)*hh, nml32(x+1, y, pitch, dim.Height, in)*amplitude, y*vh); //vector3df v1(x*hh, nml32(x, y-1, pitch, dim.Height, in)*amplitude, (y-1)*vh); //vector3df v2(x*hh, nml32(x, y+1, pitch, dim.Height, in)*amplitude, (y+1)*vh); vector3df v1(x*hh, nml32(x, y+1, pitch, dim.Height, in)*amplitude, (y-1)*vh); vector3df v2(x*hh, nml32(x, y-1, pitch, dim.Height, in)*amplitude, (y+1)*vh); vector3df v = v1-v2; vector3df h = h1-h2; vector3df n = v.crossProduct(h); n.normalize(); n *= 0.5f; n += vector3df(0.5f,0.5f,0.5f); // now between 0 and 1 n *= 255.0f; s32 height = (s32)nml32(x, y, pitch, dim.Height, in); p[y*pitch + x] = SColor( height, // store height in alpha (s32)n.X, (s32)n.Z, (s32)n.Y).color; } delete [] in; texture->unlock(); } else { // ECF_A1R5G5B5 version s16 *p = (s16*)texture->lock(); if (!p) { Printer::log("Could not lock texture for making normal map.", ELL_ERROR); return; } u32 pitch = texture->getPitch() / 2; // copy texture s16* in = new s16[dim.Height * pitch]; memcpy(in, p, dim.Height * pitch * 2); for (s32 x=0; x < s32(pitch); ++x) for (s32 y=0; y < s32(dim.Height); ++y) { // TODO: this could be optimized really a lot vector3df h1((x-1)*hh, nml16(x-1, y, pitch, dim.Height, in)*amplitude, y*vh); vector3df h2((x+1)*hh, nml16(x+1, y, pitch, dim.Height, in)*amplitude, y*vh); vector3df v1(x*hh, nml16(x, y-1, pitch, dim.Height, in)*amplitude, (y-1)*vh); vector3df v2(x*hh, nml16(x, y+1, pitch, dim.Height, in)*amplitude, (y+1)*vh); vector3df v = v1-v2; vector3df h = h1-h2; vector3df n = v.crossProduct(h); n.normalize(); n *= 0.5f; n += vector3df(0.5f,0.5f,0.5f); // now between 0 and 1 n *= 255.0f; p[y*pitch + x] = RGBA16((u32)n.X, (u32)n.Z, (u32)n.Y); } delete [] in; texture->unlock(); } texture->regenerateMipMapLevels(); }
void Image::draw(int x, int y, int r, int g, int b, int a) { Video->draw2DImage(img, position2d<s32>(x,y), rect<s32>(0,0, w, h),0, SColor(a,r,g,b), true); }
void drawText(Font locFont, const wchar_t *text, int x, int y, int r, int g, int b, int a) { dimension2d<u32> size = locFont.font->getDimension(text); locFont.font->draw(text,rect<s32>(x,y, (x + size.Width),(y + size.Height)), SColor(a,r,g,b)); }
int main(int argc, const char** argv) { /* - deviceType: Type of the device. This can currently be the Null-device, one of the two software renderers, D3D8, D3D9, or OpenGL. In this example we use EDT_SOFTWARE, but to try out, you might want to change it to EDT_BURNINGSVIDEO, EDT_NULL, EDT_DIRECT3D8, EDT_DIRECT3D9, or EDT_OPENGL. */ MyEventReceiver receiver; ISoundEngine* music = createIrrKlangDevice(); IrrlichtDevice *device = createDevice( EDT_DIRECT3D9, dimension2d<u32>(640, 480), 32, false, false, false, &receiver); music->play2D("../media/MUSIC/Dark Impetus.mp3",true,false,true); IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); IGUIEnvironment* guienv = device->getGUIEnvironment(); ICameraSceneNode *camera = smgr->addCameraSceneNode(); IGUIFont* font = device->getGUIEnvironment()->getFont("../media/fonthaettenschweiler.bmp"); camera->setFarValue(900); IAnimatedMesh* map = smgr->getMesh(DC_01); IAnimatedMeshSceneNode* mapnode = smgr->addAnimatedMeshSceneNode(map); mapnode->setMaterialFlag(EMF_LIGHTING,false); IAnimatedMesh* player1 = smgr->getMesh(SORA); IAnimatedMeshSceneNode* p1node = smgr->addAnimatedMeshSceneNode(player1); p1node->setMaterialFlag(EMF_LIGHTING, false); p1node->setScale(SORA_VECTOR3D); IAnimatedMesh* player2 = smgr->getMesh(AQUA); IAnimatedMeshSceneNode* p2node = smgr->addAnimatedMeshSceneNode(player2); p2node->setMaterialFlag(EMF_LIGHTING, false); p2node->setScale(NORMAL_VECTOR3D); vector3df Position = p1node->getPosition(); vector3df P2Pos = p2node->getPosition(); vector3df PosCam = p1node->getPosition(); vector3df Rotate = p1node->getPosition(); int CurrentHP = 300; int MaxHP = 400; int HeartP = 10; bool LockOn = false; bool LockCheck = false; stringw CoorCheck; while(device->run()) { CoorCheck +=L"Your position\nX:"; CoorCheck +=Position.X; CoorCheck +=L"\nY:"; CoorCheck +=Position.Y; CoorCheck +=L"\nZ:"; CoorCheck +=Position.Z; CoorCheck +=L"\n\nTarget Position:"; CoorCheck +=P2Pos.X; if(LockCheck != true){ if(receiver.IsKeyDown(KEY_KEY_J)){LockOn = true; LockCheck = true;}} else{ if(receiver.IsKeyDown(KEY_KEY_J)){LockOn = false;LockCheck = false;}} //3D Rendering. MaximizeKey(receiver,device); GetCaption(driver,device); driver->beginScene(true, true, SColor(255,100,101,140)); p1node->setPosition(Position); camera->setPosition(vector3df(PosCam.X,PosCam.Y+2,PosCam.Z+3)); if(LockOn != false){camera->setTarget(P2Pos);} else{camera->setTarget(Position);} smgr->drawAll(); //2D Rendering. if(CurrentHP<=0){font->draw(L"You are dead!!!",rect<s32>(120,140,250,210),SColor(255,255,255,255));} else{if(receiver.IsKeyDown(KEY_KEY_L)){--CurrentHP;}} if(CurrentHP>=MaxHP){}else{if(receiver.IsKeyDown(KEY_KEY_K)){++CurrentHP;}} if(receiver.IsKeyDown(KEY_KEY_N)){++MaxHP;} if(receiver.IsKeyDown(KEY_KEY_M) && CurrentHP<MaxHP){--MaxHP;} if(HeartP>=86){}else{ if(receiver.IsKeyDown(KEY_KEY_F)){++HeartP;}} font->draw (L"Press O for full screen.\nPress Up-Down-Left-right to move.\nPress L to hurt the character.\nPress K to heal the character.\nPress N to increase Max HP.\nPress M to decrease Max HP.\nPress F to fill the Heart gauge.",rect<s32>(20,40,150,110),SColor(255,0,0,0)); font->draw(CoorCheck,rect<s32>(20,140,150,110),SColor(255,0,0,0)); //Button detection. if(receiver.IsKeyDown(KEY_UP)){ Position.Z -= 0.1f; PosCam.Z = Position.Z; p1node->setRotation(vector3df(Rotate.X,Rotate.Y = 0,Rotate.Z)); p1node->setPosition(Position);} if(receiver.IsKeyDown(KEY_DOWN)){ Position.Z += 0.1f; PosCam.Z = Position.Z; p1node->setRotation(vector3df(Rotate.X,Rotate.Y -180,Rotate.Z)); p1node->setPosition(Position);} if(receiver.IsKeyDown(KEY_LEFT)){ Position.X += 0.1f; PosCam.X = Position.X; p1node->setRotation(vector3df(Rotate.X,Rotate.Y -90,Rotate.Z)); p1node->setPosition(Position);} if(receiver.IsKeyDown(KEY_RIGHT)){ Position.X -= 0.1f; PosCam.X = Position.X; p1node->setRotation(vector3df(Rotate.X,Rotate.Y +90,Rotate.Z)); p1node->setPosition(Position);} HUD_Display(device,driver,receiver,font,CurrentHP,MaxHP,HeartP); guienv->drawAll(); CoorCheck = L""; driver->endScene(); } music->drop(); device->drop(); return 0; }
inline void SetS3DVertex(S3DVertex* v, f32 x1, f32 y1, f32 x2, f32 y2, f32 z, f32 nz, f32 tu1, f32 tv1, f32 tu2, f32 tv2) { v[0] = S3DVertex(x1, y1, z, 0, 0, nz, SColor(255, 255, 255, 255), tu1, tv1); v[1] = S3DVertex(x2, y1, z, 0, 0, nz, SColor(255, 255, 255, 255), tu2, tv1); v[2] = S3DVertex(x1, y2, z, 0, 0, nz, SColor(255, 255, 255, 255), tu1, tv2); v[3] = S3DVertex(x2, y2, z, 0, 0, nz, SColor(255, 255, 255, 255), tu2, tv2); }
void CRespawn::Render() { position2d<s32> pos; for ( int i = 0; i < points.size(); i++ ) { WideString wstr = "(S) "; wstr += points[i]->getActorName().c_str(); pos = IRR.smgr->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition( points[i]->getPosition(), IRR.smgr->getActiveCamera() ); IRR.gui->getBuiltInFont()->draw( wstr.c_str(), core::rect<s32>( pos.X, pos.Y, pos.X + 100, pos.Y + 50 ), irr::video::SColor( 255, 15, 85, 10 ), false, true ); } // draw 3d stuff IRR.video->setTransform( ETS_WORLD, matrix4() ); SMaterial m; m.Lighting = false; m.BackfaceCulling = false; IRR.video->setMaterial( m ); vector3df vP; for ( int i = 0; i < points.size(); i++ ) { vP = points[i]->getPosition(); IRR.video->draw3DBox( aabbox3df( vP - vector3df( points[i]->radius, points[i]->radius, points[i]->radius ), vP + vector3df( points[i]->radius, points[i]->radius, points[i]->radius ) ), SColor( 255, 105, 22, 90 ) ); } }
void PhysicsSim::view(Camera* cam, RenderTarget* pipTarget) { //if (dvc->isWindowActive()) //{ updatePhysics(); //* driver->beginScene(true, true, SColor(255,255,255,255)); for(unsigned int i = 0; i < render_targets.size(); i++) render_targets[i]->drawAll(); driver->setRenderTarget(0, true, true, 0); smgr->setActiveCamera(cam); smgr->drawAll(); if(pipTarget != NULL) { pipImage->setImage(pipTarget->target); } driver->setTransform(video::ETS_WORLD, core::IdentityMatrix); for(uint i = 0; i < lines.size(); i++) drawLine(lines[i].p1, lines[i].p2, lines[i].color); lines.clear(); for(uint i = 0; i < boxes.size(); i++) driver->draw3DBox(boxes[i].box, boxes[i].color) ; boxes.clear(); for(uint i = 0; i < images.size(); i++) { ITexture* tex = driver->getTexture(images[i].name); Dimension dim = tex->getOriginalSize(); driver->draw2DImage(tex, images[i].position, rect<s32>(0,0,dim.Width,dim.Height),0, video::SColor(255,255,255,255), true); } images.clear(); for(uint i = 0; i < texts.size(); i++) { this->font = NULL; if(texts[i].size == 0) this->font = env->getBuiltInFont(); else if(texts[i].size == 1) this->font = env->getFont(mediaDirectory + "fontcourier.bmp"); else this->font = env->getFont(mediaDirectory + "bigfont.png"); if(!this->font) this->font = env->getBuiltInFont(); Dimension dim = this->font->getDimension(texts[i].text.c_str()); this->font->draw(texts[i].text, rect<s32>(texts[i].position.X,texts[i].position.Y,texts[i].position.X+dim.Width,texts[i].position.Y+dim.Height), texts[i].color); } texts.clear(); env->drawAll(); driver->endScene(); for(uint i = 0; i < arrows.size(); i++) { smgr->getMeshCache()->removeMesh(arrows[i]->getMesh()); arrows[i]->remove(); } arrows.clear(); //*/ //} //else // dvc->yield(); }
// render // override render state void CGameAnimatedMeshSceneNode::render() { #ifdef GSEDITOR CGameObject::EObjectState state = m_owner->getObjectState(); // draw bbox on select if ( state == CGameObject::Move || state == CGameObject::Review ) setDebugDataVisible( EDS_BBOX ); else setDebugDataVisible( 0 ); // call object draw m_owner->drawObject(); #endif // draw animesh CAnimatedMeshSceneNode::render(); #ifdef GSANIMATION // get driver IVideoDriver* driver = getSceneManager()->getVideoDriver(); ISkinnedMesh *mesh = (ISkinnedMesh*)getMesh(); IView *pView = getIView(); irr::gui::IGUIFont* font = getSceneManager()->getGUIEnvironment()->getBuiltInFont(); video::SMaterial debug_mat; debug_mat.Lighting = false; debug_mat.AntiAliasing = 0; debug_mat.ZBuffer = video::ECFN_NEVER; for (u32 g=0; g < mesh->getAllJoints().size(); ++g) { ISkinnedMesh::SJoint *joint = mesh->getAllJoints()[g]; core::vector3df v; //basic bone //core::matrix4 mat1 = joint->GlobalInversedMatrix; //mat1.makeInverse(); //anim bone core::matrix4 mat1 = joint->GlobalAnimatedMatrix; // get position mat1.transformVect( v ); // scale with character v *= m_owner->getScale(); // draw name bone on screen int x, y; pView->getScreenCoordinatesFrom3DPosition( v, &x, &y ); wchar_t text[1024]; uiString::copy<wchar_t, const c8>( text, joint->Name.c_str() ); // draw bone position SColor c = SColor(255,0,0,255); driver->setMaterial(debug_mat); driver->draw2DRectangle( c, core::rect<s32>( x - 2, y - 2, x + 2, y + 2 ) ); // draw text font->draw( text, core::rect<s32>( x + 10, y, x + 100, y + 50), SColor(255, 255,255,0) ); } #endif #ifdef GSEDITOR // draw move if ( state == CGameObject::Move || state == CGameObject::Rotation || state == CGameObject::Scale ) m_owner->drawFrontUpLeftVector(); if ( state == CGameObject::Rotation ) m_owner->drawCircleAroundObject(); #endif }
// ---------------------------------------------------------------------------- void RoadCrossSectionWndw::init() { m_sym_mode = false; m_allign = false; m_grid_on = true; m_grid = 0.25; m_rt = 0; Editor* editor = Editor::getEditor(); IGUIEnvironment* gui_env = editor->getGUIEnv(); m_smgr = editor->getSceneManager(); m_driver = editor->getVideoDriver(); path icons = editor->getIconsLoc(); dimension2du ss = Editor::getEditor()->getScreenSize(); ICameraSceneNode* c = m_smgr->getActiveCamera(); m_cam = m_smgr->addCameraSceneNode(0, vector3df(m_offset - 1, 0, 5), vector3df(m_offset - 1, 0, 0)); m_cam->setID(1); matrix4 mat; f32 nv = m_cam->getNearValue(); f32 fv = m_cam->getFarValue(); f32 hVol = 10.0f * ss.Height / ss.Width; mat.buildProjectionMatrixOrthoLH(10, hVol, nv, fv); m_cam->setProjectionMatrix(mat, true); m_smgr->setActiveCamera(c); m_nodes = 0; m_visible = false; m_center_node = m_smgr->addSphereSceneNode(0.02f); m_center_node->setID(1); m_center_node->setPosition(vector3df((f32)m_offset, 0, 0)); m_center_node->getMaterial(0).DiffuseColor = SColor(255, 0, 255, 0); m_center_node->getMaterial(0).AmbientColor = SColor(255, 0, 255, 0); m_center_node->setVisible(false); f32 dx = (ss.Width - 300 - 8 * 50) / 9.0f; f32 x = 25 + dx; s32 h = ss.Height; m_gof = gui_env->addButton(rect<s32>((s32)x,h - 100, (s32)x+50, h-50)); x += dx + 50; m_gp = gui_env->addButton(rect<s32>((s32)x,h - 100, (s32)x+50, h-50)); x += dx + 50; m_gm = gui_env->addButton(rect<s32>((s32)x,h - 100, (s32)x+50, h-50)); x += dx + 50; m_pp = gui_env->addButton(rect<s32>((s32)x,h - 100, (s32)x+50, h-50)); x += dx + 50; m_pm = gui_env->addButton(rect<s32>((s32)x,h - 100, (s32)x+50, h-50)); x += dx + 50; m_sym = gui_env->addButton(rect<s32>((s32)x,h - 100, (s32)x+50, h-50)); x += dx + 50; m_ok = gui_env->addButton(rect<s32>((s32)x,h - 100, (s32)x+50, h-50)); x += dx + 50; m_cancel = gui_env->addButton(rect<s32>((s32)x,h - 100, (s32)x+50, h-50)); x += dx + 50; m_gof ->setImage(Editor::loadImg(icons + "grid-on_align-off.png")); m_gp ->setImage(Editor::loadImg(icons + "grid-plus.png")); m_gm ->setImage(Editor::loadImg(icons + "grid-minus.png")); m_pp ->setImage(Editor::loadImg(icons + "points-plus.png")); m_pm ->setImage(Editor::loadImg(icons + "points-minus.png")); m_sym ->setImage(Editor::loadImg(icons + "symm_off.png")); m_ok ->setImage(Editor::loadImg(icons + "qsave.png")); m_cancel ->setImage(Editor::loadImg(icons + "qcancel.png")); m_gof ->setID(GRID_ON_OFF); m_gp ->setID(GRID_P ); m_gm ->setID(GRID_M ); m_pp ->setID(POINT_P ); m_pm ->setID(POINT_M ); m_sym ->setID(SYM_ON_OFF ); m_ok ->setID(OK ); m_cancel ->setID(CANCEL ); m_gof ->setVisible(false); m_gp ->setVisible(false); m_gm ->setVisible(false); m_pp ->setVisible(false); m_pm ->setVisible(false); m_sym ->setVisible(false); m_ok ->setVisible(false); m_cancel ->setVisible(false); m_gof ->setToolTipText(_(L"Grid on alignment on")); m_gp ->setToolTipText(_(L"Increase grid density")); m_gm ->setToolTipText(_(L"Decrease grid density")); m_pp ->setToolTipText(_(L"Add 4 points")); m_pm ->setToolTipText(_(L"Remove 4 points")); m_sym ->setToolTipText(_(L"Click to turn on symmetry")); m_ok ->setToolTipText(_(L"Save and Leave")); m_cancel ->setToolTipText(_(L"Leave without save")); } // init
void CPlayer::createPlayerGUI(bool bHSplit, const wchar_t *sName, u32 iCheckpoints) { dimension2du cScreenSize=m_pDevice->getVideoDriver()->getScreenSize(); position2di pos; IVideoDriver *pDriver=m_pDevice->getVideoDriver(); IGUIEnvironment *pGuienv=m_pDevice->getGUIEnvironment(); if (m_iNum==1 || m_bNetClient) { pos.X=37; pos.Y=(bHSplit || m_bNetClient)?cScreenSize.Height-42:cScreenSize.Height/2-42; } else { //m_kinectJoystick->setVisible(false); //if two players don't show joystick pos.X=bHSplit?cScreenSize.Width-237:37; pos.Y=cScreenSize.Height-42; m_kinectJoystick->plyerNo=2; //HACK } m_pName=pGuienv->addStaticText(sName,rect<s32>(pos.X,pos.Y,pos.X+200,pos.Y+32)); m_pName->setDrawBackground(true); m_pName->setOverrideColor(SColor(255,255,118,70)); m_pName->setOverrideFont(m_pBigFont); m_pName->setBackgroundColor(SColor(128,16,16,16)); m_pName->setTextAlignment(EGUIA_CENTER,EGUIA_CENTER); if (bHSplit) pos=position2di(m_iNum==1 || m_bNetClient?5:cScreenSize.Width-37,cScreenSize.Height-42); else pos=position2di(5,m_iNum==1 && !m_bNetClient?cScreenSize.Height/2-42:cScreenSize.Height-42); m_pCamMode=pGuienv->addImage(pDriver->getTexture("data/freecam.png"),pos); m_pCamFree=pDriver->getTexture("data/freecam.png"); m_pCamRace=pDriver->getTexture("data/racecam.png"); m_pCpOk =pDriver->getTexture("data/checkpoint_ok.png" ); m_pCpNok=pDriver->getTexture("data/checkpoint_nok.png"); if (bHSplit || m_bNetClient) pos=position2di(m_iNum==1 || m_bNetClient?5:cScreenSize.Width-265,12); else pos=position2di(5,m_iNum==1 || m_bNetClient?12:cScreenSize.Height/2+17); ITexture *img=pDriver->getTexture("data/checkpoint.png"); m_pSpeed=pGuienv->addImage(img,pos); m_pInfo=pGuienv->addStaticText(L"Hello World!",rect<s32>(pos.X+15,pos.Y+7,pos.X+245,pos.Y+30)); pos=position2di(m_iNum==1 || m_bNetClient?5:bHSplit?cScreenSize.Width-22:5,bHSplit?56:m_iNum==1 || m_bNetClient?56:cScreenSize.Height/2+61); for (u32 i=0; i<iCheckpoints; i++) { IGUIImage *pCp=pGuienv->addImage(m_pCpNok,pos); pos.Y+=22; m_aCpState.push_back(pCp); } if (bHSplit || m_bNetClient) pos=position2di(m_iNum==1 || m_bNetClient?39:cScreenSize.Width-255,56); else pos=position2di(35,m_iNum==1 || m_bNetClient?56:cScreenSize.Height/2+61); m_pCpInfo=pGuienv->addTab(rect<s32>(pos.X,pos.Y,pos.X+215,pos.Y+60)); m_pCpInfo->setBackgroundColor(SColor(128,192,192,192)); m_pCpInfo->setDrawBackground(true); m_pCpInfo->setToolTipText(L"Checkpoint Info"); pGuienv->addImage(pDriver->getTexture("data/cp_done.png"),position2di(5,5),true,m_pCpInfo); m_pCpTime=pGuienv->addStaticText(L"Cp_time",rect<s32>(5,40,205,60),false,true,m_pCpInfo); m_pCpInfo->setVisible(false); pos.Y+=10; if (m_iNum!=1 && !m_bNetClient && bHSplit) { pos.X=cScreenSize.Width-190; } pos=position2di(m_iNum==1 || m_bNetClient?30:bHSplit?cScreenSize.Width-240:50,bHSplit?56:m_iNum==1 || m_bNetClient?56:cScreenSize.Height/2+61); m_pLapTab=pGuienv->addTab(rect<s32>(pos.X,pos.Y,pos.X+200,pos.Y+55)); m_pLapTab->setVisible(false); m_pLapTab->setToolTipText(L"Lap Info"); pos=position2di(5,5); ITexture *tex=pDriver->getTexture("data/lap.png"); m_pLap=pGuienv->addImage(pDriver->getTexture("data/lap.png"),pos,true,m_pLapTab); pos.X+=tex->getSize().Width+5; for (u32 j=0; j<5; j++) { IGUIImage *pImg=pGuienv->addImage(m_aNumbers[11],pos,true,m_pLapTab); m_aLapNo.push_back(pImg); pos.X+=26; } pos.X=(!bHSplit || m_iNum==1 || m_bNetClient)? 30:cScreenSize.Width -136; pos.Y=( bHSplit || m_iNum==1 || m_bNetClient)?130:cScreenSize.Height/2+140; m_pFinished=pGuienv->addImage(pDriver->getTexture("data/finished.png"),pos); m_pFinished->setVisible(false); m_pFinished->setToolTipText(L"Finished"); }
vector<vector3df> Editor::startEditor(){ myRecEditor->startEventProcess(); #ifdef EDITOR_VIEW myRecEditorView->startEventProcess(); #endif bool leftPress = false; mouseWheelCurr = 0; double value = 0; CAMPOSX = 0; CAMPOSY = 0; CAMPOSZ = CAM_POS_DEFAULT; while (deviceEditor->run()) { mouseWheelCurr = (int)(myRecEditor->mouseWheel()*1.29); if (currentEksen == EKSEN_X) X = mouseWheelCurr; else X = myRecEditor->mouseX() - EDITOR_HALF_SCREEN_SIZE; if (currentEksen == EKSEN_Y) Y = mouseWheelCurr; else{ Y = (EDITOR_HALF_SCREEN_SIZE - myRecEditor->mouseY()); } if (currentEksen == EKSEN_X) Z = (myRecEditor->mouseX() - EDITOR_HALF_SCREEN_SIZE); else if (currentEksen == EKSEN_Y) Z = EDITOR_HALF_SCREEN_SIZE - myRecEditor->mouseY(); else Z = mouseWheelCurr; driverEditor->beginScene(true, true, SColor(204, 204, 204, 204)); #ifdef EDITOR_VIEW driverEditorView->beginScene(true, true, SColor(204, 204, 204, 204)); #endif cameraCalibration(myRecEditor, editorCam); if (myRecEditor->keyDown(KEY_KEY_W)){ // .... EVENT HANDLERS .... currentEksen = EKSEN_Y; deviceEditor->setWindowCaption(L"Editor Platform X - Z Ekseni "); editorParentNode->setRotation(vector3df(((int)(editorParentNode->getRotation().X + NODE_ROTATION_SPEED)) % ROTATION_LIMIT, 0, 0)); } else if (myRecEditor->keyDown(KEY_KEY_S)){ currentEksen = EKSEN_Z; deviceEditor->setWindowCaption(L"Editor Platform X - Y Ekseni "); editorCam->setPosition(vector3df(0, 0, CAM_POS_DEFAULT + (mouseWheelCurr * CAM_POS_INC))); editorParentNode->setRotation(vector3df(0, 0, 0)); CAMPOSX = 0; CAMPOSY = 0; CAMPOSZ = CAM_POS_DEFAULT; } else if (myRecEditor->keyDown(KEY_KEY_A)){ currentEksen = EKSEN_X; deviceEditor->setWindowCaption(L"Editor Platform Y - Z Ekseni "); editorParentNode->setRotation(vector3df(0, ((int)(editorParentNode->getRotation().Y + NODE_ROTATION_SPEED)) % ROTATION_LIMIT, 0)); } else if (myRecEditor->keyDown(KEY_KEY_D)){ currentEksen = EKSEN_Z; deviceEditor->setWindowCaption(L"Editor Platform X - Y Ekseni "); editorParentNode->setRotation(vector3df(0, 0, ((int)(editorParentNode->getRotation().Z + NODE_ROTATION_SPEED)) % ROTATION_LIMIT)); } else if (myRecEditor->keyDown(KEY_KEY_P)) { stopEditor(); } if (myRecEditor->leftMousePressed()){ if (!leftPress) vFirst = vLast; // Clear Buffer. drawLine(); leftPress = true; } if (myRecEditor->leftMouseReleased()){ if (leftPress){ vFirst = vLast; // Clear buffer. leftPress = false; } } if (myRecEditor->rightMouseDown()){ drawLine(); } if (myRecEditor->keyDown(KEY_KEY_C)) { positionNodes.clear(); smgrEditor->clear(); editorParentNode = smgrEditor->addEmptySceneNode(); editorParentNode->setVisible(true); editorChildNode = smgrEditor->addSphereSceneNode(); nodeEditorCurrMouse = editorChildNode->clone(); if (nodeEditorCurrMouse && editorChildNode){ editorParentNode->setVisible(true); editorChildNode->setMaterialFlag(EMF_LIGHTING, false); editorChildNode->setScale(editorChildNode->getScale()*0.60f); #if defined(_WIN32) || defined(_WIN64) editorChildNode->setMaterialTexture(0, driverEditor->getTexture("media/blueTexture.png")); #else editorChildNode->setMaterialTexture(0, driverEditor->getTexture("../media/blueTexture.png")); #endif editorChildNode->setVisible(false); nodeEditorCurrMouse->setMaterialFlag(EMF_LIGHTING, false); #if defined(_WIN32) || defined(_WIN64) nodeEditorCurrMouse->setMaterialTexture(0, driverEditor->getTexture("media/redTexture.png")); #else nodeEditorCurrMouse->setMaterialTexture(0, driverEditor->getTexture("../media/redTexture.png")); #endif nodeEditorCurrMouse->setVisible(true); nodeEditorCurrMouse->setScale(nodeEditorCurrMouse->getScale()*1.3f); } // add camera editorCam = smgrEditor->addCameraSceneNode(0, vector3df(0, 0, CAM_POS_DEFAULT), vector3df(0, 0, -CAM_POS_DEFAULT)); X = 0; Y = 0; Z = 0; // camera View .. currentEksen = EKSEN_Z; editorParentNode->addChild(nodeEditorCurrMouse); deviceEditor->getCursorControl()->setVisible(false); // Unvisible mouse cursor mouseWheelBefore = 0; // mouse depth value set 0. smgrEditor->setActiveCamera(editorCam); } drawEditorFrame(driverEditor); driverEditor->draw3DLine(vector3df(-EDITOR_SCREEN_WIDTH, 0, 0), vector3df(EDITOR_SCREEN_WIDTH, 0, 0), SColor(255, 0, 255, 0)); driverEditor->draw3DLine(vector3df(0, -EDITOR_SCREEN_WIDTH, 0), vector3df(0, EDITOR_SCREEN_WIDTH, 0), SColor(255, 255, 0, 0)); driverEditor->draw3DLine(vector3df(0, 0, -EDITOR_SCREEN_WIDTH), vector3df(0, 0, EDITOR_SCREEN_WIDTH), SColor(0, 0, 0, 0)); /* Current node will be painted on editor */ nodeEditorCurrMouse->setPosition(vector3df(X, Y, Z)); #ifdef EDITOR_VIEW nodeEditorViewCurrMouse->setPosition(vector3df(X, Y, Z)); handleCameraDevice2(myRecEditorView, editorViewCam, eBoxEditorView, editorViewParentNode); #endif snprintf(stringEditorHelper, 100, "X: %d Y: %d Z: %d ", X, Y, Z); mbstowcs(stringEditor, stringEditorHelper, (size_t)100); eBoxEditor->setText(stringEditor); guienvEditor->drawAll(); smgrEditor->drawAll(); driverEditor->endScene(); #ifdef EDITOR_VIEW smgrEditorView->drawAll(); guienvEditorView->drawAll(); driverEditorView->endScene(); #endif } return positionNodes; }
void Entity::addBoxEmitter(vector3df boxDim, vector3df dir, vector2df pps, vector2df size, vector2df life, f32 angle) { if(type != PARTICLE_SYS_TYPE) return; vector3df globPos = pSys->getAbsolutePosition(); boxDim /= 2; pSys->setEmitter(pSys->createBoxEmitter(aabbox3df(globPos.X - boxDim.X, globPos.Y - boxDim.Y, globPos.Z - boxDim.Z, globPos.X + boxDim.X, globPos.Y + boxDim.Y, globPos.Z + boxDim.Z), dir, pps.X, pps.Y, SColor(255, 0, 0, 0), SColor(255, 255, 255, 255), life.X, life.Y, angle, dimension2df(size.X, size.X), dimension2df(size.Y, size.Y))); }
SetUnSaved(); } void VectorSimulation::ChangeSelectedVectors(wxArrayInt vectorIndexes) { //Deselect currently selected arrows foreach(int, selectedIt, selectedVectorsIndexes) { arrowVertices[selectedIt->GetData()*4].Color = vectorColor; arrowVertices[selectedIt->GetData()*4 + 1].Color = vectorColor; arrowVertices[selectedIt->GetData()*4 + 2].Color = vectorColor; arrowVertices[selectedIt->GetData()*4 + 3].Color = vectorColor; } selectedVectorsIndexes->Clear(); SColor newColor = SColor(255, 255, 255, 0); for(unsigned int i = 0; i < vectorIndexes.size(); i++) { arrowVertices[vectorIndexes[i]*4].Color = newColor; arrowVertices[vectorIndexes[i]*4 + 1].Color = newColor; arrowVertices[vectorIndexes[i]*4 + 2].Color = newColor; arrowVertices[vectorIndexes[i]*4 + 3].Color = newColor; selectedVectorsIndexes->Add(vectorIndexes[i]); } } Vector3 VectorSimulation::GetUnitVector(int arrowNumber) { Vector3 direction = arrowVertices[arrowNumber*4+1].Pos - arrowVertices[arrowNumber*4].Pos;
void Station::drawTexture() { this->_vidDriver->draw2DImage(this->_stationTexture, position2d<s32>(0,0),rect<s32>(0,0,1280,720),0,SColor(255,255,255,255),true); }
int main() { SIrrlichtCreationParameters pars; pars.DriverType=EDT_OPENGL; pars.WindowSize=dimension2d<s32>(800,600); pars.Bits=32; pars.AntiAlias=true; pars.Stencilbuffer=true; pars.Doublebuffer = true; pars.Fullscreen=false; pars.Vsync=false; pars.EventReceiver=&receiver; device = createDeviceEx(pars); //device = createDevice(EDT_OPENGL, dimension2d<u32>(800, 600), 32, false, false, false, &receiver); if (!device) return 1; driver = device->getVideoDriver(); driver->setTextureCreationFlag(ETCF_ALWAYS_32_BIT, true); smgr = device->getSceneManager(); smgr->setShadowColor(SColor(127,0,0,0)); load_map(); load_player(); int fps = 0; int prev_fps = -1; stringw the_title; camera = smgr->addCameraSceneNode();//FPS(); camera->setPosition(vector3df(-50,50,-150)); device->getCursorControl()->setVisible(false); then = device->getTimer()->getTime(); while(device->run()) { now = device->getTimer()->getTime(); //check_input(); then = now; driver->beginScene(true, true, SColor(255, 255, 255, 255)); smgr->drawAll(); driver->endScene(); fps = driver->getFPS(); if (fps != prev_fps) { the_title = L"The Game | "; the_title += driver->getName(); the_title += " | FPS:"; the_title += fps; device->setWindowCaption(the_title.c_str()); } } device->drop(); return 0; }
void loop_ctr(s4 &game_state) { ISceneNode* empty_node = irrlicht->smgr->addEmptySceneNode(); empty_node->setPosition(vector3df(0,0,0)); ICameraSceneNode* camera = irrlicht->smgr->addCameraSceneNode(); camera->setPosition({0,-250,-100}); camera->setUpVector({0,0,-1}); camera->setTarget({0,0,0}); camera->setParent(empty_node); camera->setFOV(70); irrlicht->device->getCursorControl()->setVisible(false); irrlicht->smgr->setAmbientLight(SColorf(1,1,1,1)); irrlicht->hud = irrlicht->smgr->createNewSceneManager(false); ICameraSceneNode* hud_camera = irrlicht->hud->addCameraSceneNode(); matrix4 ortho; ortho.buildProjectionMatrixOrthoLH( irrlicht->driver->getScreenSize().Width/ortho_scale, irrlicht->driver->getScreenSize().Height/ortho_scale,-1.0,1000.0); hud_camera->setProjectionMatrix(ortho); hud_camera->setPosition({0,0,-100}); hud_camera->setTarget({0,0,0}); // temp objects ---------------------------------- blist cmpnt_list, joint_list, tree_list; b_set(cmpnt_list,memory,sizeof(Component)); b_set(joint_list,memory,sizeof(Joint)); b_set(tree_list,memory,sizeof(CTree)); irr::core::map<ISceneNode*,Component*> node_cmpnt_map; ISceneNode* ctr_parent = irrlicht->smgr->addEmptySceneNode(); IMesh* cube_mesh = irrlicht->smgr->getGeometryCreator()->createCubeMesh(); auto add_object_to_world = [&] (vec3 pos, vec3 scale, s4 a, s4 r, s4 g, s4 b) -> Component* { const f4 floor_position = 10.0f; Component make_cmpnt; make_cmpnt.id = CMPNT_ID; CMPNT_ID++; make_cmpnt.node = irrlicht->smgr->addMeshSceneNode(cube_mesh,ctr_parent); make_cmpnt.node->setPosition(pos.irr()); make_cmpnt.node->setScale(scale.irr()); make_cmpnt.node->getMaterial(0).AmbientColor.set(a,r,g,b); make_cmpnt.shadow = irrlicht->smgr->addMeshSceneNode(cube_mesh,0); make_cmpnt.shadow->setScale({scale.x, scale.y, 0.1f}); make_cmpnt.shadow->setPosition({pos.x, pos.y,floor_position}); make_cmpnt.shadow->getMaterial(0).AmbientColor.set(GREY_BLUE_SHADOW); for (s4 i = 0; i < MAX_JOINTS; i++) make_cmpnt.joints[i] = 0; make_cmpnt.tree = 0; b_copy(cmpnt_list,&make_cmpnt); node_cmpnt_map.insert(make_cmpnt.node, (Component*)blast_address(cmpnt_list) ); return (Component*)blast_address(cmpnt_list); }; auto add_joint = [&] (Component* A, Component* B, vec3 posA, vec3 posB) { Joint C; C.A = A; C.posA = A->node->getTransformedBoundingBox().getExtent() * A->node->getScale(); C.posA *= (posA * 0.5f); C.B = B; C.posB = B->node->getTransformedBoundingBox().getExtent() * B->node->getScale(); C.posB *= (posB * 0.5f); C.type = Joint::SNAP; C.is_connected = false; b_copy(joint_list,&C); for (s4 i = 0; i < MAX_JOINTS; i++) { if (C.A->joints[i] == 0) { C.A->joints[i] = (Joint*)blast_address(joint_list); break; } else if (i == MAX_JOINTS-1) { std::cout << "ERROR: Joint could not be added to C.A." << std::endl; } } for (s4 i = 0; i < MAX_JOINTS; i++) { if (C.B->joints[i] == 0) { C.B->joints[i] = (Joint*)blast_address(joint_list); break; } else if (i == MAX_JOINTS-1) { std::cout << "ERROR: Joint could not be added to C.B." << std::endl; } } }; { Component* A = add_object_to_world(vec3(0,30,-20),vec3(3,3,3),BLUE_LIGHT); Component* B = add_object_to_world(vec3(0,60,-20),vec3(9,3,2),BLACK); add_joint(A,B,vec3(0.0f,0.0f,1.0f),vec3(0.0f,0.0f,-1.0f)); Component* C = add_object_to_world(vec3(0,-90,-20),vec3(3,3,3),YELLOW_LIGHT); Component* D = add_object_to_world(vec3(0,-40,-20),vec3(8,10,4),GREEN_LIGHT); add_joint(C,D,vec3(0.0f,1.0f,0.0f),vec3(0.0f,-1.0f,0.0f)); add_joint(A,D,vec3(0.0f,0.0f,-1.0f),vec3(0.0f,0.0f,1.0f)); } // temp objects ---------------------------------- SimpleNodeEditor* sneditor = simple_node_editor_init(); sneditor->root_node = ctr_parent; f4 target_z_rotation = empty_node->getRotation().Z; p("---- Game loop start ----"); f4 dt = 0.0f; const f4 maxDelta = 1.0f/60.0f * 5.0f; const f4 tick_ms = 0.01666f; f4 render_dt = 0.0f; const f4 render_ms = 0.016667f; u4 time_physics_prev = btclock->getTimeMicroseconds(); while(irrlicht->device->run() && game_state == GAME_STATE_PLAY) { const u4 time_physics_curr = btclock->getTimeMicroseconds(); const f4 frameTime = ((f4)(time_physics_curr - time_physics_prev)) / 1000000.0; // todo: is this truncated correctly? time_physics_prev = time_physics_curr; f4 capped_dt = frameTime; if (capped_dt > maxDelta) { capped_dt = maxDelta; } render_dt += capped_dt; if ( render_dt >= render_ms ) { render_dt = 0.0f; f4 curr_rotation = empty_node->getRotation().Z; if (curr_rotation != target_z_rotation) { weighted_average(curr_rotation,target_z_rotation, 20.0f); if (curr_rotation >= 360.0f) { curr_rotation -= 360.0f; target_z_rotation -= 360.0f; } else if (curr_rotation < 0) { curr_rotation += 360.0f; target_z_rotation += 360.0f; } empty_node->setRotation({0,0,curr_rotation}); } if (sneditor->selected_node) { position2d<s32> screen_coord = irrlicht->colmgr->getScreenCoordinatesFrom3DPosition(sneditor->selected_node->getPosition(), camera); sneditor->hand_icon->setPosition({(screen_coord.X - (SCREEN_WIDTH/2)) / ortho_scale, (screen_coord.Y - (SCREEN_HEIGHT/2)) / -ortho_scale,0}); } else { sneditor->hand_icon->setPosition({(sneditor->cursor->getPosition().X - (SCREEN_WIDTH/2)) / ortho_scale, (sneditor->cursor->getPosition().Y - (SCREEN_HEIGHT/2)) / -ortho_scale,0}); } // Render irrlicht->driver->beginScene(true, true, SColor(GREY_BLUE)); irrlicht->smgr->drawAll(); irrlicht->driver->clearZBuffer(); irrlicht->hud->drawAll(); irrlicht->driver->endScene(); } dt += capped_dt; while( dt >= tick_ms ) { dt -= tick_ms; receiver->input(); if (receiver->a.state) target_z_rotation -= 90.0f; if (receiver->d.state) target_z_rotation += 90.0f; simple_node_editor_update( sneditor, receiver->mouse.left.state, receiver->mouse.left.released, receiver->mouse.right.state, false, receiver->tab.state, camera, &node_cmpnt_map); // TODO: Change this to: // - only test what the user is holding // - and only if the user is holding the smaller inserting part. // example: holding a screw in a large box bloop(joint_list, i) { Joint* c = (Joint*)b_get_mem_address(joint_list,i); if (c->A->tree != sneditor->selected_tree && c->B->tree != sneditor->selected_tree ) { continue; } if (!c->is_connected) { vec3 A = c->A->node->getPosition(); vec3 B = c->B->node->getPosition(); A += c->posA; B += c->posB; if (A.distance(B) < 13 /* && receiver->spacebar*/) { std::cout << "Comparing " << i << std::endl; c->is_connected = true; connect_joints(c,sneditor,camera,tree_list); } } } bloop(tree_list, i) { CTree* tree = (CTree*)b_get_mem_address(tree_list,i); if (tree->translation == vec3(0,0,0)) { continue; } for (s4 k = 0; k < tree->child_list.length;k++) { Component* cmpnt = (Component*)b_get_value(tree->child_list,k); cmpnt->node->setPosition(cmpnt->node->getPosition() + tree->translation.irr()); cmpnt->shadow->setPosition(cmpnt->node->getPosition() * vector3df(1,1,0) + vector3df(0,0,10)); } tree->translation = vec3(0,0,0); } if (receiver->restart.state) { game_state = GAME_STATE_RESET; } if (receiver->QUIT) { game_state = GAME_STATE_QUIT; } }
void IrrDriver::renderGlow(std::vector<GlowData>& glows) { m_scene_manager->setCurrentRendertime(scene::ESNRP_SOLID); m_rtts->getFBO(FBO_TMP1_WITH_DS).bind(); glClearStencil(0); glClearColor(0, 0, 0, 0); glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); const u32 glowcount = (int)glows.size(); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); glStencilFunc(GL_ALWAYS, 1, ~0); glEnable(GL_STENCIL_TEST); glEnable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); glDisable(GL_BLEND); if (CVS->isARBBaseInstanceUsable()) glBindVertexArray(VAOManager::getInstance()->getVAO(EVT_STANDARD)); for (u32 i = 0; i < glowcount; i++) { const GlowData &dat = glows[i]; scene::ISceneNode * cur = dat.node; STKMeshSceneNode *node = static_cast<STKMeshSceneNode *>(cur); node->setGlowColors(SColor(0, (unsigned) (dat.b * 255.f), (unsigned)(dat.g * 255.f), (unsigned)(dat.r * 255.f))); if (!CVS->supportsIndirectInstancingRendering()) node->render(); } if (CVS->supportsIndirectInstancingRendering()) { glBindBuffer(GL_DRAW_INDIRECT_BUFFER, GlowPassCmd::getInstance()->drawindirectcmd); InstancedColorizeShader::getInstance()->use(); glBindVertexArray(VAOManager::getInstance()->getInstanceVAO(video::EVT_STANDARD, InstanceTypeGlow)); if (CVS->isAZDOEnabled()) { if (GlowPassCmd::getInstance()->Size) { glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, (const void*)(GlowPassCmd::getInstance()->Offset * sizeof(DrawElementsIndirectCommand)), (int)GlowPassCmd::getInstance()->Size, sizeof(DrawElementsIndirectCommand)); } } else { for (unsigned i = 0; i < ListInstancedGlow::getInstance()->size(); i++) glDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, (const void*)((GlowPassCmd::getInstance()->Offset + i) * sizeof(DrawElementsIndirectCommand))); } } glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glDisable(GL_STENCIL_TEST); glDisable(GL_BLEND); // To half FrameBuffer::Blit(irr_driver->getFBO(FBO_TMP1_WITH_DS), irr_driver->getFBO(FBO_HALF1), GL_COLOR_BUFFER_BIT, GL_LINEAR); // To quarter FrameBuffer::Blit(irr_driver->getFBO(FBO_HALF1), irr_driver->getFBO(FBO_QUARTER1), GL_COLOR_BUFFER_BIT, GL_LINEAR); glEnable(GL_BLEND); glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glStencilFunc(GL_EQUAL, 0, ~0); glEnable(GL_STENCIL_TEST); m_rtts->getFBO(FBO_COLORS).bind(); m_post_processing->renderGlow(m_rtts->getRenderTarget(RTT_QUARTER1)); glDisable(GL_STENCIL_TEST); }
static inline SColor GetSpeedModColor(const float& m) { SColor col(120, 0, 80); if (m > 0.0f) { col.r = 255 - ((m <= 1.0f) ? (m * 255) : 255); col.g = 255 - col.r; col.b = 0; } return col; } static const SColor buildColors[] = { SColor(138, 138, 138), // nolos SColor( 0, 210, 0), // free SColor(190, 180, 0), // objblocked SColor(210, 0, 0), // terrainblocked }; static inline const SColor& GetBuildColor(const DefaultPathDrawer::BuildSquareStatus& status) { return buildColors[status]; } DefaultPathDrawer::DefaultPathDrawer() { pm = dynamic_cast<CPathManager*>(pathManager); }
int main() { int idCenario = 0; int quadId; vector3df p1, p2, p3, p4; SMatrix mtxCenario; CArquivoMatrizes *_fileMtx = new CArquivoMatrizes(); CSampleSceneNode *myQuad[2500]; CGerEventos eventos; IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<s32>(800, 600), 16, false,false,false, &eventos); device->setWindowCaption(L"Editor de matrizes - Warbugs"); IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); smgr->addCameraSceneNodeFPS(); //smgr->addCameraSceneNode(0, vector3df(0,100,0), vector3df(0,0,0)); smgr->loadScene(pathCenario[idCenario]); mtxCenario = _fileMtx->getMatrix(idCenario); ITerrainSceneNode *sceneTerrain = (ITerrainSceneNode*)smgr->getSceneNodeFromType(ESNT_TERRAIN, 0); ITriangleSelector *sceneTris = smgr->createTerrainTriangleSelector(sceneTerrain, 0); sceneTerrain->setTriangleSelector(sceneTris); for(int i=0; i<50; i++) // z { for(int j=0; j<50;j++) // x { //if( //{ p1.X = 10.0; p1.Y = 1.0; p1.Z = 0.0; p2.X = 10.0; p2.Y = 1.0; p2.Z = 500.0; p3.X = 0.0; p3.Y = 1.0; p3.Z = 500.0; p4.X = 0.0; p4.Y = 1.0; p4.Z = 0.0; quadId = j + (i * 10); myQuad[quadId] = new CSampleSceneNode(smgr->getRootSceneNode(), smgr, quadId, p1, p2, p3, p4); //} } } while(device->run()) { driver->beginScene(true, true, SColor(0,100,100,100)); smgr->drawAll(); driver->endScene(); } device->drop(); return 0; }
// render // ISceneNode implement void CGameStaticShadowSceneNode::render() { video::IVideoDriver* driver = SceneManager->getVideoDriver(); ICameraSceneNode* camera = SceneManager->getActiveCamera(); if (!camera || !driver) return; const core::matrix4 &m = camera->getViewFrustum()->getTransform( video::ETS_VIEW ); const core::vector3df view ( -m[2], -m[6] , -m[10] ); // get shadow comp CShadowComponent* shadow = (CShadowComponent*)m_owner->getComponent(IObjectComponent::Shadow); if ( shadow == NULL ) return; // make buffer by shadow pos std::vector<video::S3DVertex>& listShadow = shadow->getListShadow(); int nShadow = (int)listShadow.size(); if ( nShadow > 0 ) { // create shadow mesh buffer reallocateBuffers(nShadow); s32 idx = 0; std::vector<video::S3DVertex>::iterator i = listShadow.begin(), end = listShadow.end(); while (i != end) { core::vector3df pos = i->Pos; core::vector3df nor = i->Normal; float width = 80.0f; float height = 80.0f; // set texcoord Buffer->Vertices[0+idx].TCoords.set(0.0f, 0.0f); Buffer->Vertices[1+idx].TCoords.set(0.0f, 1.0f); Buffer->Vertices[2+idx].TCoords.set(1.0f, 1.0f); Buffer->Vertices[3+idx].TCoords.set(1.0f, 0.0f); // calc plane position f32 f = 0.5f * width; core::vector3df horizontal ( f, 0, 0 ); f = -0.5f * height; core::vector3df vertical ( 0, 0, f ); // rotate plane core::quaternion quaternion; quaternion.rotationFromTo( core::vector3df(0.0f,1.0f,0.0f), nor ); core::matrix4 matrix = quaternion.getMatrix(); matrix.rotateVect(horizontal); matrix.rotateVect(vertical); // update buffer position Buffer->Vertices[0+idx].Pos = pos + horizontal + vertical; Buffer->Vertices[0+idx].Color = SColor(255,0,0,0); Buffer->Vertices[0+idx].Normal = nor; Buffer->Vertices[1+idx].Pos = pos + horizontal - vertical; Buffer->Vertices[1+idx].Color = SColor(255,0,0,0); Buffer->Vertices[1+idx].Normal = nor; Buffer->Vertices[2+idx].Pos = pos - horizontal - vertical; Buffer->Vertices[2+idx].Color = SColor(255,0,0,0); Buffer->Vertices[2+idx].Normal = nor; Buffer->Vertices[3+idx].Pos = pos - horizontal + vertical; Buffer->Vertices[3+idx].Color = SColor(255,0,0,0); Buffer->Vertices[3+idx].Normal = nor; idx += 4; Buffer->BoundingBox.addInternalPoint(pos); ++i; } // render all core::matrix4 mat; driver->setTransform(video::ETS_WORLD, mat); // render 2 face on nonbillboard particle Buffer->Material.BackfaceCulling = false; Buffer->Material.FrontfaceCulling = false; Buffer->Material.Lighting = false; driver->setMaterial(Buffer->Material); driver->drawVertexPrimitiveList( Buffer->getVertices(), nShadow*4, Buffer->getIndices(), nShadow*2, video::EVT_STANDARD, EPT_TRIANGLES, Buffer->getIndexType() ); } listShadow.clear(); }