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

Pages: [1]
1
Support / Applying VertexController causes the model to dark-out
« on: October 15, 2016, 11:50:10 am »
Hi,

I have here a strange behaviour you surely know what to do with. It looks so obvious that it must be a mistake on my side. But I am still new in this so I am asking for your help.

I created a simple object and apply to it a vertex controller. (and put lamp and ambient lighting) In the moment I applied the controller, the object get's darker and stays that way. Like the sun does not apply for the object any more. Do you know why and how to fix it? How does it look can be seen in the attached screenshots.

Thank you,
Darai.

The renderer
Code: [Select]
public void onSurfaceChanged(GL10 gl, int w, int h) {
...
world = new World();
world.setAmbientLight(20, 20, 20);
 
sun = new Light(world);
sun.setIntensity(250, 250, 250);

sqr = new MiniMonster3D();

sqr.setTexture("Tex");
sqr.setScale(10f);
sqr.build();

world.addObject(sqr);
Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
cam.lookAt(sqr.getTransformedCenter());

SimpleVector sv = new SimpleVector();
sv.set(sqr.getTransformedCenter());
sv.y -= 100;
sv.z -= 100;
sun.setPosition(sv);
MemoryHelper.compact();
...
}

public void onDrawFrame(GL10 gl) {
...
  if (System.currentTimeMillis() - time >= 100) {
    //Logger.log(fps/10 + "fps");
    fps = 0;
    time = System.currentTimeMillis();
    sqr.pulse();
  }
  fps++;
...
}

the Object
Code: [Select]
public class MiniMonster3D extends Object3D {

public MiniMonster3D(){
super(2);
SimpleVector LU = new SimpleVector(-0.5f, -0.5f, 0f);
SimpleVector LD = new SimpleVector(-0.5f, 0.5f, 0f);
SimpleVector RU = new SimpleVector(0.5f, -0.5f, 0f);
SimpleVector RD = new SimpleVector(0.5f, 0.5f, 0f);
this.addTriangle(LU,0,0,LD,0,1,RD,1,1);
this.addTriangle(LU,0,0,RD,1,1,RU,1,0);
this.getMesh().setVertexController(new MyVertexController(), false);
}

public void pulse(){
this.getMesh().applyVertexController();
this.touch();
}
}

the Controller
Code: [Select]
public class MyVertexController extends GenericVertexController {
 ...
@Override
public void apply() {
nextScale();
Log.i("VC", "pulse, scale = "+myscale);
SimpleVector[]out = getDestinationMesh();
SimpleVector[]in  = getSourceMesh();
SimpleVector tgt, src;
for(int i = 0;i<3;i++){
tgt = out[i];
src = in[i];
tgt.x = src.x*myscale;
tgt.y = src.y*myscale;
tgt.z = src.z*myscale;
}
}
 ...

2
Support / SystemUI swap & Failed to create frame buffer
« on: February 10, 2016, 02:15:40 pm »
Hello again,

here is a new issue I would like to ask about. I am testing the code with the blitting to texture you gave me (thanks again EgonOlsen so much) http://www.jpct.net/forum2/index.php/topic,4609.0.html. I implemented several performance tests and now I'm trying following situation:
  • Blit to the texture every frame
  • Have more than one object on the screen (in my example 100)
  • Try to call DecorView.setSystemUiVisibility() to show/hide the system icons of the phone. For simple, I have it here initiated by touching the screen

What is the expected problem: The program calls the main activity thread to swap the UI visibility, which initiates new onSurfaceChange run of the renderer and recreates the buffer. And in the same time use intensively the buffer by the blit function on multiple objects.

Here is the entire test activity:
Code: [Select]
package com.threed.jpct.example;

import java.lang.reflect.Field;
import java.util.Random;

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

import android.annotation.SuppressLint;
import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

import com.threed.jpct.Camera;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Light;
import com.threed.jpct.Logger;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.RGBColor;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;
import com.threed.jpct.util.BitmapHelper;
import com.threed.jpct.util.MemoryHelper;

/**
 * @author Darai
 *
 */
public class HelloWorld extends Activity {

private static HelloWorld master = null;

private GLSurfaceView mGLView;
private MyRenderer renderer = null;
private FrameBuffer fb = null;
private World world = null;

private int fps = 0;

private Light sun = null;

private RGBColor back = RGBColor.BLACK;

private static final int SWAP_UI = 1;
private boolean swapUI = false;

private Random rand = new Random();

