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.


Topics - .jayderyu

Pages: [1] 2
1
Support / looking for reasonable Object3d net data
« on: February 06, 2010, 02:28:18 pm »
ok so i'm slow an working on my prototype. I've got server/client stuff.. blah blah.

What i'm looking for is rotation data to send in a ByteBuffer. I have jBullet to do most of the work in regards to movement and stuff. I have commands that tell the system to start moving, stopping, turning, stopping.... but I had thought to send sync data with these messages. Looking through Object3D it seems I might have to send a float[16] through system. That seems a bit heavy handed though. I can't really see much data outside of the matrix that I can grab and dump into the remote Object.

2
Support / Texture Splatting for Terrain Texturing
« on: January 30, 2010, 06:40:26 pm »
I was reading up on Oddlabs Procedurality api. I thought it was nifty, while I was reading their talk about game terrain and looking through the api. I noticed there was nothing on texturing. So after some digging around I found out something called Texture Splatting. Visually it meshes with Tribal Trouble and other nice terrain.

http://tribaltrouble.com/screenshots?id=04(I use to use some of their early screen shots as wall paper. When it was just terrain).

Here is I thought a descent reference to how it works.
http://blog.nostatic.org/2007/11/3d-landscape-rendering-with-texture.html

Heres the jist of it as an example.
create a plane say 256x256 by 2units(as meters). That's  512 meters. though size doesn't really matter. Set the UV to tile a textures.

create 2 or more alpha maps. Let's say circles. One is a white circle that slow fades to black. The other is reverse that. Black circle slowly fading to white.
This is a 0-255 alpha map that is translated to a 0-1 as needed.

get 2 textures. one is bumpy grass that is 64x64. or bigger/less. regardless it's a detailed texture that will be tiled. the other can be dirt.

render the plane. texture the plane with the tiled dirt using the white circle alpha map. this results in a dirt circle on the first pass.
on the second texture pass. render the tiling grass texture with the black circle. what happens is that the grass is rendered onto the white alpha values of the surface. Now since both have some grey fade in between both texture will visually create a smooth transition.

I've gone over Object3D. While I could find setAllTextures(String Texture, String bumbmap). I couldn't easily see any way to do alphamaps.

maybe JPCT has something that can do this, but I don't know where I would look.


3
Support / JPCT special effects(Film Grain and Motion Blur)
« on: January 20, 2010, 06:56:22 pm »
ok I'm a bit of a glutton on punishment. I was playing Mass Effect last night and I while I noticed the special effects used. I didn't really think of using them until my current projects.

What I was wondering was are there ways to do Film Grain and Motion Blur. Well Motion Blur more specificly.

I figure Film Grain from what I read. Artificial film grain is a series(2-4) of highly transparent static'y images that are drawn on top of the current buffer. What I was wondering if there was a fast way to blit a transparent buffer onto buffer before drawn to screen and ways to keep in fast. I figure pre sizing it to the current buffer would be best to reduce resize each frame. Or create a specific size grain images.

The other Motion Blur, not a darn idea how I would do it. Well not entire true. My thought was to keep the last image as a background image. Render a new image, back it up as the next frame background. Then transparent it a lot. Then render it on the last frame background. The idea is that farther objects will "blur" more due to greater effect of distance of movement, while closer objects will stay more in "focus".

4
Support / jBullet, a simple how to guide
« on: January 18, 2010, 10:08:56 am »
Hi fine folks of the JPCT boards. I sat back down working on a new project using jBullet physics. So I thought for those of you who are not sure how to get jBullet working. I present this basic guide.

[This is a work in progress code and guide]

Since you have decided to use jBullet I suggest going here http://jbullet.advel.cz/ first. Download the latest version. Integrating straight forward raw physics is easy and won't cause any kind of hair pulling :) at least I've already dealt with part of that hair pulling for you :)

Things to know:
jBullet uses java3D vecmath library. You will need this. Fortunetly it is packed with the jBullet download.

jBullet unit scale by default is a 1:1 meter. Though feel free to scale it as 1 Unit as needed. For safety issues don't create objects less than 0.01. Really big objects also tend to start causing simulation problems if landing on top of smaller objects. IIRC up to 10 is safe.

jBullet uses a Y Z axis and coordinates that are more in line with OGL. This is important as JPCT has opposing  YZ.


