How move entity in version 1.10 ?
Posted: Fri Feb 09, 2018 11:27 pm
Hello,
How in Ogre 1.10 move entity ?
How in Ogre 1.10 move entity ?
Support and community hang-out spot for Ogre3D
https://forums.ogre3d.org/
Code: Select all
Root* root;
SceneManager* scnMgr;
SceneNode* camNode;
Camera* cam;
Entity* ninja;
SceneNode* ninjaNode;
void TutorialApplication::setup()
{
RTShader::ShaderGenerator* shadergen;
// do not forget to call the base first
ApplicationContext::setup();
addInputListener(this);
// get a pointer to the already created root
root = getRoot();
scnMgr = root->createSceneManager();
// register our scene with the RTSS
shadergen = RTShader::ShaderGenerator::getSingletonPtr();
shadergen->addSceneManager(scnMgr);
// -- tutorial section start --
//! [cameracreate]
camNode = scnMgr->getRootSceneNode()->createChildSceneNode();
cam = scnMgr->createCamera("myCam");
//! [cameracreate]
//! [cameraposition]
camNode->setPosition(0, 200, 200); // 200, 300, 400
camNode->lookAt(Vector3(0, 150, 0), Node::TransformSpace::TS_WORLD);
//! [cameraposition]
//! [cameralaststep]
cam->setNearClipDistance(5);
camNode->attachObject(cam);
//! [cameralaststep]
//! [addviewport]
Viewport* vp = getRenderWindow()->addViewport(cam);
//! [addviewport]
//! [viewportback]
vp->setBackgroundColour(ColourValue(0, 0, 0));
//! [viewportback]
//! [cameraratio]
cam->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
//! [cameraratio]
//! [ninja]
ninja = scnMgr->createEntity("ninja.mesh");
ninja->setCastShadows(true);
ninjaNode = scnMgr->getRootSceneNode()->createChildSceneNode();
ninjaNode ->attachObject(ninja);
//! [ninja]
//! [plane]
Plane plane(Vector3::UNIT_Y, 0);
//! [plane]
//! [planedefine]
MeshManager::getSingleton().createPlane(
"ground",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
plane,
1500, 1500, 20, 20,
true,
1, 5, 5,
Vector3::UNIT_Z);
//! [planedefine]
//! [planecreate]
Entity* groundEntity = scnMgr->createEntity("ground");
scnMgr->getRootSceneNode()->createChildSceneNode()->attachObject(groundEntity);
//! [planecreate]
//! [planenoshadow]
groundEntity->setCastShadows(false);
//! [planenoshadow]
//! [planesetmat]
groundEntity->setMaterialName("Examples/Rockwall");
//! [planesetmat]
//! [lightingsset]
scnMgr->setAmbientLight(ColourValue(0, 0, 0));
scnMgr->setShadowTechnique(ShadowTechnique::SHADOWTYPE_STENCIL_MODULATIVE);
//! [lightingsset]
//! [spotlight]
Light* spotLight = scnMgr->createLight("SpotLight");
//! [spotlight]
//! [spotlightcolor]
spotLight->setDiffuseColour(0, 0, 1.0);
spotLight->setSpecularColour(0, 0, 1.0);
//! [spotlightcolor]
//! [spotlighttype]
spotLight->setType(Light::LT_SPOTLIGHT);
//! [spotlighttype]
//! [spotlightposrot]
spotLight->setDirection(Vector3::NEGATIVE_UNIT_Z);
SceneNode* spotLightNode = scnMgr->getRootSceneNode()->createChildSceneNode();
spotLightNode->attachObject(spotLight);
spotLightNode->setDirection(-1, -1, 0);
spotLightNode->setPosition(Vector3(200, 200, 0));
//! [spotlightposrot]
//! [spotlightrange]
spotLight->setSpotlightRange(Degree(35), Degree(50));
//! [spotlightrange]
//! [directlight]
Light* directionalLight = scnMgr->createLight("DirectionalLight");
directionalLight->setType(Light::LT_DIRECTIONAL);
//! [directlight]
//! [directlightcolor]
directionalLight->setDiffuseColour(ColourValue(0.4, 0, 0));
directionalLight->setSpecularColour(ColourValue(0.4, 0, 0));
//! [directlightcolor]
//! [directlightdir]
directionalLight->setDirection(Vector3::NEGATIVE_UNIT_Z);
SceneNode* directionalLightNode = scnMgr->getRootSceneNode()->createChildSceneNode();
directionalLightNode->attachObject(directionalLight);
directionalLightNode->setDirection(Vector3(0, -1, 1));
//! [directlightdir]
//! [pointlight]
please, help
Light* pointLight = scnMgr->createLight("PointLight");
pointLight->setType(Light::LT_POINT);
//! [pointlight]
//! [pointlightcolor]
pointLight->setDiffuseColour(0.3, 0.3, 0.3);
pointLight->setSpecularColour(0.3, 0.3, 0.3);
//! [pointlightcolor]
//! [pointlightpos]
SceneNode* pointLightNode = scnMgr->getRootSceneNode()->createChildSceneNode();
pointLightNode->attachObject(pointLight);
pointLightNode->setPosition(Vector3(0, 150, 250));
//! [pointlightpos]
// -- tutorial section end --
}
bool TutorialApplication::keyPressed(const KeyboardEvent& evt)
{
if (evt.keysym.sym == SDLK_ESCAPE)
{
getRoot()->queueEndRendering();
}
if (evt.keysym.sym == SDLK_UP)
{
ninjaNode->setPosition(ninjaNode->getOrientation() * Vector3(0, 0, 100));
}
if (evt.keysym.sym == SDLK_DOWN)
{
ninjaNode->setPosition(ninjaNode->getOrientation() * Vector3(0, 0, -100));
}
return true;
}
Code: Select all
ninjaNode->translate(0,0,value)
Code: Select all
ninjaNode->setPosition( ninjaNode->getOrientation() * ( ninjaNode->getPosition() + Vector3(0, 0, value) ) );
Code: Select all
if (evt.keysym.sym == SDLK_ESCAPE)
{
getRoot()->queueEndRendering();
}
if (evt.keysym.sym == SDLK_UP)
{
//value = value - 5.0f;
// ninjaNode->setPosition(ninjaNode->getOrientation() * Vector3(0, 0, 100));
//ninjaNode->translate(0, 0, value);
ninjaNode->setPosition(ninjaNode->getOrientation() * (ninjaNode->getPosition() + Vector3(0, 0, -50)));
camNode->translate(0, 0, -50);
}
if (evt.keysym.sym == SDLK_DOWN)
{
//value = value + 5.0f;
// ninjaNode->setPosition(ninjaNode->getOrientation() * Vector3(0, 0, 100));
//ninjaNode->translate(0, 0, value);
//ninjaNode->setPosition(ninjaNode->getOrientation() * Vector3(0, 0, -100));
ninjaNode->setPosition(ninjaNode->getOrientation() * (ninjaNode->getPosition() + Vector3(0, 0, 50)));
camNode->translate(0, 0, 50);
}
if (evt.keysym.sym == SDLK_LEFT)
{
camNode->setOrientation(Ogre::Quaternion(Ogre::Math::Sqrt(0.5f),
Ogre::Math::Sqrt(0.5f), 200, 200));
}
return true;
Code: Select all
camNode->getParentSceneNode()->removeChild( camNode );
ninjaNode ->addChild( camNode );
Code: Select all
ninjaNode->translate(0,0,someValue)
Code: Select all
if (evt.keysym.sym == SDLK_LEFT)
{
ninjaNode->setOrientation(Ogre::Quaternion(Ogre::Math::Sqrt(0.5f), Ogre::Math::Sqrt(0.5f), 200, 0));
}
Code: Select all
if (evt.keysym.sym == SDLK_LEFT)
{
ninjaNode->setOrientation( ninjaNode->getOrientation() * Ogre::Quaternion(Ogre::Math::Sqrt(0.5f), Ogre::Math::Sqrt(0.5f), 200, 0) );
}
Code: Select all
Ogre::Quaternion newQuat = Ogre::Quaternion( Ogre::Radian( Ogre::Degree(15).valueRadians() ), Ogre::Vector3::UNIT_Y );
ninjaNode->setOrientation( ninjaNode->getOrientation() * newQuat );
Code: Select all
class TutorialApplication
: public ApplicationContext
, public InputListener
{
public:
TutorialApplication();
virtual ~TutorialApplication();
void setup();
bool keyPressed(const KeyboardEvent& evt);
};
TutorialApplication::TutorialApplication()
: ApplicationContext("OgreTutorialApp")
{
}
TutorialApplication::~TutorialApplication()
{
}
Root* root;
SceneManager* scnMgr;
SceneNode* camNode;
Camera* cam;
Entity* ninja;
SceneNode* ninjaNode;
void TutorialApplication::setup()
{
RTShader::ShaderGenerator* shadergen;
// do not forget to call the base first
ApplicationContext::setup();
addInputListener(this);
// get a pointer to the already created root
root = getRoot();
scnMgr = root->createSceneManager();
// register our scene with the RTSS
shadergen = RTShader::ShaderGenerator::getSingletonPtr();
shadergen->addSceneManager(scnMgr);
// -- tutorial section start --
//! [cameracreate]
camNode = scnMgr->getRootSceneNode()->createChildSceneNode();
cam = scnMgr->createCamera("myCam");
//! [cameracreate]
//! [cameraposition]
camNode->setPosition(0, 200, 200); // 200, 300, 400
camNode->lookAt(Vector3(0, 150, 0), Node::TransformSpace::TS_WORLD);
//! [cameraposition]
//! [cameralaststep]
cam->setNearClipDistance(5);
camNode->attachObject(cam);
//! [cameralaststep]
//! [addviewport]
Viewport* vp = getRenderWindow()->addViewport(cam);
//! [addviewport]
//! [viewportback]
vp->setBackgroundColour(ColourValue(0, 0, 0));
//! [viewportback]
//! [cameraratio]
cam->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
//! [cameraratio]
//! [ninja]
ninja = scnMgr->createEntity("ninja.mesh");
ninja->setCastShadows(true);
ninjaNode = scnMgr->getRootSceneNode()->createChildSceneNode();
ninjaNode ->attachObject(ninja);
//! [ninja]
//! [plane]
Plane plane(Vector3::UNIT_Y, 0);
//! [plane]
//! [planedefine]
MeshManager::getSingleton().createPlane(
"ground",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
plane,
1500, 1500, 20, 20,
true,
1, 5, 5,
Vector3::UNIT_Z);
//! [planedefine]
//! [planecreate]
Entity* groundEntity = scnMgr->createEntity("ground");
scnMgr->getRootSceneNode()->createChildSceneNode()->attachObject(groundEntity);
//! [planecreate]
//! [planenoshadow]
groundEntity->setCastShadows(false);
//! [planenoshadow]
//! [planesetmat]
groundEntity->setMaterialName("Examples/Rockwall");
//! [planesetmat]
//! [lightingsset]
scnMgr->setAmbientLight(ColourValue(0, 0, 0));
scnMgr->setShadowTechnique(ShadowTechnique::SHADOWTYPE_STENCIL_MODULATIVE);
//! [lightingsset]
//! [spotlight]
Light* spotLight = scnMgr->createLight("SpotLight");
//! [spotlight]
//! [spotlightcolor]
spotLight->setDiffuseColour(0, 0, 1.0);
spotLight->setSpecularColour(0, 0, 1.0);
//! [spotlightcolor]
//! [spotlighttype]
spotLight->setType(Light::LT_SPOTLIGHT);
//! [spotlighttype]
//! [spotlightposrot]
spotLight->setDirection(Vector3::NEGATIVE_UNIT_Z);
SceneNode* spotLightNode = scnMgr->getRootSceneNode()->createChildSceneNode();
spotLightNode->attachObject(spotLight);
spotLightNode->setDirection(-1, -1, 0);
spotLightNode->setPosition(Vector3(200, 200, 0));
//! [spotlightposrot]
//! [spotlightrange]
spotLight->setSpotlightRange(Degree(35), Degree(50));
//! [spotlightrange]
//! [directlight]
Light* directionalLight = scnMgr->createLight("DirectionalLight");
directionalLight->setType(Light::LT_DIRECTIONAL);
//! [directlight]
//! [directlightcolor]
directionalLight->setDiffuseColour(ColourValue(0.4, 0, 0));
directionalLight->setSpecularColour(ColourValue(0.4, 0, 0));
//! [directlightcolor]
//! [directlightdir]
directionalLight->setDirection(Vector3::NEGATIVE_UNIT_Z);
SceneNode* directionalLightNode = scnMgr->getRootSceneNode()->createChildSceneNode();
directionalLightNode->attachObject(directionalLight);
directionalLightNode->setDirection(Vector3(0, -1, 1));
//! [directlightdir]
//! [pointlight]
Light* pointLight = scnMgr->createLight("PointLight");
pointLight->setType(Light::LT_POINT);
//! [pointlight]
//! [pointlightcolor]
pointLight->setDiffuseColour(0.3, 0.3, 0.3);
pointLight->setSpecularColour(0.3, 0.3, 0.3);
//! [pointlightcolor]
//! [pointlightpos]
SceneNode* pointLightNode = scnMgr->getRootSceneNode()->createChildSceneNode();
pointLightNode->attachObject(pointLight);
pointLightNode->setPosition(Vector3(0, 150, 250));
//! [pointlightpos]
// -- tutorial section end --
camNode->getParentSceneNode()->removeChild(camNode);
ninjaNode->addChild(camNode);
}
float value = 0.0f;
Ogre::Quaternion newQuat = Ogre::Quaternion(Ogre::Radian(Ogre::Degree(15).valueRadians()), Ogre::Vector3::UNIT_Y);
bool TutorialApplication::keyPressed(const KeyboardEvent& evt)
{
if (evt.keysym.sym == SDLK_ESCAPE)
{
getRoot()->queueEndRendering();
}
if (evt.keysym.sym == SDLK_UP)
{
//value = value - 5.0f;
// ninjaNode->setPosition(ninjaNode->getOrientation() * Vector3(0, 0, 100));
//ninjaNode->translate(0, 0, value);
ninjaNode->setPosition(ninjaNode->getOrientation() * (ninjaNode->getPosition() + Vector3(0, 0, -50)));
//camNode->translate(0, 0, -50);
}
if (evt.keysym.sym == SDLK_DOWN)
{
//value = value + 5.0f;
// ninjaNode->setPosition(ninjaNode->getOrientation() * Vector3(0, 0, 100));
//ninjaNode->translate(0, 0, value);
//ninjaNode->setPosition(ninjaNode->getOrientation() * Vector3(0, 0, -100));
ninjaNode->setOrientation(ninjaNode->getOrientation());
ninjaNode->setPosition(ninjaNode->getOrientation() * (ninjaNode->getPosition() + Vector3(0, 0, 50)));
//camNode->translate(0, 0, 50);
}
if (evt.keysym.sym == SDLK_LEFT)
{
//ninjaNode->setOrientation(Ogre::Quaternion(50, (ninjaNode->getOrientation() *ninjaNode->getPosition().x), (ninjaNode->getOrientation() *ninjaNode->getPosition().y), (ninjaNode->getOrientation() *ninjaNode->getPosition().z)));
//ninjaNode->setOrientation(Ogre::Quaternion(Ogre::Math::Sqrt(0.5f),
// 0, 200, Ogre::Math::Sqrt(0.5f)));
//ninjaNode->setPosition(ninjaNode->getOrientation() * (ninjaNode->getPosition() + Vector3(0, 0, 0)));
//ninjaNode->setOrientation(Quaternion(Degree(90), ninjaNode->getOrientation() * (ninjaNode->getPosition() + Vector3(1, 0, 0))));
// ninjaNode->setOrientation(aroundPos.getRotationTo(targetPos));
// ninjaNode->setOrientation(Ogre::Quaternion(Ogre::Math::Sqrt(0.5f), Ogre::Math::Sqrt(0.5f), 200, 0));
// ninjaNode->rotate(Vector3::UNIT_Y, Degree(90```));
ninjaNode->setOrientation(ninjaNode->getOrientation() * newQuat );
}
if (evt.keysym.sym == SDLK_RIGHT)
{
// ninjaNode->setOrientation(Ogre::Quaternion(Ogre::Math::Sqrt(0.5f),
// Ogre::Math::Sqrt(0.5f), 200, 0));
//ninjaNode->setPosition(ninjaNode->getOrientation() * (ninjaNode->getPosition() + Vector3(-50, 0, 0)));
}
return true;
pressing UP seems to be moving the ninja -50 units in the direction of the orientation of the nodeCode: Select all
if (evt.keysym.sym == SDLK_UP) { ninjaNode->setPosition(ninjaNode->getOrientation() * (ninjaNode->getPosition() + Vector3(0, 0, -50))); }
pressing down seems to be doing the same but with 50 unitsCode: Select all
if (evt.keysym.sym == SDLK_DOWN) { ninjaNode->setOrientation(ninjaNode->getOrientation()); <<<<<<<<THIS LINE DOES NOTHING, sets the orientation value from the current one ninjaNode->setPosition(ninjaNode->getOrientation() * (ninjaNode->getPosition() + Vector3(0, 0, 50))); }
pressing left seems to be rotating the node 15 degrees in the Y axisCode: Select all
if (evt.keysym.sym == SDLK_LEFT) { ninjaNode->setOrientation(ninjaNode->getOrientation() * newQuat ); }
and pressing right does nothing, should this do the oposite of left? rotate -15 in the Y axis (which would be the same as rotating 15 in the negative Y axis)Code: Select all
if (evt.keysym.sym == SDLK_RIGHT) { }