A Little help!

Discussion about Irrlicht's Java wrapper

A Little help!

Postby renegadeandy » Wed Aug 06, 2008 9:20 pm

Alright it was because I was using the wrong dll version!

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)
   }

   
}



The bits in particular im stuck with is this :

Code: Select all
public void recalculateViewArea()
   {
      ViewArea.setCameraPosition(getAbsolutePosition());
      ViewArea.setFrom ( ViewArea.getMatrices());//wrong , what do i do here!
   }


The original was :

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!
Last edited by renegadeandy on Fri Aug 08, 2008 4:52 pm, edited 1 time in total.
renegadeandy
 
Posts: 122
Joined: Sun May 25, 2008 11:14 pm
Location: Scotland

Postby Serg Nechaeff » Fri Aug 08, 2008 4:28 am

Sorry mate, I can not be of any help at the moment for that particular problem. Good luck.
http://www.javazing.com
P-III-950, WinXP, GeForce FX5600 128 MB ForceWare 52.16, DX9, Eclipse IDE, JRE 1.6
Serg Nechaeff
 
Posts: 162
Joined: Wed Nov 26, 2003 5:24 pm
Location: Europe

Postby renegadeandy » Fri Aug 08, 2008 9:53 am

Ahh! please somebody help me - it cannot be that hard. there must be a way!

Andy
renegadeandy
 
Posts: 122
Joined: Sun May 25, 2008 11:14 pm
Location: Scotland

Postby jirr » Sat Aug 09, 2008 12:08 am

Ah, I see the problem. This is a bug in jirr. It should return an array of matrix4 but only returns one matrix4 element.
Will try to fix that for jirr 1.4.x.
jirr
 
Posts: 36
Joined: Sat Feb 19, 2005 8:05 am

Postby renegadeandy » Sat Aug 09, 2008 12:11 am

Ahh!

Thanks Jirr this is wonderful news - it proves im not overlooking something obvious! When do you think the 1.4 release will happen?

Is there any other way I can contact you quickly, like an IM like yahoo or msn or aol or anything (you could pm me then =D)- its just im using jirr a lot and could provide quite a bit of decent feedback and i also have a lot of questions - for instance i thought i was doing something wrong there, when i wasnt!

Thanks very much,

Andy
renegadeandy
 
Posts: 122
Joined: Sun May 25, 2008 11:14 pm
Location: Scotland

Postby jirr » Sun Oct 05, 2008 11:30 am

Just to inform you at first hand: Jirr 1.4.2 will be released by the end of this month (planned).
jirr
 
Posts: 36
Joined: Sat Feb 19, 2005 8:05 am


Return to Jirr

Who is online

Users browsing this forum: No registered users and 0 guests