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 - AugTech

Pages: 1 2 [3] 4 5
31
Support / Re: Ground clamping through calcMinDistance with .obj's help
« on: February 09, 2013, 03:59:17 pm »
Hold on... Am just working through more methodically and it appears my maths is crap!
I think the additional confusion is that child translations are 'forgotten' when the parent is translated - could you just confirm this Egon?

32
Support / Re: Ground clamping through calcMinDistance with .obj's help
« on: February 09, 2013, 02:37:41 pm »
Ok, my apologise, the -20 confused things. Replace the -20 with the value I'm getting from calcMinDistance

So;

Code: [Select]
SimpleVector upAxis = sceneOrientation.up.normalize();
SimpleVector frontAxis = sceneOrientation.front.normalize();
SimpleVector trans = new SimpleVector();

obj.setOrientation(frontAxis, upAxis);
obj.build();
theWorld.addObject( obj );

float dist = plane.calcMinDistance( obj.getTransformedCenter(), upAxis );
trans.set( upAxis );
trans.scalarMul( dist );
obj.translate( trans );

results in objects being translated in different directions

33
Support / Re: Ground clamping through calcMinDistance with .obj's help
« on: February 09, 2013, 01:41:28 pm »
Thats actually what I thought I was doing with;

Code: [Select]
trans.set( upAxis );
trans.scalarMul( -20f );//Distance to move
obj.translate( trans );

Would the translation vector have to added/ multiplied by the object axis?

34
Support / Re: Ground clamping through calcMinDistance with .obj's help
« on: February 09, 2013, 11:21:52 am »
Egon, I tried the getWorldBounds() method and get slightly different numbers/ distances, but the objects still translate in odd directions.

This, plus some sleep has made me realise (hopefully) the root of all my evil...
The objects are getting checked for distance on the arbitrary axis I'm providing (sceneOrientation.up), but are still being translated on the world axis (or possibly standard object axis), not the axis I'm providing.

Is it possibly to rotate the world axis? - I'll tell you why!

The sceneOrientation.up and sceneOrientation.front vectors define the orientation of the axis for all objects within the world, with the world camera orientation being set constantly through two similar/ relative vectors, so that the user POV is aligned with the ground within the world. But these axis are not static, they are created dynamically on top of a sphere (the world).
My world space is the green square in this diagram;

So I either need to translate objects according to these arbitrary axis, or rotate and lock the world axis so all objects obey them... Does this make sense?!  :-\

35
Support / Ground clamping through calcMinDistance with .obj's help
« on: February 08, 2013, 07:33:19 pm »
Hi all !
I'm trying to implement two things at the moment, and after three days its still driving me nuts! >:(

Firstly, and most importantly, I'm trying to automatically 'clamp' objects to the ground....yes that old chestnut! I've read many a post here, but I just can't get a catch all that works for .obj models and in-built primitives (like a cube, which I seem to have fixed now incidentally)

In the app I either create a primitive, such as a cube, or load an .obj model and then add it to the scene through the following method;

