About Mouse position and Particle effects
by skeletor · in Torque Game Engine · 11/29/2006 (12:23 am) · 5 replies
Hello, sameone know how I can do a Particle effects like smooke, that follow the mouse?
Many thnks!
Many thnks!
#2
Really... many thnks!
I'm begginer in TGE... when I'll lern, I'll can help to the people xD I'm impacient!!
Saludos
11/29/2006 (6:12 am)
Woooww!!!Really... many thnks!
I'm begginer in TGE... when I'll lern, I'll can help to the people xD I'm impacient!!
Saludos
#3
Does this mean that I need to create a particle emitter datablock in script?
If so, how do I make sure that the code above recognizes and mounts the particle effect correctly? (I'll add that I am using TGEA 1.8.1, but thought that it might make the most sense to post this question in the thread where the code originated.)
03/19/2009 (8:48 am)
This is a great resource. Even though it was posted a long time ago, maybe someone might still be able to help me get it working. I have made the code and script additions that Michael suggests above, and both code and script compile fine. However, I don't see any smoke attached to the cursor. I figure this is because I need to create the "smokeEmitter" referenced in the final line myself, so I placed a particle emitter node using the mission editor and gave it the name "smokeEmitter." However, no luck. The smoke effect shows up where I place it but is not mounted to the cursor.Does this mean that I need to create a particle emitter datablock in script?
If so, how do I make sure that the code above recognizes and mounts the particle effect correctly? (I'll add that I am using TGEA 1.8.1, but thought that it might make the most sense to post this question in the thread where the code originated.)
#4
I might ask in the TGEA forum also but am trying not to double-post, so any help is appreciated. While I'm at it, does anybody have any suggestions on how to create the particle emitter in a way that it will be recognized by the last line of script?
04/01/2009 (12:13 pm)
Does anybody know what is the TGEA equivalent of server/scripts/playGui.cs? The resource says to put scripts in client/scripts/playGui.cs and server/scripts/playGui.cs. In TGEA 1.8.1, I can only find client/scripts/playGui.cs but not server/scripts/playGui.cs. In TGE, there is a playGui.cs file in both client/scripts and server/scripts but apparently not in TGEA. Does anybody know where I should put the last piece of script in the thread to make this code work in TGEA 1.8.1? I might ask in the TGEA forum also but am trying not to double-post, so any help is appreciated. While I'm at it, does anybody have any suggestions on how to create the particle emitter in a way that it will be recognized by the last line of script?
smokeEmitter.setTransform(%rangeEnd);
#5
10/24/2011 (2:34 pm)
How to do this with Torque3D v1.1 ?
Employee Michael Perry
ZombieShortbus
[b] In engine\game\gameTSCtrl.h, add the following public entries:[/b] Point3F mMouse3DVec; Point3F mMouse3DPos; Point3F getMouse3DVec() {return mMouse3DVec;} Point3F getMouse3DPos() {return mMouse3DPos;}[b]In engine\game\gameTSCtrl.cpp, add the following functions:[/b] [b]//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-[/b] void GameTSCtrl::onMouseMove(const GuiEvent &evt) { // Get the 3D vec and pos of the mouse in the world MatrixF mat; Point3F vel; if(GameGetCameraTransform(&mat, &vel)) { // Get the camera pos Point3F pos; mat.getColumn(3, &pos); // Convert mouse coords to screen coords Point3F screenPoint(evt.mousePoint.x, evt.mousePoint.y, -1); // Convert screen coords to world coords Point3F worldPoint; if(unproject(screenPoint, &worldPoint)) { mMouse3DPos = pos; mMouse3DVec = worldPoint - pos; mMouse3DVec.normalizeSafe(); } } Con::executef(this, 1, "onMouseMove"); } [b]//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-[/b] ConsoleMethod(GameTSCtrl, getMouse3DVec, const char*, 2, 2, "()") { char* retBuffer = Con::getReturnBuffer(256); const Point3F &vec = object->getMouse3DVec(); dSprintf(retBuffer, 256, "%f %f %f ", vec.x, vec.y, vec.z); return retBuffer; } [b]//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-[/b] ConsoleMethod(GameTSCtrl, getMouse3DPos, const char*, 2, 0, "()") { char* retBuffer = Con::getReturnBuffer(256); const Point3F &pos = object->getMouse3DPos(); dSprintf(retBuffer, 256, "%f %f %f ", pos.x, pos.y, pos.z); return retBuffer; }[b]In client\scripts\playGui.cs:[/b] function PlayGui::onMouseMove(%this) { %mouseVec = %this.getMouse3DVec(); %cameraPoint = %this.getMouse3DPos(); commandToServer('displaySmoke', %mouseVec, %cameraPoint); }[b]In server\scripts\playGui.cs:[/b] function function serverCmddisplaySmoke(%client, %mouseVec, %cameraPoint) { //Determine how far away from the camera you want the emitter to be placed %rangeScale = 200; // scale mouseVec to the rangeScale %mouseScaled = VectorScale(%mouseVec, %rangeScale); // cameraPoint = the world position of the camera // rangeEnd = camera point + length of selectable range %rangeEnd = VectorAdd(%cameraPoint, %mouseScaled); [b]// %rangeEnd REPRESENTS THE 3D POSITION OF WHERE YOU WANT YOUR PARTICLE EMITTER[/b] smokeEmitter.setTransform(%rangeEnd); }Like I said, this is one way to do it. It may be overkill, but this code is how I set up my mouse selection and grabbing of objects. I've used it for other routines as well.
*EDIT*
Credit goes to Dave Myers and his Object Selection Resource
*EDIT*