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

Pages: 1 ... 13 14 [15] 16
211
Support / Re: Inconsistency in collision detection
« on: September 23, 2011, 10:52:03 am »
I'm  having a bit of difficulty placing an Object3D (an MD2 character) on the ground. I got it working, but the character ends up too high off the ground, so I hack the offset by 20.

The ground is an Object3D plane created with Primitives and modified by a VertexController
terrain = Primitives.getPlane(50, 50);
terrain.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);


On every frame I call this function:

Code: [Select]
private void ObjectToGround(Object3D object)
{
SimpleVector sv = new SimpleVector();

// Get object position
sv = object.getTranslation();

// Determine height above terrain
float terrHeight = terrain.calcMinDistance(sv, new SimpleVector(0,1,0));
if(terrHeight == Object3D.COLLISION_NONE)
{
//Log.v(TAG, "COLLISION_NONE" );
}
else
{
//sv.scalarMul(terrHeight); // object goes underground
terrHeight -= 20; // Hack offset
sv.set(0, terrHeight, 0);
character.translate(sv);

}
}


My question is, how do you determine the height or bottom of the 3D Object and place it on the ground properly without hacking the value?


Do I need to use the ellipse method?

Or scale the value returned by calcMinDistance() to the world scale?


212
Support / Re: How to use 2048 * 1024 texture on a sphere?
« on: September 22, 2011, 10:37:46 am »
I found a way to load huge textures, but only honeycomb (Android 3.x) is supported.

Honeycomb increases the memory size per application to 48MB using the standard heap (as opposed to 24MB and 32MB in previous Androids). But loading a 2048x2048 texture still crashed my app.

Here is the memory allocation (crashes when loading the large texture):
09-22 18:21:08.190: VERBOSE/Tosh(25398): debug.heap native: allocated 3.02MB of 3.04MB (0.01MB free)
09-22 18:21:08.190: VERBOSE/Tosh(25398): debug.memory: allocated: 22.00MB of 48.00MB (6.00MB free)

Then I made the following changes to increase the heap to Large:
In default.properties file, I changed the target to 'target=android-11'
In AndroidManifest.xml file, I added 'android:largeHeap="true"' to the Application tag.

Now that large 2048 texture loads with no problem.
09-22 18:23:14.980: VERBOSE/Tosh(25572): debug.heap native: allocated 3.02MB of 3.02MB (0.00MB free)
09-22 18:23:14.980: VERBOSE/Tosh(25572): debug.memory: allocated: 55.00MB of 256.00MB (22.00MB free)

256MB to play with! But your app won't be able to run on any phone, or at least until Icecream Sandwich phones come out (2012).

Here's the code to log the memory stats
Code: [Select]
public static void logHeap() {
        Double allocated = new Double(Debug.getNativeHeapAllocatedSize())/new Double((1048576));
        Double available = new Double(Debug.getNativeHeapSize())/1048576.0;
        Double free = new Double(Debug.getNativeHeapFreeSize())/1048576.0;
        DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(2);
        df.setMinimumFractionDigits(2);

        Log.d("Log", "debug. =================================");
        Log.d("Log", "debug.heap native: allocated " + df.format(allocated) + "MB of " + df.format(available) + "MB (" + df.format(free) + "MB free)");
        Log.d("Log", "debug.memory: allocated: " + df.format(new Double(Runtime.getRuntime().totalMemory()/1048576)) + "MB of " + df.format(new Double(Runtime.getRuntime().maxMemory()/1048576))+ "MB (" + df.format(new Double(Runtime.getRuntime().freeMemory()/1048576)) +"MB free)");
    }



213
Support / Re: How to use 2048 * 1024 texture on a sphere?
« on: September 22, 2011, 08:42:59 am »
Is there a way to stream the texture into the GPU or perhaps use Texture compression?

214
Support / Re: How to use 2048 * 1024 texture on a sphere?
« on: September 21, 2011, 04:31:10 pm »
I was thinking it may be a 3DS issue, perhaps try texturing a bare sphere using primitives.getSphere.

215
Support / Re: How to use 2048 * 1024 texture on a sphere?
« on: September 21, 2011, 03:53:14 pm »
you can check how much memory is being used by using the code from here:
http://www.jpct.net/forum2/index.php/topic,2287.msg16929.html#msg16929


216
Support / Re: Switching between multiple Worlds
« on: September 21, 2011, 03:42:39 pm »
I've got it all working now.

I ended up using two preloaded worlds, placing each world in it's own class file, and using a main class to handle both worlds. I ended up using queueEvent in the TouchEvent to handle the multiple threads.

Now I can swap between the two worlds 60 times a second via TouchEvent, causing the two worlds to appear blended together. It's solid as a rock now :)

Thanks again Egon.


217
Support / Re: How to use 2048 * 1024 texture on a sphere?
« on: September 21, 2011, 02:58:24 pm »
What android device/phone are you using? (please don't say the Android Emulator :p)

Have a read of this article: http://blog.javia.org/how-to-work-around-androids-24-mb-memory-limit/

I don't know how accurate that article is, but it mentions that you can get around the 24MB memory limit by using OpenGL textures, apparently textures are not limited to 24MB.

Also, what is your android:minSdkVersion value in the AndroidManifest.xml file? Increasing it to say "9" (gingerbread) may help relieve limitations.


218
Support / Re: How to use 2048 * 1024 texture on a sphere?
« on: September 21, 2011, 11:22:05 am »
Each type/model of Graphics Chip (GPU) has it's own maximum texture size, so you should check the size before creating large textures.

To query the texture size, call glGetIntegerv() in your main Activity's GLSurfaceView.Renderer class. You need a pointer to GL10 so you could place it in onSurfaceCreated().

Code: [Select]
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// Do nothing special.
int[] maxTextureSize = new int[1];
gl.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);
Log.v("Log", "Max texture size = " + maxTextureSize[0]);

}


