void Surface::clear() { flags = 0; lightMapId = 0; textureName = ""; uvOffset.set(0.0f,0.0f); uvScale.set(0.0f,0.0f); uvRotation = 0.0f; triangles.clear(); lines.clear(); vertices.clear(); }
void Surface::clear() { flags = 0; lightMapId = 0; textureName = ""; uvOffset.set(0.0f,0.0f); uvScale.set(0.0f,0.0f); uvRotation = 0.0f; triangles.clear(); lines.clear(); for(u32 v = 0; v < vertices.size(); v++) delete vertices[v]; vertices.clear(); }
/* Every time it gets drawn, this function gets called */ void CLensFlareSceneNode::render() { video::IVideoDriver* driver = SceneManager->getVideoDriver(); ICameraSceneNode* camera = SceneManager->getActiveCamera(); // Bail out if function dosn't have enough info // Will fail here if no textures supplied if (!camera || !driver || !Material.getTexture(0)) return; driver->setTransform(video::ETS_WORLD, core::matrix4()); const core::vector3df campos = camera->getAbsolutePosition(); const core::dimension2d<u32> sz = SceneManager->getVideoDriver()->getScreenSize(); const core::vector2df mid = core::vector2df((f32)sz.Width, (f32)sz.Height) * 0.5f; const core::position2di lp = SceneManager->getSceneCollisionManager()-> getScreenCoordinatesFrom3DPosition(getAbsolutePosition(), camera); const core::vector2df lightpos = core::vector2df((f32)lp.X, (f32)lp.Y); const u32 nframes = Material.getTexture(0)->getOriginalSize().Width / Material.getTexture(0)->getOriginalSize().Height; int texw = 8; float texp = 1.0f / nframes; core::vector3df target = camera->getTarget(); core::vector3df up = camera->getUpVector(); core::vector3df view = target - campos; view.normalize(); core::vector3df horizontal = up.crossProduct(view); horizontal.normalize(); core::vector3df vertical; vertical = horizontal.crossProduct(view); vertical.normalize(); view *= -1.0f; for (u32 i=0; i<4; ++i) vertices[i].Normal = view; driver->setMaterial(Material); core::vector3df pos; core::vector3df hor; core::vector3df ver; for (u32 ax = 0; ax < nframes; ++ax) { if (ax == 0 ) { pos = getAbsolutePosition(); texw = Material.getTexture(0)->getSize().Height; hor = horizontal * (sourceScale * texw); ver = vertical * (sourceScale * texw); } else { core::vector2df ipos = mid.getInterpolated(lightpos, (2.0f / nframes) * ax); pos = SceneManager->getSceneCollisionManager()->getRayFromScreenCoordinates( core::position2d<s32>(int(ipos.X ), int(ipos.Y ) ), camera).end; core::vector3df dir = core::vector3df(campos - pos).normalize(); pos = campos + (dir * -10.0f); texw = 4; hor = horizontal * (opticsScale * texw); ver = vertical * (opticsScale * texw); } vertices[0].TCoords.set( ax * texp, 1.0f); vertices[1].TCoords.set( ax * texp, 0.0f); vertices[2].TCoords.set((ax+1) * texp, 0.0f); vertices[3].TCoords.set((ax+1) * texp, 1.0f); vertices[0].Pos = pos + hor + ver; vertices[1].Pos = pos + hor - ver; vertices[2].Pos = pos - hor - ver; vertices[3].Pos = pos - hor + ver; driver->drawIndexedTriangleList(vertices, 4, indices, 2); } }