Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - .jayderyu

Pages: 1 ... 4 5 [6] 7 8
76
Support / Re: JBullet Quanternion to JPCT Matrix rotation
« on: March 06, 2009, 12:57:47 am »
Thanks, it works better. Still not right thought. Theres no more wierd rotation jerks. It's just that when the box settles on the ground it sits on it's edge. I'm not sure if it's a physics problem or a still a rotation error. I'm also asking at the bullet forums.

To note the matrix translation from TransformWorld in the motionstate also has a rotation matrix. So I was able to use some old code form somewhere on the forums here to get Matrix3fToMatrix(). I noticed a performance increase with this.

If I ever manage to solve this I'll write up a JPCT Physics integration guide just to save new comers some grief on merging the two systems :)

edit: sigh your right, the box isn't Y axis aligned.

77
Support / JBullet Quanternion to JPCT Matrix rotation
« on: March 03, 2009, 03:18:58 pm »
That's right i'm tackling JBullet. Going good except that last few days on working with getting Quat to Euler. I just can't get it to work right. No matter what I do a physics box will always show Object3D primitive Box at an angle with the corner stiking through the floor.

Code: [Select]
import sre.roam.JPCTLib;

import javax.vecmath.Vector3f;
import javax.vecmath.Quat4f;

import com.threed.jpct.SimpleVector;
import com.threed.jpct.Object3D;
import com.threed.jpct.Matrix;

import javabullet.linearmath.MotionState;
import javabullet.linearmath.Transform;


public class JPCTBulletMotionState implements MotionState{
public final Transform graphicsWorldTrans = new Transform();
public final Transform centerOfMassOffset = new Transform();
public final Transform startWorldTrans = new Transform();
 
  private Object3D obj3d;
 
  private float tran_x, tran_y, tran_z; // empty place spots
  private SimpleVector rotate = new SimpleVector();
  private SimpleVector last_rotate = new SimpleVector();
 
