void RotatedComponent::drawInternal(Graphics* const TheGraphics, Real32 Opacity) const { if(getInternalComponent() != NULL) { Pnt2f TopLeft, BottomRight; getInsideInsetsBounds(TopLeft, BottomRight); TheGraphics->incrDrawBounderiesNesting(); TheGraphics->initAddDrawBounderies(); TheGraphics->drawRect(TopLeft, BottomRight,Color4f(0.0f,0.0f,0.0f,1.0f),1.0); TheGraphics->uninitAddDrawBounderies(); TheGraphics->activateDrawBounderiesTest(); glPushMatrix(); glTranslatef(static_cast<Real32>(getSize().x())/2.0,static_cast<Real32>(getSize().y())/2.0,0.0); glRotatef(-osgRad2Degree(getAngle()), 0.0,0.0,1.0); glTranslatef(-static_cast<Real32>(getInternalComponent()->getSize().x())/2.0,-static_cast<Real32>(getInternalComponent()->getSize().y())/2.0,0.0); getInternalComponent()->draw(TheGraphics, getOpacity()*Opacity); glPopMatrix(); TheGraphics->decrDrawBounderiesNestring(); TheGraphics->initRemoveDrawBounderies(); TheGraphics->drawRect(TopLeft, BottomRight,Color4f(0.0f,0.0f,0.0f,1.0f),1.0); TheGraphics->uninitRemoveDrawBounderies(); TheGraphics->activateDrawBounderiesTest(); } }
/*! Sets the \a lightChunk fields based on light. \dev DeferredShadingStage can not use the light's own chunk, because it computes the light position based on DrawEnv::getCameraViewing(), which is just the ortho camera for rendering the full screen quads, not the perspective camera used during the gbuffer pass. \enddev */ void DeferredShadingStage::updateLightChunk( DSLightChunk *lightChunk, Light *light) { lightChunk->setBeacon (light->getBeacon ()); lightChunk->setAmbient (light->getAmbient ()); lightChunk->setDiffuse (light->getDiffuse ()); lightChunk->setSpecular(light->getSpecular()); if(light->getType() == DirectionalLight::getClassType()) { DirectionalLight *dirL = static_cast<DirectionalLight *>(light); Vec4f dir(dirL->getDirection()); dir[3] = 0.f; lightChunk->setPosition(dir); } else if(light->getType() == PointLight::getClassType()) { PointLight *pointL = static_cast<PointLight *>(light); Vec4f pos(pointL->getPosition()); pos[3] = 1.f; lightChunk->setPosition (pos ); lightChunk->setConstantAttenuation (pointL->getConstantAttenuation ()); lightChunk->setLinearAttenuation (pointL->getLinearAttenuation ()); lightChunk->setQuadraticAttenuation(pointL->getQuadraticAttenuation()); lightChunk->setCutoff (180.f ); } else if(light->getType() == SpotLight::getClassType()) { SpotLight *spotL = static_cast<SpotLight *>(light); Vec4f pos(spotL->getPosition()); pos[3] = 1.f; lightChunk->setPosition (pos ); lightChunk->setConstantAttenuation (spotL->getConstantAttenuation ()); lightChunk->setLinearAttenuation (spotL->getLinearAttenuation ()); lightChunk->setQuadraticAttenuation(spotL->getQuadraticAttenuation()); lightChunk->setDirection (spotL->getDirection ()); lightChunk->setExponent (spotL->getSpotExponent ()); lightChunk->setCutoff ( osgRad2Degree(spotL->getSpotCutOff())); } else { SWARNING << "DeferredShadingStage::updateLightChunk: " << "Unknown light type." << endLog; } }
void SpotLight::makeChunk(void) { Inherited::makeChunk(); Vec4f pos(_sfPosition.getValue ()); pos[3] = 1.f; _pChunk->setPosition (pos ); _pChunk->setDirection( getDirection () ); _pChunk->setExponent ( getSpotExponent() ); _pChunk->setCutoff (osgRad2Degree(getSpotCutOff ())); }
/*! The mouseMove is called by the viewer when the mouse is moved in the viewer and this handle is the active one. \param x the x-pos of the mouse (pixel) \param y the y-pos of the mouse (pixel) */ void PlaneMoveManipulator::mouseMove(const Int16 x, const Int16 y) { SLOG << "==============================" << endLog; SLOG << "PlaneMoveManipulator::mouseMove() enter x=" << x << " y=" << y << endLog; // get the beacon's core (must be ComponentTransform) and it's center if( getTarget() == NULL ) { SWARNING << "Handle has no target.\n"; return; } // get transformation of beacon Transform *t = dynamic_cast<Transform *>(getTarget()->getCore()); if( t == NULL ) { SWARNING << "handled object has no parent transform!\n"; return; } Vec3f translation; // for matrix decomposition Quaternion rotation; Vec3f scaleFactor; Quaternion scaleOrientation; t->getMatrix().getTransform(translation, rotation, scaleFactor, scaleOrientation); OSG::Line viewray; getViewport()->getCamera()->calcViewRay(viewray, x, y, *getViewport()); SLOG << "Manipulator::mouseMove(): viewray: " << viewray << endLog; // Get manipulator axes into world space OSG::Matrix tm = getTarget()->getToWorld(); Vec3f rot_axis; tm.multFull(Vec3f(0,1,0), rot_axis); Plane pl(rot_axis, getClickPoint()); Pnt3f plpoint; if (pl.intersect(viewray, plpoint) == true) // Ignore moving out of the plane... { SLOG << "Manipulator::mouseMove(): plpoint: " << plpoint << endLog; Vec3f trans = getBaseTranslation(); Quaternion rot = getBaseRotation(); // Get manipulator axes into world space Vec3f xp,zp; tm.multFull(Vec3f(1,0,0), xp); tm.multFull(Vec3f(0,0,1), zp); if (getActiveSubHandle() == getHandleXNode()) { Line xaxis(getClickPoint(), xp); Line zaxis(getClickPoint(), zp); Real32 fx = xaxis.getClosestPointT(plpoint); Real32 fz = zaxis.getClosestPointT(plpoint); SLOG << "Manipulator::mouseMove(): xaxis: " << xaxis << " zaxis: " << zaxis <<endLog; SLOG << "Manipulator::mouseMove(): fx: " << fx << " fz: " << fz <<endLog; // Alternative: transform hitpoint into manip space OSG::Matrix m = getTarget()->getToWorld(); m.invert(); Pnt3f mpoint; m.mult(plpoint, mpoint); SLOG << "Manipulator::mouseMove(): mpoint:" << mpoint << endLog; trans = trans + xp * fx + zp * fz; } else if (getActiveSubHandle() == getHandleZNode()) { Pnt3f wcenter; tm.multFull(Pnt3f(0,getLength()[1],0), wcenter); Vec3f vclick, vcurrent; vclick = getClickPoint() - wcenter; vcurrent = plpoint - wcenter; vclick.normalize(); vcurrent.normalize(); Real32 a = vclick.enclosedAngle(vcurrent); SLOG << "Manipulator::mouseMove(): wcenter:" << wcenter << "" <<endLog; SLOG << "Manipulator::mouseMove(): vclick:" << vclick << " vcurrent:" << vcurrent <<endLog; SLOG << "Manipulator::mouseMove(): angle:" << a << " deg: " << osgRad2Degree(a) << endLog; } Matrix m; m.setTransform(trans, rot, scaleFactor, scaleOrientation); t->setMatrix(m); } setLastMousePos(Pnt2f(Real32(x), Real32(y))); updateHandleTransform(); //SLOG << "Manipulator::mouseMove() leave\n" << std::flush; }