219
Support / Re: How to use 2048 * 1024 texture on a sphere?
« on: September 21, 2011, 09:53:30 am »
Try to keep the textures at 512x512 to increase compatibility. If you set to minimum SDK to Android 2.2 then you can generally be safe using 1024x1024 textures. I wouldn't go higher than that unless you are specifically targeting Honeycomb tablets.

220
Support / Re: Switching between multiple Worlds
« on: September 20, 2011, 03:40:03 pm »
I tried adding Synchronized() to those two areas and it helped with one problem, but it still crashes when exiting to the menu and it crashes at random when loading the app. It's got to be a threading/timing issue. The Resources are not large.

I'll redesign the system to use two Worlds as you recommended, and perhaps use RENDER_WHEN_DIRTY instead since I don't see the value of having a dedicated rendering thread if it complicates everything. Keeping the flow in my own loop seems cleaner and more logical to me.

Appreciate your help, thanks.


221
Support / Re: Switching between multiple Worlds
« on: September 20, 2011, 02:57:25 pm »
Maybe I should use queueEvent()?

http://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer.html

Threading
The renderer will be called on a separate thread, so that rendering performance is decoupled from the UI thread. Clients typically need to communicate with the renderer from the UI thread, because that's where input events are received. Clients can communicate using any of the standard Java techniques for cross-thread communication, or they can use the queueEvent(Runnable) convenience method.

222
Support / Re: Switching between multiple Worlds
« on: September 20, 2011, 02:40:39 pm »
I'm having headaches trying to load 3D objects during onDrawFrame(GL10 gl) from the renderer thread. I think there is a sync problem with the renderer thread and the touch input thread

If I do this:

onDrawFrame()
{
    if(bLoad3DObjects == true)
   {
      LoadWorldObjects();
                bLoad3DObjects = false; // all 3d objects are loaded, should be ready to draw
      return;
   }
   
   world.draw()...
   etc..
}

and..

onTouchEvent(MotionEvent event)
{
   if(ACTION_DOWN == true)
   {
      bLoad3DObjects = true;
   }
}


Next time it calls onDrawFrame, it crashes saying:


Thread [<9> GLThread 10] (Suspended (exception OutOfMemoryError))   
   GLSurfaceView$GLThread.run() line: 1184   




It doesn't crash when I do this:

onDrawFrame()
{
    if(bDontRender == true)
   {
      return;
   }
   
   world.draw()...
   etc..
}

and..

onTouchEvent(MotionEvent event)
{
   if(ACTION_DOWN == true)
   {
      bDontRender = true;
      LoadWorldObjects();
      bDontRender = false;
   }
}

But that introduces a crash when returning back to the menu. I'm guessing it's a threading problem. Should I be using Synhronize() somewhere?

Does onDrawFrame() expect something to be rendered?

Is it safe to exit from the start of onDrawFrame if I load or unload from a Touch event?

223
Support / Re: Switching between multiple Worlds
« on: September 20, 2011, 10:41:45 am »
Ok I found the main problem. For those who run into the same problems, here's the story...

The GL renderer was calling onFrame while I was loading objects into the 2nd world, causing Object3D pointers to crash since they were null. Obviously the renderer is running on it's own thread.

What confused me is that the null objects were not generating an exception in the renderer thread (onFrame function). Instead it was just jumping/return out of the onFrame function half way through the function by itself, before it was reaching the world.draw() call, then crashing the app around 10 seconds later.

Anyway I started fresh and simply used the same World class for both worlds, using world.removeAllObjects() when switching worlds, using a boolean flag in onFrame to return straight away to avoid rendering while loading objects, and pre-loading all the textures at the start of the app rather than load them on the fly when needed. It's much less complicated that way in my opinion. The menu textures are small anyway.

224
Support / Re: Switching between multiple Worlds
« on: September 20, 2011, 01:31:51 am »
Ok I'll persist further with the current setup and double check all the logic.

The two worlds are sharing the singular TextureManager and framebuffer, everything else is separate.

Thanks for the help, I'll post the exception if I get stuck.

225
Support / Switching between multiple Worlds
« on: September 19, 2011, 04:09:06 pm »
I'm trying to utilize two separate worlds, one world is for the menu, the other is for the game.

My design is this:

-start the app
-load the menu world
-when 'start' is pressed, load another world
-go back to the original world when done

I created a class for the menu world, within that menu world I load another world on the fly, and redirect the main GLSurfaceView.Renderer OnFrame call to the game world.

I've ran into all kinds of problems. It's crashing when loading the game world, it always crashed on world.draw() for some reason. If I remove world.draw, the skymap renders ok but nothing else. If I remove all the object3D creations, draw.world works fine.
I tried using the same World both both the menu and game, but still have problems.
The confusing thing is, if I load the game world first, it works ok.


But anyway, ignore all that... Time to start fresh!

1. My main questions is, how do you handle two separate worlds correctly? Logically?

2. Do you need to dispose the first world then reload the second?  Or can both worlds coexists side by side, redirecting the onFrame method to the current world?

3. Rather calling/loading a world from within a world (in terms of class files), would it be better to create a World Handler that disposes the current world before creating the new world, having each world in it's own class?


Any help is appreciated, thanks.

Pages: 1 ... 13 14 [15] 16