    // Handle the message for turning on and off the immersive GUI
public static Handler handler = new Handler(Looper.getMainLooper()){
public void handleMessage(Message message) {
    // Handle the message on the thread associated to the given looper.
    if (message.what == HelloWorld.SWAP_UI) { swapSystemUIdo();}
  }
};

public static int countSquares = 0;
public Square[] squares = new Square[100];
public Texture texture;
public static Object frameBufferSync = new Object();

    // We are having 100 squares with blitting to their textures on every tick
public class Square{
private final int curID = countSquares++;
private final String texName = "squateTex/"+curID;
public static final float f = 5f;
public Object3D obj;
public Texture tex;

    // Create texture and object
public Square(){
obj = Primitives.getPlane(1, (float)rand.nextFloat()+0.5f);
tex = new Texture(64,64);
TextureManager.getInstance().addTexture(texName, tex);
world.addObject(obj);
obj.translate(2*rand.nextFloat()*f - f, 2*rand.nextFloat()*f - f, 0);
obj.setTexture(texName);
obj.build();
}

    // redo the texture on every tick (clear and blit)
public void onTick(){
fb.sync();
fb.setRenderTarget(tex);
int col = rand.nextInt(50)+200;
fb.clear(new RGBColor(col,col,col));
int x = convertX(fb, 5);
int y = convertY(fb, tex.getHeight() - 5);
int width = convertX(fb, tex.getWidth()-10);
int height = -convertY(fb, tex.getHeight()-10);
fb.blit(texture, 0, 0, x, y, 64, 64, width, height, -1, false, null);
fb.display();
fb.removeRenderTarget();
}

public int convertX(FrameBuffer buffer, int x) {
return (int) ((float) x * ((float) buffer.getWidth() / (float) tex.getWidth()));
}

public int convertY(FrameBuffer buffer, int y) {
return (int) ((float) y * ((float) buffer.getHeight() / (float) tex.getHeight()));
} }

protected void onCreate(Bundle savedInstanceState) {

Logger.log("onCreate");

if (master != null) {
copy(master);
}

super.onCreate(savedInstanceState);

mGLView = new GLSurfaceView(getApplication());
mGLView.setEGLContextClientVersion(2);

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

@Override
protected void onPause() {
super.onPause();
mGLView.onPause();
}

    // Swap System UI Send message to the main Activity thread.
public static void swapSystemUI(){
Message message = new Message();
message.what = HelloWorld.SWAP_UI;
HelloWorld.handler.sendMessage(message);
}

    // Swap System UI - do the work (this is the right thread which can do this)
@SuppressLint("InlinedApi")
protected static void swapSystemUIdo() {
Log.i("MainActivity", "swapUI");
    // Set the IMMERSIVE flag.
    // Set the content to appear under the system bars so that the content
    // doesn't resize when the system bars hide and show.
        int uiSetting = HelloWorld.getApp().getWindow().getDecorView().getSystemUiVisibility();
        int ver = Build.VERSION.SDK_INT;
        if(ver>=14){uiSetting ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;}
        if(ver>=16){uiSetting ^= View.SYSTEM_UI_FLAG_FULLSCREEN;}
        if(ver>=19){uiSetting ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;}       
        HelloWorld.getApp().getWindow().getDecorView().setSystemUiVisibility(uiSetting);
}

@Override
protected void onResume() {
super.onResume();
mGLView.onResume();
}

@Override
protected void onStop() {
super.onStop();
System.exit(0);
}

private void copy(Object src) {
try {
Logger.log("Copying data from master Activity!");
Field[] fs = src.getClass().getDeclaredFields();
for (Field f : fs) {
f.setAccessible(true);
f.set(this, f.get(src));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public boolean onTouchEvent(MotionEvent me) {

if (me.getAction() == MotionEvent.ACTION_DOWN) {
return true;
}

if (me.getAction() == MotionEvent.ACTION_UP) {
swapUI = true;
return true;
}

if (me.getAction() == MotionEvent.ACTION_MOVE) {
return true;
}

try {
Thread.sleep(15);
} catch (Exception e) {
// No need for this...
}

return super.onTouchEvent(me);
}

protected boolean isFullscreenOpaque() {
return true;
}

class MyRenderer implements GLSurfaceView.Renderer {

private long time = System.currentTimeMillis();

public MyRenderer() {
}

public void onSurfaceChanged(GL10 gl, int w, int h) {

// Renew the frame buffer
synchronized(frameBufferSync){
if (fb != null) {
fb.dispose();
}
fb = new FrameBuffer(w, h);
fb.setVirtualDimensions(fb.getWidth(), fb.getHeight());
}

// Create the world if not yet created
if (master == null) {
world = new World();
world.setAmbientLight(20, 20, 20);

sun = new Light(world);
sun.setIntensity(250, 250, 250);

// Create the texture we will use in the blitting
texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.icon)), 64, 64));
TextureManager.getInstance().addTexture("texture", texture);

// Create the 100 objects
for(int i = 0;i<squares.length;i++){squares[i]=new Square();}

Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 15);
cam.lookAt(SimpleVector.ORIGIN);

SimpleVector sv = new SimpleVector();
sv.set(SimpleVector.ORIGIN);
sv.y -= 100;
sv.z -= 100;
sun.setPosition(sv);
MemoryHelper.compact();

if (master == null) {
Logger.log("Saving master Activity!");
master = HelloWorld.this;
}
}
}

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

public void onDrawFrame(GL10 gl) {

// If the switch is on, call the UI swap in the correct thread
if (swapUI) {
HelloWorld.swapSystemUI();
swapUI = false;
}

synchronized(frameBufferSync){
// Blit to all the objects
for(int i = 0;i<squares.length;i++){squares[i].onTick();}

// Draw the main screen
fb.clear(back);
world.renderScene(fb);
world.draw(fb);
world.getCamera().moveCamera(Camera.CAMERA_MOVEOUT, 0.1f);
world.getCamera().rotateCameraZ(0.01f);

fb.display();
}

if (System.currentTimeMillis() - time >= 1000) {
Logger.log(fps + "fps");
fps = 0;
time = System.currentTimeMillis();
}
fps++;
}
}

public static HelloWorld getApp(){return master;}
}


