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

Pages: [1]
1
Support / pivot rotation
« on: August 17, 2011, 01:56:01 pm »
Hi,

I've been a while trying to figure this one out for a prototype I'm working on: I have a racing car that remains static, with a top view camera on it and the ground moves as necessary. The ground (racetrack) needs to translate according to speed and rotate according to bearing. The rotation needs to be made relative to the point over the racetrack where the car is, so I understand I need to change the pivot point. I set the new pivot point relative to the transformed center (car started at center of world, and background was instanced and never relocated, so it should initially have it's center at world(0,0,0)). I think I'm close to solve to problem, and I guess it relates to the transformed center inversion, but after trying many variations I just can't find the issue... maths/geometry is not my thing.
So the piece of code below has a test bit to change steering by 45 (Math.PI/4) degrees every 20 ticks and places a cube at the calculated pivot point. First iteration works fine with pivot point set to (0, -20, 0), no previous rotations so only the translation is relevant. Second iteration, after the previous 45 degrees rotation, the pivot point is calculated correctly aprox. (-14, -34, 0), the test cube is placed on the right place but the background kind of translates twice, so the car appears off by double the distance on the previous direction... and then it just gets worse:
Code: [Select]
    public void tick(Car car){
        count++;
        if (count%20 == 0){
            car.angleChangeRatio = (float) (Math.PI / 4);
        }
        model.translate(0, car.speed, 0);
        if (car.angleChangeRatio != 0){
            model.getTransformedCenter(tmpVector);
            //tmpVector.scalarMul(-1);
            tmpVector.y = -tmpVector.y;
            model.setRotationPivot(tmpVector);
            model.rotateZ(car.angleChangeRatio);
            Utils.log(model.getRotationPivot().toString());
//            model.rotateMesh();
            car.angleChangeRatio = 0;
            Object3D show = Primitives.getCube(1);
            show.translate(model.getRotationPivot());
            model.addChild(show);
            Utils.world.addObject(show);
        }
    }

any suggestions?

2
Support / scaling one axis
« on: June 07, 2011, 12:00:43 am »
I have this polygon that I want to shrink/expand on one axis. It is meant to represent a sea wake. I am currently just translating it (see current version of Run!) but I think it would be a nicer effect with scaling.
As far as I can tell, the scaling method applies to all coordinates... and the only alternative I can find is using a vertex controller but I'd rather avoid doing this kind of modifications constantly during runtime (added cost of mesh modification plus I guess there are SimpleVectors created that would then increase gc time)... is there any other option to scale one axis?

3
Support / serialization for Object3D
« on: May 31, 2011, 10:13:12 pm »
I seem to have a problem serializing Object3D... I am using a workaround which is not that nice (re-instancing with relevant data instead of serializing). I wonder why is that happening: trying to serialize generates errors because it can't serialize (unrelated) stuff like GLThread or other threads. In this trace, ThrowableObject3D line 32 is for writeObject(object3D):
I/RunActivity(19405): Unable to save game state java.io.NotSerializableException: android.opengl.GLSurfaceView$GLThread
W/System.err(19405): java.io.NotSerializableException: android.opengl.GLSurfaceView$GLThread
W/System.err(19405):    at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1547)
W/System.err(19405):    at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1859)
W/System.err(19405):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1701)
W/System.err(19405):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1665)
W/System.err(19405):    at java.util.HashMap.writeObject(HashMap.java:1025)
W/System.err(19405):    at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(19405):    at java.lang.reflect.Method.invoke(Method.java:521)
W/System.err(19405):    at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1229)
W/System.err(19405):    at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1587)
W/System.err(19405):    at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1859)
W/System.err(19405):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1701)
W/System.err(19405):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1665)
W/System.err(19405):    at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:1153)
W/System.err(19405):    at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:420)
W/System.err(19405):    at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1251)
W/System.err(19405):    at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1587)
W/System.err(19405):    at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1859)
W/System.err(19405):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1701)
W/System.err(19405):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1665)
W/System.err(19405):    at com.loxai.run.ThrowableObject3D.writeObject(ThrowableObject3D.java:32)

