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

Pages: 1 2 [3]
31
Support / Beware of parents
« on: October 22, 2014, 09:16:10 am »
And!

As I tried to point out in some older posts, beware of parenting, because to scale a parent means to scale all its children, so I am using this to calculate the real size of the object:
Code: [Select]
public static SimpleVector getSize(Object3D object){
float[] bbox = object.getMesh().getBoundingBox();
Log.i("Util","getSize-bbox:"+Util.floatArrayToString(bbox));
float s = object.getScale();
Log.i("Util","getSize-scale:"+object.getScale());
Object3D[] par;
par = object.getParents();
while(par.length>0){
s = s*par[0].getScale();
Log.i("Util","getSize-parent:"+par[0].getScale());
par = par[0].getParents();
}
SimpleVector out = new SimpleVector((bbox[1]-bbox[0])*s,(bbox[3]-bbox[2])*s,(bbox[5]-bbox[4])*s);
Log.i("Util", "getSize:"+out.toString());
return out;
}
Enjoy,
Darai.

32
Support / So before the physics, maybe some remaking
« on: October 22, 2014, 09:12:00 am »
Hi,

Thanks for the reply. I spend the last day going through your code and I was suprised that I really saw this simple linear approach there... actually I did some more precise calculations and the scale is as follows:
  • 200-300 objects, which I move and check if they are "out of the bounding box"
  • 50 objects which move, and check for collision
  • 100 objects which rotate, move, check for outOfBoundary and for collision and
  • 100 sleeping objects for some animation gadgets.
The game is having difficulty to hold the tick rate, that is why I am thinking about better than linear approach, but from what you said, maybe I can first think about improving some other gadgets, like:
  • Limit the tick rate of the onTouchEvent() method, because every time this runs, it drains some resources identifying where the touch on the screen was.
  • Remake the onTouchEvent() method, to move most of the math (Recalculation from 2D to 3D, switching on GUI, etc) to the onTick()
  • Remake all the methods in onTick to be on Lists not ArrayLists (most of them are, but not all)
  • Think more about the method which is doing the tick balance (I am also using some tick calculation, not fixed time)
Right now I focused on limiting the garbage collector, but I think I can still quite upgrade some of the calculations I am doing there.
Well, that is all for start.

I will report what I achieved with this ideas,
Thanks,

Darai.

33
Support / Best practice for "Basic Physics"
« on: October 21, 2014, 01:25:06 pm »
Hi guys,

Imagine, you have some 50+ objects in JPCT world. You have the renderer, taking care for the onDrawFrame() method and some onTouchEvent() method switching on and off the switches according the user demands.

Now, every turn each object does something - let's say it moves by predefined vector. This is a very simple type of physics, where the objects have no interaction, but they have some behavior.

Up until now, when i wanted to do something like that, I used a temporary solution. A for cycle in the onDrawFrame() method to cycle through each object.

I expect that there is a better solution, like threadding or using Android Services or there is some onDraw listener for the Object3D simillar to onCollision listener or if I have to implement a real physics, like Bullet even for a simple example like this one... but I don't know which is the best one to use.

To demonstrate it in example:
Lets say I have this:

Code: [Select]
public ExtendedObject[] objects;

public class ExtendedObject{
public Object3D theObject;
public SimpleVector speed;
public void move(){
// Do something
this.theObject.translate(this.speed);
}
}

