int main(int argc, char** argv) { clock_t current = clock(); IrrlichtDevice* device = createDevice(video::EDT_DIRECT3D9); ParticleEditorReceiver* receiver = new ParticleEditorReceiver; receiver->scriptPath = argc>1 ? argv[1] : "particle.lua"; receiver->smgr = device->getSceneManager(); receiver->factory = CParticleSystemScriptFactory::createDefault( receiver->smgr->getParticleSystemFactory()); // receiver->factory->Initers["Texture"] = irrptr<IStackPusherFactory>( // new CTextureIniterStackPusherFactory(*device->getRandomizer(), *device->getVideoDriver()), false); receiver->L = luaL_newstate(); { luaT::StackMemo m(receiver->L); luaL_openlibs(receiver->L); luaopen_AllParticleSystem(receiver->L); xihad::render3d::luaopen_Material(receiver->L); xihad::render3d::luaopen_SColor(receiver->L); } receiver->smgr->addSkyDomeSceneNode(device->getVideoDriver()->getTexture("../Xihad/Assets/gfx/skydome.jpg")); ISceneNode* source = addNinja(receiver->smgr, core::vector3df(-10, 0, 0)); core::matrix4 rel = source->getRelativeTransformation(); rel.setRotationDegrees(core::vector3df(0, 90, 0)); source->setRelativeTransformation(rel); ISceneNode* target = addNinja(receiver->smgr, core::vector3df(10, 0, 0)); rel = target->getRelativeTransformation(); rel.setRotationDegrees(core::vector3df(0, -90, 0)); target->setRelativeTransformation(rel); ParticleEditorEnv* env = new ParticleEditorEnv(source, target, device, current); receiver->env.reset(env); env->drop(); receiver->createNewParticleSystem(); receiver->smgr->addCameraSceneNode(0, core::vector3df(-12,12,-12), core::vector3df(5,0, 0)); device->setEventReceiver(receiver); while (device->run()) { current = clock(); video::SColor bg = device->isWindowActive() ? video::SColor(0) : video::SColor(0xff101010); device->getVideoDriver()->beginScene(true, true, bg); device->getSceneManager()->onAnimate(current); receiver->env->update(current); device->getSceneManager()->drawAll(); device->getVideoDriver()->endScene(); } delete receiver; device->drop(); system("pause"); return 0; }
int Java_zte_irrlib_scene_SceneNode_nativeGetRelativeMatrix( JNIEnv* env, jobject thiz, jobject jmat, jint Id) { ISceneNode* node = smgr->getSceneNodeFromId(Id); if (!node) { WARN_NODE_NOT_FOUND(Id, GetRelativeMatrix); return -1; } utils->setMatrix4Frommatrix4(env, jmat, node->getRelativeTransformation()); return 0; }
void VesselSceneNode::snap(OrbiterDockingPort& ourPort, OrbiterDockingPort& theirPort) { ISceneNode* ourNode = ourPort.portNode; ISceneNode* theirNode = theirPort.portNode; theirNode->updateAbsolutePosition(); ourNode->updateAbsolutePosition(); //absolute rotation of the target port core::matrix4 theirMatrix = theirNode->getAbsoluteTransformation(); //Origin up and facing (inversed) of the target port core::vector3df theirDir = core::vector3df(0, 0, -1); core::vector3df theirRot = core::vector3df(0, 1, 0); //get absolute inversed facing and up direction of the target port theirMatrix.rotateVect(theirDir); theirMatrix.rotateVect(theirRot); theirDir.normalize(); theirRot.normalize(); //build rotation matrix to rotate from the ORIGIN of the source port to their ports current alignement core::matrix4 ourPortToTheirPort; ourPortToTheirPort.buildCameraLookAtMatrixLH(core::vector3df(0, 0, 0), theirDir, theirRot).makeInverse(); //get inverted source port rotation relative to its vessel core::matrix4 ourVesselToOurPort = ourNode->getRelativeTransformation(); ourVesselToOurPort.makeInverse(); //multiply the rotation from our vessel origin to our port and from our port origin to the target to get the total transformation for the vessel core::matrix4 ourVesselToTheirPort = ourPortToTheirPort * ourVesselToOurPort; //apply the whole brouhaha setRotation(ourVesselToTheirPort.getRotationDegrees()); //we MUST update positions for getAbsolutePosition to reflect the rotation we just did. //also, we MUST update the position of the parent before the child, or the child still won't reflect the changes //we also MUST update the child seperately, it doesn't get updated by the parent updateAbsolutePosition(); ourNode->updateAbsolutePosition(); //position the vessel so the docking ports touch core::vector3df pos = ourNode->getAbsolutePosition() - getAbsolutePosition(); setPosition(theirNode->getAbsolutePosition() - pos); //update the new position, in case there's a vessel being snapped to this right next updateAbsolutePosition(); }