Code: [Select]
public void addObjectsToWorld(A_Object3D[] objects) {

if (objects==null || sceneOrientation==null) return;
SimpleVector frontAxis = sceneOrientation.front.normalize();
SimpleVector upAxis = sceneOrientation.up.normalize();

// Align our object axis to the ECEF axis
for (A_Object3D obj : objects) {
if (obj.requiresOrientation) {
obj.setOrientation(frontAxis, upAxis);
}
obj.applyStyleRotations();
obj.build();
}

// Add...
theWorld.addObjects(objects);

// Now clamp objects to the floor if flagged to do so...
SimpleVector trans = new SimpleVector();

for (A_Object3D obj : objects) {
if (!obj.clampToGround) continue;

float dist = plane.calcMinDistance( obj.getTransformedCenter(), upAxis );

// Move object above plane by 20m and try again
if (dist==Object3D.COLLISION_NONE) {
trans.set( upAxis );
trans.scalarMul( -20f );
obj.translate( trans );

dist = plane.calcMinDistance( obj.getTransformedCenter(), upAxis );

// Couldn't collide, move to original position
if (dist==Object3D.COLLISION_NONE) {
trans.set( upAxis );
trans.scalarMul( 20f );
obj.translate( trans );
}
}

// Do the clamping...
if (dist!=Object3D.COLLISION_NONE) {
float htAdjust = obj.isPlane ? 0f : -obj.getMesh().getBoundingBox()[3];

Log.i(LOG_TAG, "Obj: "+obj.getParentFeatureID()+" Dist: "+(dist+htAdjust));
trans.set( upAxis );
trans.scalarMul( dist-obj.heightOffset+htAdjust );

// (paulscode) Grab a handle to the Object3D's world transformation matrix:
Matrix m = new Matrix( obj.getWorldTransformation() );
// Turn that into a rotation matrix:
float[] dm = m.getDump();
for( int i = 12; i < 15; i++ ) dm[i] = 0;
dm[15] = 1;
m.setDump( dm );
// Apply this rotation matrix to the translation vector:
trans.matMul( m );

obj.translate( trans );
}
}

The plane object is a transparent plane sat 2m below the camera position.
Adding additional planes (map tiles) through the above method works; adding cubes works, but .obj models (and an arrow which I'll get to in the minute) does not. The links should hopefully illustrate;

Screen1: Primitive models sat on ground, but .obj model floating


Screen2: Model the same size and axis alignment, but sat below plane (the rotating arrow is sat below the overlay).



It should be noted that the models (not mine!) are exported from Sketch-up with the swap YZ axis option enabled. To then align the axis to jPCT I use the following;

Code: [Select]
if (shapeName.endsWith(".obj") || shapeName.endsWith(".3ds")) {
ret = getShapeFromAssets(shapeName);
/* jPCT axis are rotated 180 around X axis,
* contrary to most graphics systems, so we rotate and then
* replace the matrix so this rotation is ignored in later
* translations and rotations */
ret.obj.rotateZ(PI);// Why Z, not X ??? (Is Z so North is aligned)
ret.obj.rotateMesh();
ret.obj.setRotationMatrix( new Matrix() );
ret.obj.getMesh().setLocked(true);
}

I can seem to get a decent value from calcMinDistance, one model is 0.09m, whereas the other is 19.4m. ??

As a secondary issue, I'm trying display an arrow permanently in front of the camera, at a fixed distance, but also clamped to the ground. I suspect a very similar problem as, again, the arrow is loaded from an .obj, added to as a child to a dummyObject at the camera position and then translated to be in front of the camera. With the arrow being 8m in front of the camera, calcMinDistance is returning 6.9 metres from the plane!!??

Many, many thanks to the person who tells me what stupid thing I'm doing!

[attachment deleted by admin]

36
Support / Re: obj.translate not moving object
« on: January 31, 2013, 09:44:32 am »
Indeed I have :) 

Thanks Egon

37
Support / obj.translate not moving object
« on: January 30, 2013, 07:40:59 pm »
Hi,
Can anyone tell me what I'm doing wrong here...
I'm trying to get an object to automatically place itself on the ground (a plane). I've read several posts on 'gravity' and collision detection, but nothing I do is actually moving the object.

I have an object 2m above a plane (manually created). The plane is set to
Code: [Select]
plane.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);and the 'floating' object is also set to Object3D.COLLISION_CHECK_OTHERS.
The objects are added to the world at runtime as follows
Code: [Select]
public void addObjectsToWorld(A_Object3D[] objects) {
if (objects==null) return;

for (A_Object3D obj : objects) {
if (obj.requiresOrientation==false || sceneOrientation==null) continue;

// Align and rotate to our scene
tmpDirVector.x = sceneOrientation.front.x;
tmpDirVector.y = sceneOrientation.front.y;
tmpDirVector.z = sceneOrientation.front.z;
tmpUpVector.x = sceneOrientation.up.x;
tmpUpVector.y = sceneOrientation.up.y;
tmpUpVector.z = sceneOrientation.up.z;

obj.setOrientation(tmpDirVector, tmpUpVector);

obj.applyStyleRotations();// X,Y,Z rotation done here so angles are correct for scene

}

// Add...
theWorld.addObjects(objects);
theWorld.buildAllObjects();

Immediately afterwards I've tried two methods to move the object as follows
Code: [Select]
for (A_Object3D obj : objects) {
if (!obj.clampToGround) continue;

// SimpleVector dir = obj.getYAxis();
// SimpleVector tmp = new SimpleVector(dir);
// obj.checkForCollisionEllipsoid(dir, ellipsoid, 1);
// if (!dir.equals(tmp)) {
// Log.i(LOG_TAG, "Obj collided "+dir.toString());
// obj.translate(dir);
// }
SimpleVector dir = obj.getYAxis();
float dist = theWorld.calcMinDistance(
obj.getOrigin(),
dir,
50f);
Log.i(LOG_TAG, "Dist="+dist);
if (dist!=Object3D.COLLISION_NONE) {
obj.translate(dir.x*dist, dir.y*dist, dir.z*dist);
}

}
The distance is logging as 3.7001638m, which isn't far out as the object is 1m square, although I think it should be more like 2.5m to the centre...
Anyway, the object does not move with the translate, even if I try 50f. I also tried to put the translate code into the onDrawFrame(), but still nothing :(

Could this be related to the objects all being cloned from an original?

38
Support / Re: Removing textures during runtime
« on: January 30, 2013, 03:52:08 pm »
Sorry, my mistake...;)

On closer inspection, what was actually happening was;
I was cloning the object after setting a texture on the original, so when there was an object without a texture being set it retained the original. A removeTexture() function would resolve it, but I have swapped the order around so clones are taken before texture setting.

Cheers,

39
Support / Removing textures during runtime
« on: January 28, 2013, 09:18:54 pm »
Hi Egon.
Thought I would post here as a general query.

Within my application I (can) re-use an object, such as a cube or arrow, many times... To save re-creation, memory and time I load each object type that is required into a HashMap with a name (like CUBE1) - if the same object is needed again, it is got from the Map and a new Object3D created from it via the Object3D( 'object_a' ) constructor (which I believe clones the original object).

This process also clones the textures assigned to object 'a' on object 'b' - which is fine except I want a different texture on object 'b' than 'a'. I set object 'b's texture to my newly required texture through obj.setTexture(), but it just <i>adds</i> a reference to the new texture, compared to replacing it. This would be fine, but I cannot remove/ change the reference to the original texture, therefore object 'b' now has two textures.

How can I re-use an object many times, whilst minimising replication, but keep changing the texture  - is there a way of doing obj.removeTexture(), obj.deleteTexture() or obj.replaceTexture() ?

Many thanks...

40
Bugs / Re: Crash on Galaxy S3
« on: January 09, 2013, 05:54:57 pm »
As a footnote to this...

As I have to dispose and re-create the FrameBuffer each time, I thought I'd see if there were other ways to speed up the process.
I found that onSurfaceChanged() is actually being called twice, which I believe is an Android issue, and not mine.

Anyway, I've implemented a counter that is reset in the GLSurfaceView.onResume() method, so now when onSurfaceChanged() has been called once it isn't called again.  This is probably shaved 1/3 off the restart time.

Code: [Select]
@Override
public void onSurfaceChanged(GL10 ignore, int width, int height) {
if (SURFACE_RESTART_COUNT > 0) return;
SURFACE_RESTART_COUNT++;
Globals.SCREEN_WIDTH = width;
Globals.SCREEN_HEIGHT = height;
if (frameBuffer!=null) frameBuffer.dispose();
        frameBuffer = new FrameBuffer(Globals.SCREEN_WIDTH, Globals.SCREEN_HEIGHT);

        Log.i(LOG_TAG,"Frame buffer set - w: "+ Globals.SCREEN_WIDTH + ", h: "+Globals.SCREEN_HEIGHT );
}

Cheers.

41
Bugs / Re: Crash on Galaxy S3
« on: January 08, 2013, 07:35:10 pm »
:( I'll loose those valuable 1.8 seconds I thought I'd gained onResume() - Better than not crashing though!

Thanks Egon.

42
Bugs / Re: Crash on Galaxy S3
« on: January 07, 2013, 10:30:09 pm »
Ah.. The orientation is not changing anyway, due to
Code: [Select]
android:screenOrientation="landscape" in the manifest.

Sorry for the confusion - The S3 is on Android 4.x.  My regular test/ dev device is an S2 which is on 2.3.3 - This has not shown the error, whereas the S3 has. Not sure how this fits with 4.x 'trying' to save the context...

43
Bugs / Re: Crash on Galaxy S3
« on: January 07, 2013, 10:01:47 pm »
This seems to work happily on the other devices I have tested on, so a little strange... I had thought that onSurfacedChanged() was only called when the surface dimensions changed, and therefore as the layout is fixed to landscape within the application this wouldn't get called again via onResume() or similar.

If this is the case, is there a way to check if the context has changed prior to creating a new buffer? - Previously I wasn't checking if the frame buffer was null and therefore always re-creating it, but as you know re-initialising the context/ buffer causes a major slow-down, hence the change.

Cheers Egon.

44
Bugs / Crash on Galaxy S3
« on: January 07, 2013, 09:34:28 pm »
Hi,

I have just released a new version of our app, and unfortunately there is a repeatable crash on a galaxy S3. The only 'big' difference I can think of between that and the galaxy S2 I have always tested on is Android 4.x vs 2.3.3 ... The only information I have (not owning an S3) is the reported stack trace as below;

Code: [Select]
java.lang.RuntimeException: [ 1357589905458 ] - ERROR: before: glError 1281
at com.threed.jpct.Logger.log(Logger.java:189)
at com.threed.jpct.GL20.checkError(GL20.java:142)
at com.threed.jpct.GL20.glGenBuffers(GL20.java:1324)
at com.threed.jpct.CompiledInstance.compileToVBO(CompiledInstance.java:1299)
at com.threed.jpct.CompiledInstance.render(CompiledInstance.java:533)
at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:2246)
at com.threed.jpct.World.draw(World.java:1321)
at com.threed.jpct.World.draw(World.java:1083)
at com.augtech.awila.graphics.JpctRenderer.onDrawFrame(JpctRenderer.java:165)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1516)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

This happens after starting a new activity (such as a dialog) and then returning to the main activity that runs the rendering.

Could this be related to not re-creating the frame buffer if not required?

Code: [Select]
@Override
public void onSurfaceChanged(GL10 ignore, int width, int height) {
Globals.SCREEN_WIDTH = width;
Globals.SCREEN_HEIGHT = height;
if (frameBuffer==null) {
        frameBuffer = new FrameBuffer(Globals.SCREEN_WIDTH, Globals.SCREEN_HEIGHT);
        Log.i(LOG_TAG,"Frame buffer set - w: "+ Globals.SCREEN_WIDTH + ", h: "+Globals.SCREEN_HEIGHT );
}
}


Any ideas?!?
Many thanks in advance

45
Support / Re: How to remove objects during runtime
« on: January 04, 2013, 09:48:14 pm »
Many thanks for the quick response Egon - I should have realised that!!
All working now, Cheers.

Pages: 1 2 [3] 4 5