Step 1
jBullet uses a dynamic world to handle simulation. Very similar to JPCT world setup. The following code below shows how to get a basic jBullet world. I would explain how this means, but i'm using some one else's API for the sake of time rather that learning how it works. So honestly I can not tell you how it all works.
Code: [Select]
collisionConfiguration = new DefaultCollisionConfiguration();
dispatcher = new CollisionDispatcher(collisionConfiguration);
Vector3f worldAabbMin = new Vector3f(-10000,-10000,-10000);
Vector3f worldAabbMax = new Vector3f(10000,10000,10000);
AxisSweep3 overlappingPairCache = new AxisSweep3(worldAabbMin, worldAabbMax);
SequentialImpulseConstraintSolver solver = new SequentialImpulseConstraintSolver();

dynamicWorld = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
dynamicWorld.setGravity(new Vector3f(0,-10,0));
dynamicWorld.getDispatchInfo().allowedCcdPenetration = 0f;
That's it. It's a little heftier than getting a JPCT world going, but it's not that bad.

Step 2
This is a sample physics test. So we are going to need some objects to collide against. jBullet doesn't support a generic static plane at this time. So we are going to create a box that doesn't move. Obviously if you in a space ship you won't need this :)
Code: [Select]
CollisionShape groundShape = new BoxShape(new Vector3f(100.f, 50.f, 100.f));
Transform groundTransform = new Transform();
groundTransform.setIdentity();
groundTransform.origin.set(new Vector3f(0.f, -56.f, 0.f));
float mass = 0f;
Vector3f localInertia = new Vector3f(0, 0, 0);
  DefaultMotionState myMotionState = new DefaultMotionState(groundTransform);
RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(
mass, myMotionState, groundShape, localInertia);
RigidBody body = new RigidBody(rbInfo);
dynamicWorld.addRigidBody(body);
Time to start explaining what's going on. Some parts are straight forward other parts not so much.

Code: [Select]
CollisionShape groundShape = new BoxShape(new Vector3f(100.f, 50.f, 100.f));Similar to JPCT Box. This defines a simple collision shape. There are spheres and trimesh support if needed.

Code: [Select]
Transform groundTransform = new Transform();
groundTransform.setIdentity();
groundTransform.origin.set(new Vector3f(0.f, -56.f, 0.f));
A Bullet Transform is a Body package of information. It stores both the rotation Matrix and position or translation.
Transform.origin(Vector3f) is where you will find position.
Transform.basis(Matrix3f) is where you will find the bodies rotation.
When a new Transform is created make sure .setIdentity() is run to fill in 0 values.

Code: [Select]
float mass = 0f;
Vector3f localInertia = new Vector3f(0, 0, 0);
Make note of this. A mass of 0 means that the object is static. Static objects will not move in the simulation. Static objects do not need a starting inertia.

Code: [Select]
DefaultMotionState myMotionState = new DefaultMotionState(groundTransform);
This(MotionState) is a key component to integrating physics to your graphical world. The DefaultMotionState has methods you can call on to manually get the data for graphical updates.
DefaultMotionState.graphicsWorldTransform.origin
DefaultMotionState.graphicsWorldTransform.basis
For our purposes though we are using DefaultMotionState for a static object since we don't need to update it's position.

Code: [Select]
RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(
mass, myMotionState, groundShape, localInertia);
RigidBody body = new RigidBody(rbInfo);
dynamicWorld.addRigidBody(body);
Not much to say here. Create a parameter object to create the RigidBody. RigidBody is the equivalent of Object3D. It's important to keep track of it some way. Then finally add a body to the physics world.


Step 3
Static objects are no fun to watch. They don't do anything.  This step which is second to last is where coding get's more fun :)
Code: [Select]
             BoxShape shape = new BoxShape(new Vector3f(2,2,2));
       Vector3f localInertia = new Vector3f(0,0,0);
     shape.calculateLocalInertia(mass, localInertia);

    startTransform = new Transform();
    startTransform.setIdentity();
    startTransform.origin.set(0, 0, 0);
   
    ms = new JPCTBulletMotionState(yourObject3D, startTransform);
   
    rbInfo = new RigidBodyConstructionInfo(mass, ms, shape, localInertia);
    body = new RigidBody(rbInfo);
    body.setRestitution(0.1f);
    body.setFriction(0.50f);
    body.setDamping(0f, 0f);
   
    body.setUserPointer(boxgfx);

    dynamicWorld.addRigidBody(body);
