Anyways - I am wanting to try and convert an RTSCamera class i was using in my old cpp days - the code is as follows :
http://pastebin.com/m324780e9
I have done quite a bit but have got stuck , here is what i have so far:
Code: Select all
package camera;
import net.sf.jirr.*;
public class RTSCamera extends ICameraSceneNode{
ISceneManager smgr;
IrrlichtDevice device;
vector3df Target;
vector3df UpVector;
matrix4 Projection;
matrix4 View;
SViewFrustum ViewArea;
aabbox3df BBox;
boolean InputReceiverEnabled;
dimension2df screenDim;
float Fovy; // Field of view, in radians.
float Aspect; // Aspect ratio.
float ZNear; // value of the near view-plane.
float ZFar; // Z-value of the far view-plane.
vector3df Pos;
boolean zooming, rotating, moving, translating;
float zoomSpeed;
float translateSpeed;
float rotateSpeed;
float rotateStartX, rotateStartY;
float zoomStartX, zoomStartY;
float translateStartX, translateStartY;
float currentZoom;
float rotX, rotY;
vector3df oldTarget;
vector2df MousePos;
boolean[] Keys;
boolean[] MouseKeys;
float targetMinDistance;
float targetMaxDistance;
//Public Attributes
boolean atMinDistance;
boolean atMaxDistance;
ISceneNode selectednode;
boolean movingForward;
boolean movingBackward;
public RTSCamera(IrrlichtDevice device,ISceneNode parent, ISceneManager smgr, int id, float rs, float zs, float ts){
this.device = device;
this.smgr = smgr;
BBox = new aabbox3df();
BBox.reset(0,0,0);
UpVector = new vector3df();
UpVector.set(0.0f, 1.0f, 0.0f);
Fovy = (float)Math.PI / 2.5f; // Field of view, in radians.
Aspect = 4.0f / 3.0f; // Aspect ratio.
ZNear = 1.0f; // value of the near view-plane.
ZFar = 100000.0f; // Z-value of the far view-plane.
Keys = new boolean[EKEY_CODE.valueOf("KEY_KEY_CODES_COUNT").swigValue()];
MouseKeys = new boolean[3];
IVideoDriver d = smgr.getVideoDriver();
if (d != null) {
Aspect = d.getCurrentRenderTargetSize().getWidth() / d.getCurrentRenderTargetSize().getHeight();
}
Target = new vector3df();
zooming = false;
rotating = false;
moving = false;
translating = false;
zoomSpeed = zs+4;
rotateSpeed = rs;
translateSpeed = ts+4;
targetMinDistance = 1.0f;
targetMaxDistance = 2000.0f;
Target.set(0.0f,0.0f,0.0f);
rotX = 0;
rotY = 0;
oldTarget = Target;
movingForward = false;
movingBackward = false;
atMinDistance = false;
atMaxDistance = false;
smgr.setActiveCamera(this);
}
public boolean OnEvent(SEvent event)
{
IBillboardSceneNode node = null;
System.out.println("bark like a dog");
if (!InputReceiverEnabled)
return false;
dimension2di ssize = smgr.getVideoDriver().getScreenSize();
if(event.getEventType() == EEVENT_TYPE.EET_MOUSE_INPUT_EVENT)
{
switch(event.getMouseInputEvent())
{
case EMIE_MMOUSE_PRESSED_DOWN :
selectednode = smgr.getSceneCollisionManager().getSceneNodeFromScreenCoordinatesBB(device.getCursorControl().getPosition());
//POSSIBLE PROBLEM HERE WITH THE GET TYPE COMPARISON!
if(selectednode != null && selectednode.getType() == node.getType())
{
pointCameraAtNode(selectednode);
}
else
{
selectednode = null;
MouseKeys[0] = true;
}
break;
case EMIE_RMOUSE_PRESSED_DOWN:
MouseKeys[2] = true;
break;
case EMIE_LMOUSE_PRESSED_DOWN:
MouseKeys[1] = true;
break;
case EMIE_LMOUSE_LEFT_UP:
MouseKeys[0] = false;
break;
case EMIE_RMOUSE_LEFT_UP:
MouseKeys[2] = false;
break;
case EMIE_MMOUSE_LEFT_UP:
// MouseKeys[1] = false;
MouseKeys[0] = false;
break;
case EMIE_MOUSE_MOVED:
{
IVideoDriver driver = smgr.getVideoDriver();
if (driver != null)
{
MousePos.setX(event.getMouseInputX() / (float)ssize.getWidth());
MousePos.setY(event.getMouseInputY() / (float)ssize.getHeight());
}
}
break;
case EMIE_MOUSE_WHEEL:
currentZoom -= event.getMouseInputWheel() * zoomSpeed;
break;
default:
break;
}
return true;
}
if(event.getEventType() == EEVENT_TYPE.EET_KEY_INPUT_EVENT)
{
Keys[event.getKeyInputChar()] = event.isKeyInputPressedDown();
return true;
}
return false;
}
public void pointCameraAtNode(ISceneNode selectednode)
{
vector3df totarget = getPosition().assignMinusOperator(getTarget());
setPosition(selectednode.getPosition().assignPlusOperator((totarget.normalize().assignTimesOperator(100))));
setTarget(selectednode.getPosition());
updateAnimationState();
}
public void updateAnimationState()
{
vector3df pos = new vector3df(Pos.assignMinusOperator(Target));
// X rotation
vector2df vec2d = new vector2df(pos.getX(), pos.getZ());
rotX = (float)vec2d.getAngle();
// Y rotation
pos.rotateXZBy(rotX, new vector3df());
vec2d.set(pos.getX(), pos.getY());
rotY = -(float)vec2d.getAngle();
// Zoom
currentZoom = Pos.getDistanceFrom(Target);
}
public void OnRegisterSceneNode()
{
vector3df pos = getAbsolutePosition();
vector3df tgtv = Target.assignMinusOperator(pos);
tgtv.normalize();
vector3df up = UpVector;
up.normalize();
float dp = tgtv.dotProduct(up);
//dp needs to be fabs(dp)?
if( Jirr.equals( dp, 1.f ) )
{
up.setX(up.getX()+ 0.5f);
}
//was viewArea.Matrices [ ets_view] . build camera
ViewArea.getMatrices().buildCameraLookAtMatrixLH(pos, Target, up);
ViewArea.setTransformState (E_TRANSFORMATION_STATE.ETS_VIEW);
recalculateViewArea();
if( SceneManager->getActiveCamera () == this )
SceneManager->registerNodeForRendering(this, ESNRP_CAMERA);
if(IsVisible)
ISceneNode::OnRegisterSceneNode();
}
public void recalculateViewArea()
{
ViewArea.setCameraPosition(getAbsolutePosition());
ViewArea.setFrom ( ViewArea.Matrices [ SViewFrustum::ETS_VIEW_PROJECTION_3 ] );
ViewArea.setFrom(arg0)
}
}
Code: Select all
public void recalculateViewArea()
{
ViewArea.setCameraPosition(getAbsolutePosition());
ViewArea.setFrom ( ViewArea.getMatrices());//wrong , what do i do here!
}
Code: Select all
void RTSCamera::recalculateViewArea()
{
ViewArea.cameraPosition = getAbsolutePosition();
ViewArea.setFrom ( ViewArea.Matrices [ SViewFrustum::ETS_VIEW_PROJECTION_3 ] );
}
I would be seriously grateful! As you can see my attempt does not work - the getMatrices() function doesnt return an array of matrices, it returns a matrix4 object, so how can i reference ETS_VIEW_PROJECTION_3 on this!!!
Please help!
Thanks in advance for any help!