4
Support / transparency problem
« on: May 30, 2011, 02:18:46 pm »
Hi,

I'm getting a transparency issue where objects calling setTransparency() have a strange see-through effect (see current beta of Run! on the Android Market) against each other. This effect can be seen when a road path is under a tree top (both objects using transparency).
Am I using it wrong?

cheers

5
Support / framebuffer getPixels()
« on: May 27, 2011, 09:38:36 pm »
Hi,

I am having trouble getting the right colors to generate a bitmap from the framebuffer.getPixels() method. My thought was that fb would return ints with 24bits, 1 byte per color and that, depending on the Config when creating bitmap and some previos manipulation I would get the right result. I've tried different options but none has been succesful so, I thought I better ask instead of banging my head on this...
first I tried for Config.RGB_565, doing the following conversion (and other bitwise operations combos):

                            int[] tmpPixels = fb.getPixels();
                            for (int i = 0; i < tmpPixels.length; i++){
                                int tmpInt = ((tmpPixels & 0xf8) >> 3);
                                tmpInt += ((tmpPixels & 0xfc00) >> 5);
                                tmpInt += ((tmpPixels & 0xf80000) >> 11);
                                tmpPixels = tmpInt;
                            }
                            lastImage = Bitmap.createBitmap(tmpPixels, fb.getWidth(), fb.getHeight(), Config.RGB_565);

got nice unintended predator style views, playing with that :)
also tried with a more comfortable format, Config.ARGB_8888, only adding opaque alpha:

                            int[] tmpPixels = fb.getPixels();
                            for (int i = 0; i < tmpPixels.length; i++)
                                tmpPixels = tmpPixels + 0xff000000;
                            lastImage = Bitmap.createBitmap(tmpPixels, fb.getWidth(), fb.getHeight(), Config.ARGB_8888);

and this got me a blueish tint (closer but not quite)... which actually I have also seen in some screenshot taking software... which requires to tick an option to invert red and blue... so I also tried inverting R and B (resulting in a  predator/hello kitty effect):

                            int[] tmpPixels = fb.getPixels();
                            for (int i = 0; i < tmpPixels.length; i++){
                                int tmpInt = tmpPixels + 0xff000000;
                                tmpInt &= 0xff00ff00;//remove r and b
                                int inv = ~(tmpPixels & 0x00ff00ff);//invert r and b
                                tmpInt += inv;//add r and b
                                tmpPixels = tmpInt;
                            }
                            lastImage = Bitmap.createBitmap(tmpPixels, fb.getWidth(), fb.getHeight(), Config.ARGB_8888);

any suggestions/ideas/piece of code with the solution?

cheers!

6
Projects / Run... RUUUUUUUN! (final version released)
« on: May 25, 2011, 01:27:12 pm »
Hi there!   :D

I thought it was about time to show what has kept me entertained for the last month... it's still incomplete and not fully tested, but works pretty nicely on my Galaxy S (and crawls 'glitchily' on a Pulse Mini). I hope to have a polished beta version for the Android Market soon... I wonder on what devices will it work!
See attached screenshots, and here's the test apk, the link probably won't last long as it is on megaupload:
http://www.megaupload.com/?d=K2WLC6NR

[attachment deleted by admin]

7
Support / null pointer at world 1021
« on: May 23, 2011, 10:54:51 am »
Hi,

I'm getting a Null pointer in World class, line 1021, but only when I setup the world contents at certain point in the code. Might be about the different threads (i.e. onCreate works, onTouchEvent fails) but there might be something else going on, I still can't find the reason. It might help to know what's happening at that line in class World (I think it's version 1.22, downloaded about a month ago).
Here's the exception...
E/AndroidRuntime(14758): FATAL EXCEPTION: GLThread 8
E/AndroidRuntime(14758): java.lang.NullPointerException
E/AndroidRuntime(14758):        at com.threed.jpct.World.renderScene(World.java:1021)
E/AndroidRuntime(14758):        at com.loxai.run.GameRenderer.onDrawFrame(GameRenderer.java:104)
E/AndroidRuntime(14758):        at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1332)
E/AndroidRuntime(14758):        at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)