Well, I have got an error message and app run failure. The error is fixed on the blit function, if I don't blit, it works just fine. The synchronization I tried in this example didn't helped.
Quote
02-10 13:55:58.411: E/jPCT-AE(19599): [ 1455108958411 ] - ERROR: Failed to create frame buffer (102): glError 1282
02-10 13:55:58.470: E/AndroidRuntime(19599): FATAL EXCEPTION: GLThread 7271
02-10 13:55:58.470: E/AndroidRuntime(19599): Process: com.threed.jpct.example, PID: 19599
02-10 13:55:58.470: E/AndroidRuntime(19599): java.lang.RuntimeException: [ 1455108958411 ] - ERROR: Failed to create frame buffer (102): glError 1282
02-10 13:55:58.470: E/AndroidRuntime(19599):    at com.threed.jpct.Logger.log(Logger.java:206)
02-10 13:55:58.470: E/AndroidRuntime(19599):    at com.threed.jpct.GL20.checkError(GL20.java:158)
02-10 13:55:58.470: E/AndroidRuntime(19599):    at com.threed.jpct.GL20.setRenderTarget(GL20.java:2007)
02-10 13:55:58.470: E/AndroidRuntime(19599):    at com.threed.jpct.GLRenderer.setRenderTarget(GLRenderer.java:2111)
02-10 13:55:58.470: E/AndroidRuntime(19599):    at com.threed.jpct.FrameBuffer.setRenderTarget(FrameBuffer.java:260)
02-10 13:55:58.470: E/AndroidRuntime(19599):    at com.threed.jpct.FrameBuffer.setRenderTarget(FrameBuffer.java:222)
02-10 13:55:58.470: E/AndroidRuntime(19599):    at com.threed.jpct.example.HelloWorld$Square.onTick(HelloWorld.java:94)
02-10 13:55:58.470: E/AndroidRuntime(19599):    at com.threed.jpct.example.HelloWorld$MyRenderer.onDrawFrame(HelloWorld.java:277)
02-10 13:55:58.470: E/AndroidRuntime(19599):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1535)
02-10 13:55:58.470: E/AndroidRuntime(19599):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