// And somewhere in the Renderer with FrameBuffer fb
public void onDrawFrame(GL10 gl) {
for(int i =0;i<objects.length;i++){objects[i].move();}
fb.clear(back);
world.renderScene(fb);
world.draw(fb);
fb.display();
try {
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Thanks for every hint.
Darai.

34
Bugs / Re: cloneObject does not copy scale parameter
« on: August 08, 2014, 08:52:25 am »
Whow, that was fast...

thanks.

35
Bugs / cloneObject does not copy scale parameter
« on: August 07, 2014, 10:51:55 am »
Hi guys,

i found this strange behaviour in cloneObject:
Code: [Select]
Object3D first = Primitives.getBox(1f, 1f);
first.setScale(2f);
Object3D second = first.cloneObject();

Now, first has scale == 2, second has scale == 1, their Object3D.getMesh().getBoundingBox() returns the same set of numbers, but the displayed object second has the same size as the scaled object first.

Is there problem somewhere on my side, or do you see the same behaviour?

36
Support / Created contribution for the wiki
« on: August 05, 2014, 02:52:14 pm »
Hello,

so ok, I made the contribution for the wiki in the "parsonal page" called "User:Darai"... can you edit it and moved it whereever you think it can be useful?
http://www.jpct.net/wiki/index.php/User:Darai

Thanks,
Darai.

37
Hmm...

To be blunt, I don't feel like the big expert for this... sure, I am a little bit programmer and little bit mathematician, but with BIG but. That is why I hoped that I will post it to a thread and after some corrections from the proper programmers or math gurus it could be transformed into a proprer wiki page. But if you prefer me to write a prototype of such a wiki page and let the people to do the corrections directly there, I am with you so go for it.

Darai.

38
SUCCESS, with the new file 1.29 it works fine, so it was because of the version, thanks for all the effort. A pro po, I have some hints for people fighting with algebra and vectors and spaces I would like to post. Can you recommend a good thread I can post it into?

39
All right,

now I expect that I have an old version, even though I downloaded it 2 days ago from the page
http://www.jpct.net/jpct-ae/

I did the config thing you recommended, it says that I have version 1.28... Where can I find which is the most current version? Ok, I found here in forum your link with the version 14/07/30... but can I (next time) verify the version somewhere without downloading the file and comparing size/date/Config.version?

Code: [Select]
07-30 03:19:48.641: I/onDraw(1487): >>>>>>>
07-30 03:19:48.641: I/safeLoad(1487): loading:tex
07-30 03:19:48.641: I/safeUnload(1487): unloading:tex
07-30 03:19:48.641: I/safeUnload(1487): previousID:1
07-30 03:19:48.651: I/safeUnload(1487): newID:1
07-30 03:19:48.651: I/jPCT-AE(1487): Loading Texture...
07-30 03:19:48.651: I/jPCT-AE(1487): Texture loaded...16384 bytes/64*64 pixels!
07-30 03:19:48.651: I/safeLoad(1487): newID:1
07-30 03:19:48.651: I/safeLoad(1487): names:tex
07-30 03:19:48.651: I/safeLoad(1487): names:--dummy--
07-30 03:19:48.651: I/onDraw(1487): JPCTVersion: 1.28
Thanks,
Darai.

40
Uff,

I was affraid I will not be able to create one, but at the end I succeeded and it still has the same behaviour, so here is the example:
Code: [Select]
package com.example.loadunloatest;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Iterator;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;

import com.threed.jpct.FrameBuffer;
import com.threed.jpct.RGBColor;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;

public class MainActivity extends Activity {

private GLSurfaceView mGLView;
private MyRenderer renderer = null;
private static FrameBuffer fb = null;
private World world = null;
private RGBColor back = new RGBColor(50, 50, 100);
private boolean loadTest = false;
public static TextureManager tm;
public static MainActivity act;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGLView = new GLSurfaceView(getApplication());

mGLView.setEGLContextClientVersion(2);

renderer = new MyRenderer();
mGLView.setRenderer(renderer);
setContentView(mGLView);

tm = TextureManager.getInstance();
act = this;
}
class MyRenderer implements GLSurfaceView.Renderer {

public MyRenderer() {}

public void onSurfaceChanged(GL10 gl, int w, int h) {
Log.i("onChange",">>>>>>>");
world = new World();
if (fb != null) {
fb.dispose();
}
fb = new FrameBuffer(w, h);
try {
MainActivity.safeLoadTexture("tex",act.getAssets().open("pom.png"),false,true);
} catch (IOException e) {
e.printStackTrace();
}
}

public void onSurfaceCreated(GL10 gl, EGLConfig config) {}

public void onDrawFrame(GL10 gl) {
if(!loadTest){
Log.i("onDraw",">>>>>>>");
try {
MainActivity.safeLoadTexture("tex",act.getAssets().open("pom.png"),false,true);
} catch (IOException e) {
e.printStackTrace();
}
loadTest = true;
}
fb.clear(back);
world.renderScene(fb);
world.draw(fb);
fb.display();
}

}
    public static void safeLoadTexture(String name, InputStream IS, boolean useAlpha, boolean force){
    Log.i("safeLoad","loading:"+name);
    if(force){safeUnloadTexture(name);}
    if((force)||(!tm.containsTexture(name)))
    {tm.addTexture(name, new Texture(IS, useAlpha));}
    Log.i("safeLoad", "newID:"+tm.getTextureID(name));
    HashSet names = tm.getNames();
    Iterator itr = names.iterator();
      while(itr.hasNext()) {
         Object element = itr.next();
     Log.i("safeLoad", "names:"+(String)element);
      }
      System.out.println();
    }
   
    public static boolean safeUnloadTexture(String name){
    Log.i("safeUnload","unloading:"+name);
    boolean cleared = false;
    Log.i("safeUnload", "previousID:"+tm.getTextureID(name));
if(tm.containsTexture(name)==true){
tm.removeAndUnload(name, fb);}
    Log.i("safeUnload", "newID:"+tm.getTextureID(name));

return cleared;
    }
}

On my PC Win7 + Emulator it shows this CatLog:
Code: [Select]
07-28 09:01:03.058: I/safeLoad(1365): loading:tex
07-28 09:01:03.058: I/safeUnload(1365): unloading:tex
07-28 09:01:03.058: I/safeUnload(1365): previousID:-1
07-28 09:01:03.058: I/safeUnload(1365): newID:-1
07-28 09:01:03.058: I/jPCT-AE(1365): Loading Texture...
07-28 09:01:03.068: I/jPCT-AE(1365): Texture loaded...16384 bytes/64*64 pixels!
07-28 09:01:03.068: I/safeLoad(1365): newID:1
07-28 09:01:03.068: I/safeLoad(1365): names:tex
07-28 09:01:03.068: I/safeLoad(1365): names:--dummy--
07-28 09:01:03.068: I/onDraw(1365): >>>>>>>
07-28 09:01:03.078: I/safeLoad(1365): loading:tex
07-28 09:01:03.078: I/safeUnload(1365): unloading:tex
07-28 09:01:03.078: I/safeUnload(1365): previousID:1
07-28 09:01:03.078: I/safeUnload(1365): newID:1
07-28 09:01:03.078: I/jPCT-AE(1365): Loading Texture...
07-28 09:01:03.078: I/jPCT-AE(1365): Texture loaded...16384 bytes/64*64 pixels!
07-28 09:01:03.078: I/safeLoad(1365): newID:1
07-28 09:01:03.078: I/safeLoad(1365): names:tex
07-28 09:01:03.078: I/safeLoad(1365): names:--dummy--

So there is still the part: previousID:1, newID:1 (After the call from the onDrawFrame()), which means that it can detect the texture after it was unloaded in the safeUnloadTexture method... If I am right.

Thanks a lot EgonOlsen,
Darai.

41
Hmm...

Ok, I downloaded the newest JPCT-AE... i had the version 14/05... but it didn't helped.. I am running this command in the onDrawFrame() thread in the renderer, is that correct?

Another thing that could cause this is that I see the problem on the emulator, I can and will werify today if the same problem is also on the real Android device.

Thanks,
Darai

42
Well,

I am doing all loading and unloading through this code (I used here your suggestion and it helped, but there is still the issue fo the ID I am describing in the bottom of this post)

Code: [Select]
    public static void safeLoadTexture(String name, InputStream IS, boolean useAlpha, boolean force){
    Log.i("safeLoad","loading:"+name);
    if(force){Util.safeUnloadTexture(name);}
    if((force)||(!tm.containsTexture(name)))
    {tm.addTexture(name, new Texture(IS, useAlpha));}
    Log.i("safeLoad", "newID:"+tm.getTextureID(name));
    HashSet names = tm.getNames();
    Iterator itr = names.iterator();
      while(itr.hasNext()) {
         Object element = itr.next();
     Log.i("safeLoad", "names:"+(String)element);
      }
      System.out.println();
    }
   
    public static boolean safeUnloadTexture(String name){
    Log.i("safeUnload","unloading:"+name);
    boolean cleared = false;
    Log.i("safeUnload", "previousID:"+tm.getTextureID(name));
if(tm.containsTexture(name)==true){
tm.removeAndUnload(name, AstroRenderer.getFrameBuffer());}
    Log.i("safeUnload", "newID:"+tm.getTextureID(name));

return cleared;
    }

Funny part is that right after unloading, the texture manager still sees the texture like if it is still there, at least for the getTextureID method, a moment later it is all right, example is following CatLog from one run of safeUnloadTexture method:

Quote
07-25 07:51:23.962: I/safeUnload(1280): unloading:skydome.png
07-25 07:51:23.962: I/safeUnload(1280): previousID:6
07-25 07:51:23.962: I/safeUnload(1280): newID:6

I am afraid that this may cause some problems during my Texture selecting, because the new object in new scene can select a Texture which is beeing deleted in the same moment. I hope this makes sence.

43
Support / TextureManager - removeAndUnload does not mean get rid off?
« on: July 25, 2014, 10:33:23 am »
Hi guys, i have problem with TextureManager,

I am lazy to remember which texture names I used and which I didn't, so I created a "safeLoad" which looks if such name exists and if yes, it unloads it. I am using the getTextureID method to find out if the texture exists or not, but i found out that following code can end in infinite loop... do you know why and what do I have to do differently to find out if the texture is still there or not?

Code: [Select]
while(TextureManager.getInstance().getTextureID(name)!=TextureManager.TEXTURE_NOTFOUND){
TextureManager.getInstance().removeAndUnload(name, AstroRenderer.getFrameBuffer());
};


Thanks,
Darai

44
Support / Re: Scale - not sure if I have it right
« on: July 24, 2014, 01:22:48 pm »
Thanks for the hint,

this will probably be enough for me to solve this out.

Thanks again.
Darai

45
Support / Scale - not sure if I have it right
« on: July 24, 2014, 10:40:13 am »
Hi guys,

I am fighting with scale for some time, so I created a simple example and was surprised bz the result. The Object3D was a triangle, created by addTriangle method, I created a clone of the same object and scaled it, expecting the 0,0,0 point to be still on the same spot. Surprise surprise this didnot happend and I am trying to understand why and what I have to do to get the result I expected.

Source code:
Code: [Select]
Object3D o1 = new Object3D(1);
o1.addTriangle(   new SimpleVector(-10f,-10f,0), 0, 0,
            new SimpleVector(-10f,10f,0), 0, 1,
            new SimpleVector(0f,0f,0), 1, 1,
            texID);
o1.setScale(1);
world.addObject(o1);

Object3D o2 = new Object3D(o1);
o2.setScale(2);
world.addObject(o2);
The result is in attachment. Short to say, the triangles are scaled from theirs centers, not from the 0,0,0 point.

Thanks,
Darai


[attachment deleted by admin]

Pages: 1 2 [3]