Game Development Community

Looking to test out an algorithm

by Philip Gregory · in Torque 3D Professional · 02/22/2012 (11:28 pm) · 25 replies

I've thought up an interesting new algorithm I want to try out--the only problem is, I can't find where I need to start in the source or script files. Without previewing what I'm trying to do (I wanna use this for a learning experience and release it as a resource), I want to write a function for the object editor that will affect selected object(s) when used a hot key (that I also want to code in).

If you know where I need to look in the source or script files, I would greatly appreciate it!

Thanks!

About the author

Yes... Those are ribs. Current projects: Breaking out of the box in T2D, devoting efforts and talents to Middle School student tech projects (including basic Python programming!)

Page«First 1 2 Next»
#21
02/29/2012 (4:13 am)
I do think the final, polished code would be a great asset for anyone to have if it makes you feel better :p
#22
02/29/2012 (7:56 am)
I usually spend most of my programming time correcting small typos that cripple an entire section of my game :) This is a victory. I might go ahead and resource this tonight.
#23
02/29/2012 (8:07 am)
Would you like me to post the final version of the code I put in? It has your fixes, plus some removed ditto coding and fixed typos.
#24
02/29/2012 (8:17 am)
Be my guest!
#25
03/01/2012 (4:04 am)
Here it is. It still needs binded (I prefer CRTL + Insert) and if it could select the new object so it can keep continuing it'd be great.

//K001Beta Steak's Object Duplication Algorithm performed in Torque Script by Bryce
function objectDuplicationSnapping(%obj)  
    {  
       // Get selected object  
       %obj = $editorObj;  
         
       // Figure out which way the cam is facing  
       %dir = "";  
       %bestRatio = 0;  
       %camVec = LocalClientConnection.camera.getForwardVector();  
       %camVec = VectorNormalize(%camVec);  
       //--- Left?  
       %left = "-1 0 0";  
       %leftDot = VectorDot(%camVec,%left);  
       if (%leftDot / 1 > %bestRatio)  
       {  
         %dir = "left";  
         %bestRatio = %leftDot / 1;  
       }  
       //--- Right?  
       %right = "1 0 0";  
       %rightDot = VectorDot(%camVec,%right);  
       if (%rightDot / 1 > %bestRatio)  
       {  
         %dir = "right";  
         %bestRatio = %rightDot / 1;  
       }  
       //--- Up?  
       %up = "0 0 1";  
       %upDot = VectorDot(%camVec,%up);  
       if (%upDot / 1 > %bestRatio)  
       {  
         %dir = "up";  
         %bestRatio = %upDot / 1;  
       }  
       //--- Down?  
       %down = "0 0 -1";  
       %downDot = VectorDot(%camVec,%down);  
       if (%downDot / 1 > %bestRatio)  
       {  
         %dir = "down";  
         %bestRatio = %downDot / 1;  
       }  
       //--- front?  
       %front = "0 1 0";  
       %frontDot = VectorDot(%camVec,%front);  
       if (%frontDot / 1 > %bestRatio)  
       {  
         %dir = "front";  
         %bestRatio = %frontDot / 1;  
       }  
       //--- back?  
       %back = "0 -1 0";  
       %backDot = VectorDot(%camVec,%back);  
       if (%backDot / 1 > %bestRatio)  
       {  
         %dir = "back";  
         %bestRatio = %backDot / 1;  
       }  
         
       %dupVec = "0 0 0";  
       if (%dir $= "Left")  
         %dupVec = %left;  
       else if (%dir $= "Right")  
         %dupVec = %right;  
       else if (%dir $= "Up")  
         %dupVec = %up;  
       else if (%dir $= "Down")  
         %dupVec = %down;  
       else if (%dir $= "Front")  
         %dupVec = %front;  
       else if (%dir $= "Back")  
         %dupVec = %back;  
           
       // Alright, now with that out of the way...  
       // The object should be moved in the direction of "%dupVec"  
         
       // Duplicate the object:  
       // This assumes we're trying to copy a TSStatic.  
         
       // %clone = new (%obj.getClassName()) {   
          //  ^^^ I wonder if that'd work too...  
           %clone = new TSStatic() {  
          shapeName = %obj.shapeName;  
          position = "0 0 0";  
          rotation = %obj.rotation;  
       };  
         
       // Get the original object's size from its box.  
       // Let's do this based on the direction we're moving it.  
       %size = 0;  
       %box = %obj.getWorldBox();  
       if (%dir $= "Left" || %dir $= "Right") // X-Axis  
       {  
          %v1 = getWord(%box,0);  
          %v2 = getWord(%box,3);  
          %size = mAbs(%v1 - %v2);  
       }  
       if (%dir $= "Front" || %dir $= "Back") // Y-Axis  
       {  
          %v1 = getWord(%box,1);  
          %v2 = getWord(%box,4);  
          %size = mAbs(%v1 - %v2);  
       }  
       if (%dir $= "Down" || %dir $= "Up") // Z-Axis  
       {  
          %v1 = getWord(%box,2);  
          %v2 = getWord(%box,5);  
          %size = mAbs(%v1 - %v2);  
       }  
         
       // Almost done here!  
       // Now we figure out where to place the duplicate.  
       %offsetVec = VectorScale(VectorNormalize(%dupVec),%size);  
       %position = VectorAdd(%obj.getPosition(),%offsetVec);  
         
       %clone.setTransform(%position);  
         
       // Winner?  
    }
Page«First 1 2 Next»