Do you EgonOlsen or you guys know what to do with this?
Thanks for any help, Darai.

3
Support / More FrameBuffers in one program
« on: January 27, 2016, 02:39:41 pm »
Hello,

I am trying to test bliting to an existing texture. I know, there is a warning sign don't do it, but I wanted to test it and I found a strange behaviour:

I have the renderer's function onSurfaceChange, creating the world and it's objects. In this function, I create 2 frame buffers, one for the standard rendering and one for the rendering into the texture. BUT once I make a second FrameBuffer with the same GL10 the screen shrinks to the size of the new frame buffer no matter what. So, I should maybe call different GL10? Or how can I create more independent FrameBuffers?

Code: [Select]
FrameBuffer fb;
FrameBuffer toTex;

public void onSurfaceChanged(GL10 gl, int w, int h) {
fb = new FrameBuffer(gl, w, h);
toTex = new FrameBuffer(gl, 256, 256);
...
}

public void onDrawFrame(GL10 gl) {
...
fb.display;
}

And to the larger problem, I would like to blit a text to a texture. I see here 4 ways:
1) blit to screen every frame: Too slow and can't skew the text.
2) create an object with 2 Triangle Sprite for every letter: Fine, but creates a complex Object3D
3) blit to bitmap using Canvas and replace texture in TextureManager: Unrecomended since texture replace(== upload a new texture to GPU), Canvas and Bitmap object is (i expect) much slower than Texture and FrameBuffer operations.
4) blit directly to texture using FrameBuffer.setRenderTarget(): This is unrecomended in the documentation by Egon but I don't know why.

So my question to the larger problem is: Why is the 4th approach not recomended since from this point of view it is probably the fastest one. (For a text which will not change every frame) And what would you pick and why?

Thanks for all advices.

4
Support / What to do with Error: Couldn't build()
« on: October 12, 2015, 05:00:07 pm »
Hi guys,

I am now writing my code for some time and suddenly I am getting "Error: Couldn't build() ..."

It writes me, that I should check if I have:
1) the object assigned to a world ... which I solve by calling world.addObject(object) right on the previous line
2) if the TextureManager has all the necesary textures loaded ... which I check by calling TextureManager.getInstance().getTextureID(this.texName)

Well I don't know if that is all I can do to check what is wrong. I also don't know if this is all that can cause this error. So, do you have any suggestions what to do next in situation like this?

Thanks,
Martin.

5
Support / project 2D to 3D has problem with (full)screen
« on: October 23, 2014, 09:55:01 am »
SOLVED

Hi guys,

To say this in more words, there is a difference in the result I get from Interact2D.reproject2D3DWS() depending on my screen status (with/without the system lines).

In the case I have full screen with full immersive, the resulting vector hits precisely under my touch
In the case I have the system trail and buttons visible, the result is like 5mm down (+y)  from the actual touch point

Do you have the same problem? How do you deal with it?

Thanks for all the help,
Darai.

The solution: Something I found on stackowerflow.com
Code: [Select]
public int getStatusBarHeight() {
            int result = 0;
            int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
            if (resourceId > 0) {
                result = getResources().getDimensionPixelSize(resourceId);
            }
            return result;
        }
Extracts the statusbar height from the applet R file.

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

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

8
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

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