Game Development Community

dev|Pro Game Development Curriculum

pimp out your world editor: 1 key forced select axis for move/rotate

by Charles B · 02/23/2006 (10:52 am) · 6 comments

Download Code File

The stock world editor setup is not something that I liked.
You need to move around to grab an axis when rotation and moving objects which gets real old quickly.

after you modify your source, you will be able to move/rotation objects on a specify axis by pressing one key.

the default setup is:

f key to force rotate x axis
g key to force rotate y axis
j key to force rotate z axis

v key to force move x axis
b key to force move y axis
n key to force move z axis

m key to use netgraph

if you press a force key twice in a row, you will switch back to stock
tge world editor mode.

you can tell you're in force mode since on screen you'll see something
like FMX on the axis thing drawn on your object.
F means force
M means move
R means rotate
X means force on x axis

some possible things you can see are FMX,FMY,FMZ,FRX,FRY,FRZ.
if you dont see FMX on the axis thingy, then you are in stock tge world editor mode. So the old ways of rotating/moving apply.

included with this resouce is a tar gz.
inside you will find the files that I used in torque 130 and 140.
I tested this code change & files on linux.

If you want to manually add the code changes they are listed here:
##########################################
in torque/engine/editor/worldEditor.h


near the top of the file, before the line:
class Path;

add these lines:

// ccb-pimp-my-editor codeblockadd START:
const S32 CCB_FNONE = 0;
const S32 CCB_FRX = 1;
const S32 CCB_FRY = 2;
const S32 CCB_FRZ = 3;
const S32 CCB_FMX = 4;
const S32 CCB_FMY = 5;
const S32 CCB_FMZ = 6;
// ccb-pimp-my-editor codeblockadd ^^^ END


##########################################
in torque/engine/editor/worldEditor.h

about line 200,

after the line:
bool mUsingAxisGizmo;

add these lines:

// ccb-pimp-my-editor codeblockadd START:
S32 mccbForcedAxisValue; // ccb-pimp-my-editor code add
bool mccbForceModeFlag; // ccb-pimp-my-editor code add
S32 mccbLastForcedOp; // ccb-pimp-my-editor code add
// ccb-pimp-my-editor codeblockadd ^^^ END


##########################################
in torque/engine/editor/worldEditor.cc

near line 1457,

comment out these 2 lines:

char buf[2];
buf[0] = axisText[i]; buf[1] = '\0';


add these lines:

// ccb-pimp-my-editor codeblockadd START:
char buf[4];
if (mccbForceModeFlag == true) {
buf[0]='F';
buf[1]='R';

if ( mccbLastForcedOp > CCB_FNONE && mccbLastForcedOp < CCB_FMX ) buf[1] = 'R';
else
if ( mccbLastForcedOp > CCB_FRZ && mccbLastForcedOp <= CCB_FMZ ) buf[1] = 'M';

if (mccbForcedAxisValue == 0) {
buf[2]='X';
}
else if (mccbForcedAxisValue == 1) {
buf[2]='Y';
}
else buf[2]='Z';

buf[3]='\0';
}
else {
buf[0] = axisText[i]; buf[1] = '\0';
} //end else // ccb-pimp-my-editor code add
// ccb-pimp-my-editor codeblockadd ^^^ END

##########################################
in torque/engine/editor/worldEditor.cc

near line 1663 or the end of the constructor:
"WorldEditor::WorldEditor()"

add these lines:

// ccb-pimp-my-editor codeblockadd START:
mccbForcedAxisValue = 0; //x axis //ccb-pimp-my-editor code add
mccbForceModeFlag = false; // ccb-pimp-my-editor code add
mccbLastForcedOp = CCB_FNONE; // ccb-pimp-my-editor code add
// ccb-pimp-my-editor codeblockadd ^^^ END

##########################################
in torque/engine/editor/worldEditor.cc

in method:
void WorldEditor::on3DMouseDragged(const Gui3DMouseEvent & event)