Theres the starting code for your cool fun Bodies :) First create a shape. Our sample we have a 2x2x2 Cube. Makes using JPCT Primitives easier.

Code: [Select]
     
             Vector3f localInertia = new Vector3f(0,0,0);
     shape.calculateLocalInertia(mass, localInertia);
You don't need a separate inertia variable, but I left it in so you know the parameter arguments. The second line is
VERY IMPORTANT  Shape.calculateLocalInertia(float, Vector3f) MUST be called for your physics simulation to work properly. If you miss this after this warning don't rip out your hair for a week*cough* like I did *cough*  :-[

Create a new transform and set starting position and or rotation.

Code: [Select]
ms = new JPCTBulletMotionState(yourObject3D, startTransform);
Here is the magic where jBullet and JPCT will work together. You can find the code at the bottom(with warnings).

Code: [Select]
    body.setRestitution(0.1f);
    body.setFriction(0.50f);
    body.setDamping(0f, 0f);
Fairly basic representation.

Resitution(0.0 to 1.0) represent a value of energy return on collision. Bullet doesn't naturally support infinite return.

Friction(0.0 to 1.0) well roughness. How much sliding. 0 is as slick as possible while 1 should present no sliding.

Damping(0.0 to 1.0) Linear damping and rotation damping. This represents atmosphere. Space has no atmosphere an thus objects will move and rotate forever. While water would be very dense and limit movement and rotation very fast.

Code: [Select]
body.setUserPointer(boxgfx);You don't need this, but depending on you track objects(by physics in this case). You can set a reference to a Object in the body. That way you can call the Object later on with RigidBody.getUserPointer(). Just thought this might help.

Then finally add the body.

Step 4.
Ok you have a static body to check collisions against. You have dynamic RigidBody's that can be watched(I know I didn't show graphic code). Well like JPCT some extra code to move the simulation forward is required.
Code: [Select]
  float ms = clock.getTimeMicroseconds();
  clock.reset();
  dynamicWorld.stepSimulation(ms / 1000000f);
Here it is. It's simple, add it just before your render code. Don't thread it. jBullet has not implemented multi threads yet. This is the basic HelloWorld sample. It uses a timer like clock and steps the simulation based on time difference. There are advanced topics on deterministic physics else where, but this is a good start. Knowing how much time has past since last update.


Test Code

First the basic demo code. This demo code is super basic and was written to run on a AMD 2.6mhz dual core running the software rendered. If your running on less it will run slower. If it's a big different drop the numBoxes value near the top.
Code: [Select]

package jpctbullet;

import com.threed.jpct.*;
import com.threed.jpct.util.Light;

import java.util.Vector;
import java.util.List;
import java.util.ArrayList;
import javax.vecmath.Vector3f;
import javax.swing.*;
import java.awt.*;
import javax.vecmath.Matrix3f;
import javax.vecmath.Matrix4f;

import com.bulletphysics.BulletGlobals;
import com.bulletphysics.collision.broadphase.AxisSweep3;
import com.bulletphysics.collision.dispatch.CollisionObject;
import com.bulletphysics.collision.dispatch.CollisionWorld;
import com.bulletphysics.collision.shapes.BoxShape;
import com.bulletphysics.dynamics.DynamicsWorld;
import com.bulletphysics.dynamics.constraintsolver.Point2PointConstraint;
import com.bulletphysics.dynamics.constraintsolver.TypedConstraint;

import com.bulletphysics.linearmath.*;

import com.bulletphysics.collision.broadphase.BroadphaseInterface;
import com.bulletphysics.collision.broadphase.SimpleBroadphase;
import com.bulletphysics.collision.dispatch.CollisionDispatcher;
import com.bulletphysics.collision.dispatch.DefaultCollisionConfiguration;
import com.bulletphysics.collision.shapes.BoxShape;
import com.bulletphysics.collision.shapes.CollisionShape;
import com.bulletphysics.collision.shapes.StaticPlaneShape;
import com.bulletphysics.dynamics.DiscreteDynamicsWorld;
import com.bulletphysics.dynamics.RigidBody;
import com.bulletphysics.dynamics.RigidBodyConstructionInfo;
import com.bulletphysics.dynamics.constraintsolver.ConstraintSolver;
import com.bulletphysics.dynamics.constraintsolver.SequentialImpulseConstraintSolver;