... so, what's the world like in 1021?

8
Support / Understanding collisions in 3D
« on: May 01, 2011, 02:23:01 pm »
Ok, solved... the second (preferred) alternative works. It's just that I wasn't setting the collision mode to SELF (only OTHERS). Still not sure about the use of the axis vectors...
Hi, this is my second post, and it's about time to thank the developers on their effort to create an easy and comfortable 3D engine. After a project directly working with opengl (Trapped, for Android), this is a welcomed change.
That said, my 3d math knowledge is quite limited and conflicting with implementation of collisions. I am working on a top down view game with NPCs trying to catch the main character. Now I want to have the NPCs avoid each other (i.e. no overlapping) when stalking the player.
I first tried without checking the corresponding examples, sending to checkForCollisionSpherical() the transformation that I would send to translate() (thinking the collision would be based on the transformed position, but also trying to add the current transformed position). Seeing that wouldn't work I checked the wiki and I see the use of getX/Z/YAxis() which I don't quite understand, still tried to implement it, obviously with no success... here's the alternatives I have tried:
Code: [Select]
       if (false){
            SimpleVector center = getTransformedCenter();
            SimpleVector t = new SimpleVector(speedX + center.x, speedY + center.y, center.z);
            SimpleVector avoid = checkForCollisionSpherical(t, 5f);
            if (avoid.equals(t))
                translate(speedX, speedY, 0);
        }
        if (false){
            SimpleVector avoid = checkForCollisionSpherical(new SimpleVector(speedX, speedY, 0), 5f);
            translate(avoid);
        }
        if (true){
            //SimpleVector move = new SimpleVector();//getTransformedCenter();
            SimpleVector t = getXAxis();
            t.scalarMul(speedX);
            move.add(t);
            t = getYAxis();
            t.scalarMul(speedY);
            move.add(t);
            move.z = 0;
//System.out.println(t);

            move = checkForCollisionSpherical(move, 5f);
            translate(move);
        }
any hints/links/explanations on how this works would be appreciated...

9
Support / Md2 animation on Android problem [solved]
« on: April 29, 2011, 06:11:27 pm »
[Just before posting this I had a last shot, thinking it might be the strip() call (which prevents future modification). It wasn't that but the compile() call, which I also commented, because... well, had to try. So the conclusion is not to call compile if you have animations... I saw on the docs that it's not meant to be called, kind of a legacy method or something but no further explanation. If somebody wants to add the reasoning, that would be great.
I just went ahead and posted this because it might be handy to some, point a possible problem or well... just as a Hello World!]

Hi,

I've just started with jpct and I'm having trouble getting the animations to work on Android. The md2 model loads fine, it displays properly and transformations apply, but the animation just won't work. I've followed the advanced example, the logs says it processes the animations (stand, run, etc...) but the mesh doesn't change... also tried a couple of md2 files, with same results...
Here's the code... but I can't see any relevant difference to the examples:
Code: [Select]
[...] on creation
        try {
            zombie = Loader.loadMD2(ctx.getResources().getAssets().open("zombie.md2"), 0.1f);
            zombie.translate(0, 7, -3);
            zombie.rotateX((float) (-Math.PI / 2));
            zombie.rotateZ((float) (Math.PI / 2));
            zombie.setTexture("zombieskin");
            zombie.compile();// SOLUTION: that line was the problem, so just remove this line!
            zombie.strip();
            zombie.build();
        } catch (IOException ex) {
            Logger.getLogger(GameRenderer.class.getName()).log(Level.SEVERE, null, ex);
        }
[...] on draw
    float anim = 0;
    public void onDrawFrame(GL10 gl) {
        if (running){
//System.out.println(zombie.getAnimationSequence().getSequence("run"));
            zombie.animate(anim, zombie.getAnimationSequence().getSequence("stand"));
            zombie.rotateZ(0.01f);
            anim += 0.1;
            if (anim >= 1)
                anim = 0;
            fb.clear(BLACK);
            world.renderScene(fb);
            world.draw(fb);
            fb.display();
        } else
            fb.dispose();
    }

Any ideas on what's the problem?

Pages: [1]