near line 1977

above this line:
if(!mMouseDragged)

add these lines:

// ccb-pimp-my-editor codeblockadd START:
if (mccbForceModeFlag == true) {
mUsingAxisGizmo = true;
}
// ccb-pimp-my-editor codeblockadd ^^^ END

##########################################
in torque/engine/editor/worldEditor.cc

in method:
void WorldEditor::on3DMouseDragged(const Gui3DMouseEvent & event)

near line 2029

before:
switch(mCurrentMode)

add these lines:

// ccb-pimp-my-editor codeblockadd START:
if (mccbForceModeFlag == true) {
mUsingAxisGizmo=true;
if ( mccbLastForcedOp > CCB_FNONE && mccbLastForcedOp < CCB_FMX ) mCurrentMode = Rotate;
else
if ( mccbLastForcedOp > CCB_FRZ && mccbLastForcedOp <= CCB_FMZ ) mCurrentMode = Move;
}
// ccb-pimp-my-editor codeblockadd ^^^ END

##########################################
in torque/engine/editor/worldEditor.cc

in method:
void WorldEditor::on3DMouseDragged(const Gui3DMouseEvent & event)

near line 2048 // inside the move case

after the line:
Point3F projPnt = mHitCentroid;;

add these lines:

// ccb-pimp-my-editor codeblockadd START:
if (mccbForceModeFlag == true) {
mAxisGizmoSelAxis = mccbForcedAxisValue;
}
// ccb-pimp-my-editor codeblockadd ^^^ END

##########################################
in torque/engine/editor/worldEditor.cc

in method:
void WorldEditor::on3DMouseDragged(const Gui3DMouseEvent & event)

near line 2340 // inside the rotate case

after the line:
axis = mAxisGizmoSelAxis;

add these lines:
// ccb-pimp-my-editor codeblockadd START:
if (mccbForceModeFlag == true) {
axis = mccbForcedAxisValue;
}
// ccb-pimp-my-editor codeblockadd ^^^ END

##########################################
in torque/engine/editor/worldEditor.cc

in method:
bool WorldEditor::setMode(const char* mode)

near line 2686

after this line:
mCurrentMode = WorldEditor::Scale;

add these lines:

// ccb-pimp-my-editor codeblockadd START:
else if(!dStricmp(mode, "FRX")) {
if (mccbForceModeFlag == false || ((mccbForceModeFlag == true)&&(mccbLastForcedOp != CCB_FRX)) ) {
mCurrentMode = WorldEditor::Rotate;
mccbForceModeFlag = true;
mccbForcedAxisValue = 0; // x? 2=z
mccbLastForcedOp = CCB_FRX;
}
else mccbForceModeFlag = false;
}
else if(!dStricmp(mode, "FRY")) {
if (mccbForceModeFlag == false || ((mccbForceModeFlag == true)&&(mccbLastForcedOp != CCB_FRY)) ) {
mCurrentMode = WorldEditor::Rotate;
mccbForceModeFlag = true;
mccbForcedAxisValue = 1; // x? 2=z
mccbLastForcedOp = CCB_FRY;
}
else mccbForceModeFlag = false;
}
else if(!dStricmp(mode, "FRZ")) {
if (mccbForceModeFlag == false || ((mccbForceModeFlag == true)&&(mccbLastForcedOp != CCB_FRZ)) ) {
mCurrentMode = WorldEditor::Rotate;
mccbForceModeFlag = true;
mccbForcedAxisValue = 2; // x? 2=z
mccbLastForcedOp = CCB_FRZ;
}
else mccbForceModeFlag = false;
}
else if(!dStricmp(mode, "FMX")) {
if (mccbForceModeFlag == false || ((mccbForceModeFlag == true)&&(mccbLastForcedOp != CCB_FMX)) ) {
mCurrentMode = WorldEditor::Move;
mccbForceModeFlag = true;
mccbForcedAxisValue = 0; // x? 2=z
mccbLastForcedOp = CCB_FMX;
}
else mccbForceModeFlag = false;
}
else if(!dStricmp(mode, "FMY")) {
if (mccbForceModeFlag == false || ((mccbForceModeFlag == true)&&(mccbLastForcedOp != CCB_FMY)) ) {
mCurrentMode = WorldEditor::Move;
mccbForceModeFlag = true;
mccbForcedAxisValue = 1; // x? 2=z
mccbLastForcedOp = CCB_FMY;
}
else mccbForceModeFlag = false;
}
else if(!dStricmp(mode, "FMZ")) {
if (mccbForceModeFlag == false || ((mccbForceModeFlag == true)&&(mccbLastForcedOp != CCB_FMZ)) ) {
mCurrentMode = WorldEditor::Move;
mccbForceModeFlag = true;
mccbForcedAxisValue = 2; // x? 2=z
mccbLastForcedOp = CCB_FMZ;
}
else mccbForceModeFlag = false;
}
// ccb-pimp-my-editor codeblockadd ^^^ END