public class BulletTest {
 
  public int numBoxes = 400;
  public int strHeight= 10;
 
private World world;
private FrameBuffer buffer;
private Object3D box; // only something for the camera to focus on.
private JFrame frame;
 
  public DiscreteDynamicsWorld dynamicWorld;
  public int maxSubSteps;
  public float timeStep, fixedTimeStep;
  protected Clock clock = new Clock();
private List<CollisionShape> collisionShapes = new ArrayList<CollisionShape>();
private BroadphaseInterface overlappingPairCache;
private CollisionDispatcher dispatcher;
private ConstraintSolver solver;
private DefaultCollisionConfiguration collisionConfiguration;
 
  private Vector<RigidBody> boxList;

public static void main(String[] args) throws Exception {
new BulletTest().loop();
}

public BulletTest() throws Exception {
frame=new JFrame("JPCTBullet Test");
frame.setSize(800, 600);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

  boxList = new Vector();  

    int cpu = Runtime.getRuntime().availableProcessors();
    if(cpu > 1){
      Config.useMultipleThreads = true;
      Config.maxNumberOfCores = cpu;
      Config.loadBalancingStrategy = 1;
    }
world = new World();
//World.setDefaultThread( Thread.currentThread() );
world.setAmbientLight(120, 120, 120);

TextureManager.getInstance().addTexture("box", new Texture("box.jpg"));

box = Primitives.getBox(1f, 1f);
box.translate(0, -50, 0);
box.setTexture("box");
box.setEnvmapped(Object3D.ENVMAP_ENABLED);
box.build();
world.addObject(box);

Object3D ground = Primitives.getPlane(4,25);
ground.setTexture("box");
ground.setEnvmapped(Object3D.ENVMAP_ENABLED);
ground.rotateX((float)-Math.PI);
  ground.build();
world.addObject(ground);

world.getCamera().setPosition(150, -50, -5);
world.getCamera().lookAt(box.getTransformedCenter());

Light light = new Light(world);
light.setPosition(new SimpleVector(-200, -50 , 80));
light.setIntensity(150,140,150);


collisionConfiguration = new DefaultCollisionConfiguration();
dispatcher = new CollisionDispatcher(collisionConfiguration);
Vector3f worldAabbMin = new Vector3f(-10000,-10000,-10000);
Vector3f worldAabbMax = new Vector3f(10000,10000,10000);
AxisSweep3 overlappingPairCache = new AxisSweep3(worldAabbMin, worldAabbMax);
//SimpleBroadphase overlappingPairCache = new SimpleBroadphase(1026);
SequentialImpulseConstraintSolver solver = new SequentialImpulseConstraintSolver();

dynamicWorld = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
dynamicWorld.setGravity(new Vector3f(0,-10,0));
dynamicWorld.getDispatchInfo().allowedCcdPenetration = 0f;

CollisionShape groundShape = new BoxShape(new Vector3f(100.f, 50.f, 100.f));
Transform groundTransform = new Transform();
groundTransform.setIdentity();
groundTransform.origin.set(new Vector3f(0.f, -56.f, 0.f));
float mass = 0f;
Vector3f localInertia = new Vector3f(0, 0, 0);
  DefaultMotionState myMotionState = new DefaultMotionState(groundTransform);
RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(
mass, myMotionState, groundShape, localInertia);
RigidBody body = new RigidBody(rbInfo);
dynamicWorld.addRigidBody(body);

dynamicWorld.clearForces();

initTestObects();
}

private void loop() throws Exception {
buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
//Canvas canvas=buffer.enableGLCanvasRenderer();
//buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
//frame.add(canvas);

while (frame.isShowing()) {  
  float ms = clock.getTimeMicroseconds();
  clock.reset();
  dynamicWorld.stepSimulation(ms / 1000000f);
 
  box.rotateY(0.01f); // it's rotating because it looks neater :P
buffer.clear(java.awt.Color.BLUE);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
//buffer.displayGLOnly();
//canvas.repaint();
buffer.display(frame.getGraphics());
//Thread.sleep(10);
}
buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
buffer.dispose();
frame.dispose();
System.exit(0);
}


public void initTestObects(){
  Transform transform;
  Object3D boxgfx;
  BoxShape shape = new BoxShape(new Vector3f(2,2,2));
  JPCTBulletMotionState ms;
  float mass = 2;
  //MotionState ms;
  Vector3f localInertia = new Vector3f(0,0,0);
  shape.calculateLocalInertia(mass, localInertia);
  RigidBodyConstructionInfo rbInfo;
  RigidBody body;
 
  for(int i = 1; i < numBoxes; i++){
      boxgfx = Primitives.getCube(2);
    boxgfx.setTexture("box");
    boxgfx.setEnvmapped(Object3D.ENVMAP_ENABLED);
    boxgfx.build();
    world.addObject(boxgfx);
   
    transform = new Transform();
    transform.setIdentity();
    //transform.origin.set(0, strHeight+(i * 4),(float) (-(numBoxes / 3.3)) + i/2);
    transform.origin.set(0, strHeight+(i * 4),(float) -50 + i/3);
   
    //ms = new DefaultMotionState(transform);
    ms = new JPCTBulletMotionState(boxgfx, transform);
   
    rbInfo = new RigidBodyConstructionInfo(mass, ms, shape, localInertia);
    body = new RigidBody(rbInfo);
    body.setRestitution(0.1f);
    body.setFriction(0.50f);
    body.setDamping(0f, 0f);
   
    body.setUserPointer(boxgfx);
    boxList.add(body);
   
    dynamicWorld.addRigidBody(body);
  } // end for loop

}

}



