|
|
|
@ -20,86 +20,6 @@
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
// FIXME: this section should be removed once the debugging is completed
|
|
|
|
|
void showHitPoint(Ogre::SceneManager *sceneMgr, std::string name, Ogre::Vector3 point)
|
|
|
|
|
{
|
|
|
|
|
if(sceneMgr->hasManualObject("manual" + name))
|
|
|
|
|
sceneMgr->destroyManualObject("manual" + name);
|
|
|
|
|
Ogre::ManualObject* manual = sceneMgr->createManualObject("manual" + name);
|
|
|
|
|
manual->begin("BaseWhite", Ogre::RenderOperation::OT_LINE_LIST);
|
|
|
|
|
manual-> position(point.x, point.y, point.z-100);
|
|
|
|
|
manual-> position(point.x, point.y, point.z+100);
|
|
|
|
|
manual-> position(point.x, point.y-100, point.z);
|
|
|
|
|
manual-> position(point.x, point.y+100, point.z);
|
|
|
|
|
manual-> position(point.x-100, point.y, point.z);
|
|
|
|
|
manual-> position(point.x+100, point.y, point.z);
|
|
|
|
|
manual->end();
|
|
|
|
|
sceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(manual);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void removeHitPoint(Ogre::SceneManager *sceneMgr, std::string name)
|
|
|
|
|
{
|
|
|
|
|
if(sceneMgr->hasManualObject("manual" + name))
|
|
|
|
|
sceneMgr->destroyManualObject("manual" + name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void initDebug()
|
|
|
|
|
{
|
|
|
|
|
// material for visual cue on selected objects
|
|
|
|
|
Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName("DynamicTrans");
|
|
|
|
|
if(texture.isNull())
|
|
|
|
|
{
|
|
|
|
|
texture = Ogre::TextureManager::getSingleton().createManual(
|
|
|
|
|
"DynamicTrans", // name
|
|
|
|
|
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
|
|
|
|
Ogre::TEX_TYPE_2D, // type
|
|
|
|
|
8, 8, // width & height
|
|
|
|
|
0, // number of mipmaps
|
|
|
|
|
Ogre::PF_BYTE_BGRA, // pixel format
|
|
|
|
|
Ogre::TU_DEFAULT); // usage; should be TU_DYNAMIC_WRITE_ONLY_DISCARDABLE for
|
|
|
|
|
// textures updated very often (e.g. each frame)
|
|
|
|
|
|
|
|
|
|
Ogre::HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();
|
|
|
|
|
pixelBuffer->lock(Ogre::HardwareBuffer::HBL_NORMAL);
|
|
|
|
|
const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock();
|
|
|
|
|
|
|
|
|
|
uint8_t* pDest = static_cast<uint8_t*>(pixelBox.data);
|
|
|
|
|
|
|
|
|
|
// Fill in some pixel data. This will give a semi-transparent colour,
|
|
|
|
|
// but this is of course dependent on the chosen pixel format.
|
|
|
|
|
for (size_t j = 0; j < 8; j++)
|
|
|
|
|
{
|
|
|
|
|
for(size_t i = 0; i < 8; i++)
|
|
|
|
|
{
|
|
|
|
|
*pDest++ = 255; // B
|
|
|
|
|
*pDest++ = 255; // G
|
|
|
|
|
*pDest++ = 127; // R
|
|
|
|
|
*pDest++ = 63; // A
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pDest += pixelBox.getRowSkip() * Ogre::PixelUtil::getNumElemBytes(pixelBox.format);
|
|
|
|
|
}
|
|
|
|
|
pixelBuffer->unlock();
|
|
|
|
|
}
|
|
|
|
|
Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(
|
|
|
|
|
"TransMaterial");
|
|
|
|
|
if(material.isNull())
|
|
|
|
|
{
|
|
|
|
|
Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(
|
|
|
|
|
"TransMaterial",
|
|
|
|
|
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true );
|
|
|
|
|
Ogre::Pass *pass = material->getTechnique( 0 )->getPass( 0 );
|
|
|
|
|
pass->setLightingEnabled( false );
|
|
|
|
|
pass->setDepthWriteEnabled( false );
|
|
|
|
|
pass->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA );
|
|
|
|
|
|
|
|
|
|
Ogre::TextureUnitState *tex = pass->createTextureUnitState("CustomState", 0);
|
|
|
|
|
tex->setTextureName("DynamicTrans");
|
|
|
|
|
tex->setTextureFiltering( Ogre::TFO_ANISOTROPIC );
|
|
|
|
|
material->load();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//plane Z, upvector Y, mOffset z : x-y plane, wheel up/down
|
|
|
|
|
//plane Y, upvector X, mOffset y : y-z plane, wheel left/right
|
|
|
|
|
//plane X, upvector Y, mOffset x : x-z plane, wheel closer/further
|
|
|
|
@ -159,8 +79,6 @@ namespace CSVRender
|
|
|
|
|
, mGrabbedSceneNode(""), mOrigObjPos(Ogre::Vector3()), mOrigMousePos(Ogre::Vector3())
|
|
|
|
|
, mCurrentMousePos(Ogre::Vector3()), mOffset(0.0f)
|
|
|
|
|
{
|
|
|
|
|
initDebug();
|
|
|
|
|
|
|
|
|
|
mMouseEventTimer = new QElapsedTimer();
|
|
|
|
|
mMouseEventTimer->invalidate();
|
|
|
|
|
|
|
|
|
@ -181,25 +99,6 @@ namespace CSVRender
|
|
|
|
|
MouseState::~MouseState ()
|
|
|
|
|
{
|
|
|
|
|
delete mMouseEventTimer;
|
|
|
|
|
|
|
|
|
|
// For debugging only
|
|
|
|
|
std::map<std::string, std::vector<std::string> >::iterator iter = mSelectedEntities.begin();
|
|
|
|
|
for(;iter != mSelectedEntities.end(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
removeHitPoint(mSceneManager, iter->first);
|
|
|
|
|
|
|
|
|
|
if(mSceneManager->hasSceneNode(iter->first))
|
|
|
|
|
{
|
|
|
|
|
Ogre::SceneNode *scene = mSceneManager->getSceneNode(iter->first);
|
|
|
|
|
|
|
|
|
|
if(scene)
|
|
|
|
|
{
|
|
|
|
|
scene->removeAndDestroyAllChildren();
|
|
|
|
|
mSceneManager->destroySceneNode(iter->first);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete mPlane;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -233,7 +132,6 @@ namespace CSVRender
|
|
|
|
|
{
|
|
|
|
|
std::pair<Ogre::Vector3, Ogre::Vector3> planeRes = planeAxis();
|
|
|
|
|
Ogre::Vector3 pos = mOrigObjPos + planeRes.first*mOffset;
|
|
|
|
|
//pos.z += mOffset;
|
|
|
|
|
mSceneManager->getSceneNode(mGrabbedSceneNode)->setPosition(pos+planeResult.second-mOrigMousePos);
|
|
|
|
|
mCurrentMousePos = planeResult.second;
|
|
|
|
|
mPhysics->moveSceneNodes(mGrabbedSceneNode, pos+planeResult.second-mOrigMousePos);
|
|
|
|
@ -349,9 +247,6 @@ namespace CSVRender
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// update highlighting the current object
|
|
|
|
|
if(isDebug())
|
|
|
|
|
updateSelectionHighlight(result.first, result.second);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -364,7 +259,6 @@ namespace CSVRender
|
|
|
|
|
if(mGrabbedSceneNode != "")
|
|
|
|
|
{
|
|
|
|
|
std::pair<Ogre::Vector3, Ogre::Vector3> planeRes = planeAxis();
|
|
|
|
|
//mOrigObjPos.z += mOffset;
|
|
|
|
|
Ogre::Vector3 pos = mOrigObjPos+planeRes.first*mOffset+planeResult.second-mOrigMousePos;
|
|
|
|
|
placeObject(mGrabbedSceneNode, pos);
|
|
|
|
|
//mCurrentObj = mGrabbedSceneNode; // FIXME
|
|
|
|
@ -440,7 +334,6 @@ namespace CSVRender
|
|
|
|
|
|
|
|
|
|
std::pair<Ogre::Vector3, Ogre::Vector3> planeRes = planeAxis();
|
|
|
|
|
Ogre::Vector3 pos = mOrigObjPos + planeRes.first*mOffset;
|
|
|
|
|
//pos.z += mOffset;
|
|
|
|
|
mSceneManager->getSceneNode(mGrabbedSceneNode)->setPosition(pos+mCurrentMousePos-mOrigMousePos);
|
|
|
|
|
mPhysics->moveSceneNodes(mGrabbedSceneNode, pos+mCurrentMousePos-mOrigMousePos);
|
|
|
|
|
updateSceneWidgets();
|
|
|
|
@ -525,80 +418,6 @@ namespace CSVRender
|
|
|
|
|
return std::make_pair("", Ogre::Vector3());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FIXME: for debugging only
|
|
|
|
|
void MouseState::updateSelectionHighlight(const std::string sceneNode, const Ogre::Vector3 &position)
|
|
|
|
|
{
|
|
|
|
|
uint32_t visibilityMask = getViewport()->getVisibilityMask();
|
|
|
|
|
bool ignoreObjects = !(visibilityMask & (uint32_t)CSVRender::Element_Reference);
|
|
|
|
|
|
|
|
|
|
if(ignoreObjects || !mSceneManager->hasSceneNode(sceneNode) || !isDebug())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance();
|
|
|
|
|
bool debugCursor = userSettings.setting(
|
|
|
|
|
"debug/mouse-position", QString("false")) == "true" ? true : false;
|
|
|
|
|
|
|
|
|
|
//TODO: Try http://www.ogre3d.org/tikiwiki/Create+outline+around+a+character
|
|
|
|
|
Ogre::SceneNode *scene = mSceneManager->getSceneNode(sceneNode);
|
|
|
|
|
std::map<std::string, std::vector<std::string> >::iterator iter =
|
|
|
|
|
mSelectedEntities.find(sceneNode);
|
|
|
|
|
if(iter != mSelectedEntities.end()) // currently selected
|
|
|
|
|
{
|
|
|
|
|
std::vector<std::string> clonedEntities = mSelectedEntities[sceneNode];
|
|
|
|
|
while(!clonedEntities.empty())
|
|
|
|
|
{
|
|
|
|
|
if(mSceneManager->hasEntity(clonedEntities.back()))
|
|
|
|
|
{
|
|
|
|
|
scene->detachObject(clonedEntities.back());
|
|
|
|
|
mSceneManager->destroyEntity(clonedEntities.back());
|
|
|
|
|
}
|
|
|
|
|
clonedEntities.pop_back();
|
|
|
|
|
}
|
|
|
|
|
mSelectedEntities.erase(iter);
|
|
|
|
|
|
|
|
|
|
if(debugCursor)
|
|
|
|
|
removeHitPoint(mSceneManager, sceneNode);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::vector<std::string> clonedEntities;
|
|
|
|
|
Ogre::SceneNode::ObjectIterator iter = scene->getAttachedObjectIterator();
|
|
|
|
|
iter.begin();
|
|
|
|
|
while(iter.hasMoreElements())
|
|
|
|
|
{
|
|
|
|
|
Ogre::MovableObject * element = iter.getNext();
|
|
|
|
|
if(!element)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if(element->getMovableType() != "Entity")
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
Ogre::Entity * entity = dynamic_cast<Ogre::Entity *>(element);
|
|
|
|
|
if(mSceneManager->hasEntity(entity->getName()+"cover"))
|
|
|
|
|
{
|
|
|
|
|
// FIXME: this shouldn't really happen... but does :(
|
|
|
|
|
scene->detachObject(entity->getName()+"cover");
|
|
|
|
|
mSceneManager->destroyEntity(entity->getName()+"cover");
|
|
|
|
|
}
|
|
|
|
|
Ogre::Entity * clone = entity->clone(entity->getName()+"cover");
|
|
|
|
|
|
|
|
|
|
Ogre::MaterialPtr mat =
|
|
|
|
|
Ogre::MaterialManager::getSingleton().getByName("TransMaterial");
|
|
|
|
|
if(!mat.isNull())
|
|
|
|
|
{
|
|
|
|
|
clone->setMaterial(mat);
|
|
|
|
|
scene->attachObject(clone);
|
|
|
|
|
clonedEntities.push_back(entity->getName()+"cover");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mSelectedEntities[sceneNode] = clonedEntities;
|
|
|
|
|
|
|
|
|
|
if(debugCursor)
|
|
|
|
|
showHitPoint(mSceneManager, sceneNode, position);
|
|
|
|
|
}
|
|
|
|
|
mParent->flagAsModified();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MouseState::placeObject(const std::string sceneNode, const Ogre::Vector3 &pos)
|
|
|
|
|
{
|
|
|
|
|
mSceneManager->getSceneNode(sceneNode)->setPosition(pos);
|
|
|
|
|