##########################################
in this change, you can pick whatever keys you want but I list the changes i made:

in file torque/example/starter.fps/client/scripts/default.bind.cs
at the end of the file,

note the change netgraph key bind from 'n' to 'm'.

add these lines:

//moveMap.bindCmd(keyboard, "n", "NetGraph::toggleNetGraph();", ""); //ccb pimp my world editor
moveMap.bindCmd(keyboard, "m", "NetGraph::toggleNetGraph();", ""); //ccb pimp my world editor
moveMap.bindCmd(keyboard, "f", "$ccbWorldEditor.setMode(\"FRX\");", ""); //ccb pimp my world editor
moveMap.bindCmd(keyboard, "g", "$ccbWorldEditor.setMode(\"FRY\");", ""); //ccb pimp my world editor
moveMap.bindCmd(keyboard, "h", "$ccbWorldEditor.setMode(\"FRZ\");", ""); //ccb pimp my world editor

moveMap.bindCmd(keyboard, "v", "$ccbWorldEditor.setMode(\"FMX\");", ""); //ccb pimp my world editor
moveMap.bindCmd(keyboard, "b", "$ccbWorldEditor.setMode(\"FMY\");", ""); //ccb pimp my world editor
moveMap.bindCmd(keyboard, "n", "$ccbWorldEditor.setMode(\"FMZ\");", ""); //ccb pimp my world editor

##########################################
ONLY CHANGE for torque 1.4.0
in file torque/example/creator/editor/EditorGui.cs

in function:
function EditorGui::init(%this)

line 243

after this line:
EditorGui.saveAs = false;

add this line:
$ccbWorldEditor = EWorldEditor; //ccb pimp my world editor


##########################################
ONLY CHANGE for torque 1.3.0

in file torque/example/common/editor/EditorGui.cs

in function:
function EditorGui::init(%this)

after this line:
EditorGui.saveAs = false;

add this line:
$ccbWorldEditor = EWorldEditor; //ccb pimp my world editor

About the author

Recent Blogs


#1
02/23/2006 (10:32 am)
Neat looking resource, but it might help if you applied some nicer formatting to it... ;)
#2
02/23/2006 (11:40 am)
Hey nice, Maybe some day the world editor will get some nice rotate gizmo's "hint,hint" ;P
#3
02/23/2006 (1:09 pm)
Ar luv yoo ar do :-) (best Yorkshire accent)

I've been hoping for something like this. I don't get on with the current system.

Now all I need is for someone to make a 4 window view (top,left,front,3D) for the world editor ;-)
#4
02/23/2006 (7:00 pm)
Excellent resource. I just implemented and tested it out and it works great!
#5
02/27/2006 (3:14 pm)
This is much needed! And we do need a better rotate/scale system.
#6
03/06/2006 (1:16 pm)
On PC, I had to add the binds to editor.binds.cs for making this work.

Regards

Berndt