Heres is the magic code. I must warn that this code is still in work of progress. There is a problem with the rotation. You will see the problem in execution.
Code: [Select]

package jpctbullet;

import javax.vecmath.Vector3f;
import javax.vecmath.Quat4f;
import javax.vecmath.Matrix3f;
import javax.vecmath.Matrix4f;


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

import com.bulletphysics.linearmath.MotionState;
import com.bulletphysics.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;
 
  public JPCTBulletMotionState(Object3D obj)
  {
    obj3d = obj;
graphicsWorldTrans.setIdentity();
centerOfMassOffset.setIdentity();
startWorldTrans.setIdentity();
  }
 
public JPCTBulletMotionState(Object3D obj, Transform startTrans)
  {
    obj3d = obj;
    this.graphicsWorldTrans.set(startTrans);
centerOfMassOffset.setIdentity();
this.startWorldTrans.set(startTrans);

 
public JPCTBulletMotionState(Object3D obj, Transform startTrans, Transform centerOfMassOffset)
  {
    obj3d = obj;
    this.graphicsWorldTrans.set(startTrans);
this.centerOfMassOffset.set(centerOfMassOffset);
this.startWorldTrans.set(startTrans);


  //public void getWorldTransform(Transform worldTrans){
  public Transform getWorldTransform(Transform worldTrans){
  //worldTrans.set(graphicsWorldTrans);
    //worldTrans.inverse(centerOfMassOffset);
    //worldTrans.set(centerOfMassOffset);
//worldTrans.mul(graphicsWorldTrans);
 
worldTrans.inverse(centerOfMassOffset);
worldTrans.mul(graphicsWorldTrans);

//Matrix4f matrix4 = new Matrix4f(obj3d.getRotationMatrix().getDump());
//matrix4.rotX((float)Math.PI);
//matrix4.getRotationScale(worldTrans.basis);// want to place matrix in argument
    return worldTrans;
  }
 
  public void setWorldTransform(Transform worldTrans)
  {
    SimpleVector pos = obj3d.getTransformedCenter();
   
    obj3d.translate(worldTrans.origin.x - pos.x,
  (-worldTrans.origin.y) - pos.y,
  (-worldTrans.origin.z) - pos.z);
   
   
   
    // following rotation may or maynot work. no working rotation to
    // find out and fix.
    float[] ma = new float[4];
    float[] dump = new float[16]; //obj3d.getRotationMatrix().getDump();
    Matrix4f matrix4 = new Matrix4f();
    Matrix matrixGfx = new Matrix();
   
    matrix4.set(worldTrans.basis); // want to set current matrix by arg
   
    matrix4.getRow(0, ma);
    dump[0] = ma[0]; dump[1] = ma[1]; dump[2] = ma[2]; dump[3] = ma[3];
    matrix4.getRow(1, ma);
    dump[4] = ma[0]; dump[5] = ma[1]; dump[6] = ma[2]; dump[7] = ma[3];
    matrix4.getRow(2, ma);
    dump[8] = ma[0]; dump[9] = ma[1]; dump[10] = ma[2]; dump[11] = ma[3];
    matrix4.getRow(3, ma);
    dump[12] = ma[0]; dump[13] = ma[1]; dump[14] = ma[2]; dump[15] = ma[3];
   
    /*
    Matrix3f matrix3 = worldTrans.basis;
    matrix3.normalize();
    matrix3.getRow(0, ma);
    dump[0] = ma[0]; dump[1] = ma[1]; dump[2] = ma[2];// dump[3] = ma[3];
    matrix3.getRow(1, ma);
    dump[4] = ma[0]; dump[5] = ma[1]; dump[6] = ma[2];// dump[7] = ma[3];
    matrix3.getRow(2, ma);
    dump[8] = ma[0]; dump[9] = ma[1]; dump[10] = ma[2];// dump[11] = ma[3];
    */
    matrixGfx.setDump(dump);
    matrixGfx.rotateX((float)Math.PI);
   
    obj3d.setRotationMatrix(matrixGfx);
  }

}



Here is the source. I have limited bandwidth so don't download to much please :) Also server sometimes goes down. So just be patient and it will be up. Usually less than a day.
http://sre.hopto.org/share/jBulletTest.zip



5
Support / Silly Matrix question
« on: January 15, 2010, 12:51:24 am »
It's a simple answer to those that know, but i'm a bit of a Matrix twit :\   

JPCT has a different Y Z axis on a rotation. In an Object3D.getDump().
How would I change it to mirror the YZ value.

My thought was some thing like this.
Code: [Select]
[0,    *-1, *-1,  0]
[*-1, *-1,    0,  0]
[*-1,    0, *-1,  1]
[   0,    0,    0,  0]
The idea was flipping the values for YZ rotation assuming row major. I think. I've been searching the web so I'm more guessing.

6
Feedback / Thanks for JPCT
« on: November 14, 2009, 03:38:13 pm »
I wanted to say thanks for JPCT. It is an excellent 3d api for getting things going. I've been able to see some of my ideas come to work a bit. It's easy to use, small and efficient. I tried using JME for an applet once. It weighed at about 2mb after all required libs were in place. JPCT is just awesome.

As for me not always being here.  I'm just wishy washy :P jumping from idea to idea. Currently i'm working on some of my server stuff for a 2d game idea. Maybe I'll show horn 2d engine from jpct.

7
Support / How to stream a City priority LOD?
« on: May 22, 2009, 12:34:39 am »
There was another discussion about height maps that got to me thinking about this again. What would be the best way to get a GTA like City world working. While maintaining a 1:1 meter ratio(since I would use a physics engine like JBullet).

I've had some thoughts on the matter. Breaking it up into a grid to load, but some objects would have a massive priority. Like massive buildings would still be seen from a far distance. It would make me think that I would have to process to much of the grid at one time. How would I keep all of this spacially related in the JPCT world where the meters would be limited to float.

I'm not saying I'm going to start something like this anytime soon, but this has been mulling in my mind for a few years now.



8
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().


9
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.

10
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.

11
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.

12
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.

13
Support / GLSL? Egon?
« on: January 30, 2009, 10:27:07 am »
I was looking over some older forum posts to see if anyone managed to get shaders going. I found a thread from feb 9,2008 mentioning that Egon was going to add support for a render path in the pipleline. Did this ever happen? do we have some form of shader support or did it require to much of a change within in the system?

14
Support / Brute reset
« on: January 28, 2009, 04:39:54 am »
Hi i'm back after needing to focus on some physics issues that came up.

Ok this seems a little simple and rather brute force ish. I am trying to recreate World for an initilizing and at the moment I'm looking for the simplest removal and reinitilize.

I have done a
world.dispose();
buffer.dispose();
...
world = new World();
... redoing all everything

what happens is that I am left with the last frame and nothing updates.
I know there is updating going because my window for the 2d physics is works fine.

15
Support / Camera matching Object3d Z Axis
« on: January 07, 2009, 12:33:44 am »
Ok so things are mostly going well. Outside of the other thread.

I've tried playing around with some of the axis, vectors, alligning.... but I can't seem to figure out how to make it work.

I'm trying to get the camera Z roation(ie looking at it from a 2d perspective) to rotate with the target object. So if I flip the target object upside down through rotation. I want the camera to match. So it seems like the object always is upright.

Pages: [1] 2