  public JPCTBulletMotionState()
  {
graphicsWorldTrans.setIdentity();
centerOfMassOffset.setIdentity();
startWorldTrans.setIdentity();
  }
 
public JPCTBulletMotionState(Transform startTrans)
  {
    this.graphicsWorldTrans.set(startTrans);
centerOfMassOffset.setIdentity();
this.startWorldTrans.set(startTrans);

 
public JPCTBulletMotionState(Transform startTrans, Transform centerOfMassOffset)
  {
    this.graphicsWorldTrans.set(startTrans);
this.centerOfMassOffset.set(centerOfMassOffset);
this.startWorldTrans.set(startTrans);

 
  public void setObject(Object3D obj)
  {
    obj3d = obj;
  }
 
  public void getWorldTransform(Transform worldTrans){
  worldTrans.set(graphicsWorldTrans);
    //worldTrans.inverse(centerOfMassOffset);
    //worldTrans.set(centerOfMassOffset);
//worldTrans.mul(graphicsWorldTrans);
    return;
  }
 
  public void setWorldTransform(Transform worldTrans)
  {
    SimpleVector pos = obj3d.getTransformedCenter();
   
    tran_x = worldTrans.origin.x - pos.x;
    tran_y = worldTrans.origin.y - pos.y;
    tran_z = worldTrans.origin.z - pos.z;
    obj3d.translate(tran_x, tran_y, tran_z);
   
    Quat4f quat = worldTrans.getRotation();
    quat.inverse();
    quat.normalize();
    QuatToEuler(quat);
   
    graphicsWorldTrans.origin.set(tran_x, tran_y, tran_z);

    float rx = last_rotate.x - rotate.x;
    float rz = last_rotate.y - rotate.y;
    float ry = last_rotate.z - rotate.z;
    quat.set(rx,rz,ry, quat.w);
    graphicsWorldTrans.setRotation(quat);

    if(obj3d != null)
    {
      obj3d.rotateX(rx);
      obj3d.rotateY(ry);
      obj3d.rotateZ(rz);
    }
  }


  public void QuatToEuler(Quat4f quat)
  {
  double sqw;
  double sqx;
  double sqy;
  double sqz;

  double rotxrad;
  double rotyrad;
  double rotzrad;

  sqw = quat.w * quat.w;
  sqx = quat.x * quat.x;
  sqy = quat.y * quat.y;
  sqz = quat.z * quat.z;
  rotxrad = (double)Math.atan2(2.0 * ( quat.y * quat.z + quat.x * quat.w ) , ( -sqx - sqy + sqz + sqw ));
  rotyrad = (double)Math.asin(-2.0 * ( quat.x * quat.z - quat.y * quat.w ));
  rotzrad = (double)Math.atan2(2.0 * ( quat.x * quat.y + quat.z * quat.w ) , (  sqx - sqy - sqz + sqw ));
   
    last_rotate.set((float)rotate.x, (float)rotate.y, (float)rotate.z);
  rotate.set((float)rotxrad, (float)rotyrad, (float)rotzrad);
    return;
  }
 
}
The conversion code above has worked in other graphical cases. Other uses of Bullet+Irrelect, Ode and ogre. I just can't get it to work with JBullet and JPCT.


maybe i'm missing something silly. I don't know. So I'm thinking of using cyberkilla skeletal
Matrix.setQuaternionRotation(). Which converts a quat to a float mat[16].
Will changing a quat to a JPCT.Matrix cause any troubles. Will children rotate with the new matrix or will I have to continue with trying to work a way with Object3D.rotate().


78
Support / Re: setting 0 value on object rotation
« on: February 23, 2009, 10:46:06 am »
thanks you so much. I never thought about rotating the objects instead of the dummy.
Code: [Select]
      list[i].rotateX( (float) Math.PI / 2 );
      list[i].rotateY( (float) Math.PI / 2);
      list[i].rotateZ( (float) Math.PI );

This got me exactly what I wanted.

79
Support / setting 0 value on object rotation
« on: February 23, 2009, 08:51:20 am »
I'm not sure how to do this.

I load my 3ds file, but the model loads at a "wrong" angle. I don't have the skill to know what the hell i'm doing in an edit.
What i'm trying to do is rotate the object so it's along the angle I want it. Then set the current values as new 0.

Why. I'm trying to add a camera satellite, but when I do the orientation of the model is so off it's really hard to figure out where to put, rotate the satellite for the camera. So if I can get the objected rotated the right way then add the satellite using 0,0,0 as the starting refernce then it would make my life so much easier.

If I knew more about modeling I would probably model in a target and cam location.

I tried the .setRotationMatrix(new Matrix())
but that just put's it back to the original rotational.

80
Support / Re: Model guide, is there one?
« on: February 21, 2009, 11:02:42 pm »
I thought all children of an object by default were added to the world. Ok I will try that.

Code: [Select]
  public Object3D loadModel(String file, float scale){
    Object3D base = Object3D.createDummyObj();
    Object3D[] list = Loader.load3DS(getResource(file), scale);
   
    for(int i = 0; i < list.length; i++){
      list[i].build();
      base.addChild(list[i]);
    }
   
    return base;
  }


81
Support / Re: Alternative Sky method?
« on: February 21, 2009, 08:27:14 pm »
nope not yet. I'm still playing around with getting some of the other stuff up once. I get moving working I will start playing with the skybox some more.

82
Support / Re: Model guide, is there one?
« on: February 21, 2009, 08:25:54 pm »
Ok I tried the createDummyObj(). added all the bits of the array to it. even built each part though I don't think I need too. added the dummy to th world. and I don't see any form of it.

worrying about the textures later. I just don't see even a grey version of the object.
could I be missing something.

I'm incrementing a zoom out at camera.z -1.0 per cycle just to see if the scale is way out their. after a minute I still don't see anything.



83
Support / Model guide, is there one?
« on: February 21, 2009, 05:59:03 am »
I'm sorry to be a pest. All my projects typicly use Primitive shapes. This is the first time I've tried to use a model. I'm experimenting with a advanced model that I downloaded from the web.

I noticed that the Loader loads an array of Object[]. What I'm wondering is there a guide to this.

Are these Objects attached to each other. Do these objects have ID that corrospond to their editor name?
Will I need to Object[0].add(Object).  how do textures get loaded and applied. Is this automatic or do I have
to go through the Objects.

The model i'm using has 57 materials & textures, 32000 faces and I'm not sure how many parts. I think 50. It's a Obj whatever that editor is from. I'm only using it temporarily until I can get some one to help with some low poly models.

84
Support / Re: Alternative Sky method?
« on: February 21, 2009, 05:52:17 am »
Thanks for your help. It works great. I also found a pretty good reason to use this method. Lighting. When I set the ambient light to low you can't see the sky. If it's too high it can be far to inapropriate for other objects, say space ships should be invisble on the dark side.

I'm sure there are other reasons, but it works.

The only hiccup was that I forgot to invert the skybox :P

85
Support / Re: Alternative Sky method?
« on: February 14, 2009, 04:21:45 am »
So I have been thinking about this.

Currently one form of display would be this
Code: [Select]
   
buffer.clear(Color.blue);   // erase the previous frame
// render the world onto the buffer:
world.renderScene( buffer );
world.draw( buffer );
buffer.update();
buffer.displayGLOnly();
canvas.repaint();

what if
Code: [Select]
buffer.clear(Color.blue);   // erase the previous frame
skyWorld.renderScene( buffer );
skyWorld.draw( buffer );
world.renderScene( buffer );
world.draw( buffer );
buffer.update();
buffer.displayGLOnly();
canvas.repaint();

of course this would require 2 cameras. What's the point of all this.

Well i'v never played with skyboxes much. So I was thinking of using a different skybox rendering system to just play with elements like size, texture res relative to box distance.

86
Support / Alternative Sky method?
« on: February 13, 2009, 01:50:00 pm »
On my searches through opengl 3d forums land I came across a posting about skyboxs. I was wondering if JPCT could support a similiar method.

The idea is that the skybox/dome wasn't very big. say a 4x4x4 box around the camera. All the other objects would sit in an appropriate places in 3d world. Wich would be outside of the skybox. The trick is that the objects would ignore the sorting and render over the skybox. This way you don't need to set anykind of large size for the skybox.

Now I don't know if this will make much of a difference in the grandscheme of sky boxes/domes, but I thought it would be an interesting experiment.

87
Support / Re: How to get Object3D radian?
« on: February 11, 2009, 01:19:48 pm »
Thanks I will look into that.

88
Support / Re: How to get Object3D radian?
« on: February 03, 2009, 07:46:15 am »
thanks, i'm currently using Egon reference. It works well. Though another issue has some up.

Code: [Select]
 // create the box
  box = primitiveFactory:getBox(1.0, 1.01);
  box:translate(10, -100, 0);
  box:rotateX(math.pi / 2);
  box:rotateZ(math.pi / 1.333);
  box:setRotationMatrix(luajava.newInstance("com.threed.jpct.Matrix")); // <-- problem & fix line
  ....
The aforementioned problem&fix line above is the problem. There is a rotation and graphic problem
1. Graphic problem. With the line commented out the box looks fine along the Z camera view.(2d view only no rotate around.)
2. With the line in place the box doesn't isn't orientated right.

1fix. with the line comment out the rotation update doesn't work. I just get an endless super fast rotation.(ref 1 above)
2fix. with the line in the rotation works great.(ref 2 above)

here is the rotation update
Code: [Select]
 // update
  r = playerBody:getRotation();
  angle = _JPCTLib:deriveAngles(player:getRotationMatrix());

  //  Phys2d unfortunatly just adds the total radian making finding the difference unrealist.
  // so setting the radian of angle within 2pi range is forced.
  if(r > (math.pi * 2)) then r = r - (math.pi * 2) end;
  if(r < 0) then r = r + (math.pi * 2) end;
  playerBody:setRotation(r);

  // update the rotation
  shift = r - pAngle.z;
  if(shift ~= 0) then
    player:rotateZ(shift);
  end;

Any suggestions as to why and how to fix it would be helpful.

I also noticed that if I create the new Matrix imidiatly rotating along the Z by 1.333 for orientation doesn't work.

89
Support / How to get Object3D radian?
« on: January 31, 2009, 12:21:09 pm »
Pretty simple question. How do I get the Object3D rotation radian value.

90
Support / Re: GLSL? Egon?
« on: January 30, 2009, 02:00:00 pm »
Thank you very much. I was wondering what had happened to it. We will wait and I won't hold my breath :)

Pages: 1 ... 4 5 [6] 7 8