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

Pages: 1 ... 3 4 [5] 6 7 ... 13
61
I think pretty much everything in jpct works with radians rather than degrees... :P

62
Support / Re: How to place object at specific location of world?
« on: April 01, 2017, 12:46:32 am »
Uhm... I don't quite understand what you mean... Sorry

63
Support / Re: How to place object at specific location of world?
« on: March 31, 2017, 03:18:54 pm »
Hmmm you could add some scalar to the translation...
model.getRoot().translate(
      -1.5f * targetPosition.x -model.getRoot().getTransformedCenter().x,
      -1.5f * targetPosition.y -model.getRoot().getTransformedCenter().y,
      0);

With 1.5f being your scalar... Which could be any value up to you :)

64
Support / Re: How to place object at specific location of world?
« on: March 31, 2017, 11:18:20 am »
Oh my bad...

model.getRoot().translate(
      -targetPosition.x -model.getRoot().getTransformedCenter().x,
      -targetPosition.y -model.getRoot().getTransformedCenter().y,
      0);

I hope this will work...

65
Support / Re: How to place object at specific location of world?
« on: March 31, 2017, 08:57:06 am »
Oh hmmm, well you could try to swap this:
model.getRoot().translate(
      targetPosition.x -model.getRoot().getTransformedCenter().x,
      targetPosition.y -model.getRoot().getTransformedCenter().y,
      0);

To:
model.getRoot().translate(
      -targetPosition.x +model.getRoot().getTransformedCenter().x,
      -targetPosition.y +model.getRoot().getTransformedCenter().y,
      0);

Which should swap the translation direction into the opposite X and Y direction.

66
Support / Re: How to place object at specific location of world?
« on: March 30, 2017, 11:37:19 pm »
I guess it's best to do the translation when initializing your objects. (So it's just executed once rather than nonstop)
If you really need to do absolute translation during draw calls I guess this could work:

Private variable somewhere in your renderer class:
private SimpleVector absCoords = new SimpleVector (3.3f,3.3f,3.3f);

In your OnDraw loop:
yourObject.translate(absCoords.x -yourObject.getTransformedCenter().x,
absCoords.y -yourObject.getTransformedCenter().y,
absCoords.z -yourObject.getTransformedCenter().z);

This should pretty much keep your Object3D at the absCoords location. Even when you change absCoords during runtime it should still work :)

67
Support / Re: Make the camera follow an object3d
« on: February 07, 2017, 01:07:42 am »
the camera took the spaceships centerposition so it put itself on the spaceship so I cant see him :P. Here is my code https://1drv.ms/u/s!AvWnW88CHl4QhQ3HZryfAKLpa139
That was kind of the idea of the code I gave you...
But try messing a bit more with the second line.
The first line puts the camera at the center of the spaceship and the second line should move the camera 'backwards' with a certain distance.
Try increasing the value of this distance (I'd say somewhere between 3f and 21f...? But it depends how big your spaceship object is too...)

camera.setPosition(spaceship.getTransformedCenter());
camera.moveCamera(Camera.CAMERA_MOVEOUT, someDistance);



but im using the jcpt-ae. How can I load a texture into the Texture?
Eh... I suppose you're making an Android app... right?
You can use load images from drawables in Android and turn it into a Bitmap and then turn it into a Texture
http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Texture.html
http://www.jpct.net/jpct-ae/doc/com/threed/jpct/util/BitmapHelper.html
Tip: since OpenGL prefers textures with sides that are a power of 2... I recommend you to place the images in a 'drawable-nodpi' folder so Android won't resize these...

68
Support / Re: Make the camera follow an object3d
« on: February 05, 2017, 02:09:45 pm »
Hmmm, I see...

What about:
camera.setPosition(spaceship.getTransformedCenter());
camera.moveCamera(Camera.CAMERA_MOVEOUT, someDistance);

someDistance is a float value that would be totally up to you :)

69
Support / Re: Make the camera follow an object3d
« on: February 05, 2017, 11:07:22 am »
camera.lookAt(spaceship.getTransformedCenter());
Something like that?

70
Support / Re: Why does jPCT-AE need to keep the texture in the VM memory?
« on: January 06, 2017, 11:37:08 pm »
Well for example this texture: https://commons.wikimedia.org/wiki/File:ESO_-_Milky_Way.jpg
On lower resolution it looks uglier than with 8192x4096...
So I suppose that's why I thought splitting it into 4 parts would reduce the maximum VM memory usage at a point. (which does happen; but the result is not satisfactory...)

71
Support / Re: Why does jPCT-AE need to keep the texture in the VM memory?
« on: January 06, 2017, 04:08:39 pm »
Is there another solution? To load textures this way to not hit high VM memory usage and still get the textures to work properly on the Object3D's vertices?

72
Support / Re: Why does jPCT-AE need to keep the texture in the VM memory?
« on: January 06, 2017, 02:13:51 pm »
Basically like in this fragment shader:
Code: [Select]
precision highp float;
precision highp int;

uniform sampler2D textureUnit0;
uniform sampler2D textureUnit1;
uniform sampler2D textureUnit2;
uniform sampler2D textureUnit3;
varying vec2 texCoord0;

void main() {
float xVal = texCoord0.x;
float yVal = texCoord0.y;

vec4 base;

if(xVal < 0.5){
// tex0 or tex2
if(yVal < 0.5){
// tex0
base = texture2D(textureUnit0, vec2(xVal*2.0,yVal*2.0));
}else{
base = texture2D(textureUnit2, vec2(xVal*2.0, yVal*2.0 - 1.0));
}
}else{
// tex1 or tex3
if(yVal < 0.5){
// tex1
base = texture2D(textureUnit1, vec2(xVal*2.0 - 1.0,yVal*2.0));
}else{
// tex3
base = texture2D(textureUnit3, vec2(xVal*2.0 - 1.0,yVal*2.0 - 1.0));
}
}

gl_FragColor = base;
}
It works but it kind of looks ugly around the borders of the textures...
I actually used texture.setClamping(true) so not 'false' to make it look better around the borders which kind of worked.
But it only looks better for higher resolution textures.
Let's say I have 4 lower resolution textures, then these borders become visible again which I don't really want. (it should just work like a single texture)

See attachment for clarification :)

73
Support / Re: Why does jPCT-AE need to keep the texture in the VM memory?
« on: January 05, 2017, 11:11:30 pm »
I wanted to optimize texture loading so I tried splitting the texture into 4 parts.
So a 8192x4096 texture now is 4 * 4096x2048 textures.

So why split?: Because I'll be uploading the texture after it has loaded and textures use a lot in VM memory and I thought this would be a nice solution to split the textures, so the VM memory doesn't go up as much as with a complete texture...

I added these 4 textures to the Object3D and in the shader I'd use the texcoords to select which texture to use (and change the texcoords so it draws the texture properly on the Object3D's vertices)...
However, the results seem kind of ugly and it's not as I hoped it would be... Using a complete texture in the shader looked better than 4 split textures. texture.setClamping(false) helped but it's still kind of visible on the Object3D that the textures are split...

Is there some way to merge these 4 textures into 1 texture without the Bitmap stuff in Android since that obviously just uses memory? The textures are immediately uploaded after loading so the VM memory only 'spikes' up when the Bitmap instance is still used for uploading...
I suppose jPCT and OpenGL see these textures as texture layers but actually they're just next to each other.

74
Support / Re: Why does jPCT-AE need to keep the texture in the VM memory?
« on: December 27, 2016, 10:36:08 pm »
My version:
Code: [Select]
import com.threed.jpct.Camera;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Interact2D;
import com.threed.jpct.Object3D;
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;

/**
 * A simple lens flare effect. You need five different textures for this, one burst and four halos. How
 * to create/get these textures is up to you. jPCT doesn't come with any.
 * @author EgonOlsen & AeroShark333
 */
public class CustomLensFlare implements java.io.Serializable {
private static final long serialVersionUID = 1L;

private final SimpleVector sunPos;

private final Texture[] types;
private final float[][] scales;

private float globalScale=1;
private float burstScale=1;
private int trans=1;
private int burstTrans = 1;

private boolean cover=true;
private float maxDistance=-1;
private boolean revertDirection=false;

private boolean visible=false;
private SimpleVector light2D=null;

private final SimpleVector tmp1;
private final SimpleVector tmp2;
private final SimpleVector tmp3;

/**
* Create a new lens flare for a light source.
* Note: call initializeLensFlare(String texturenames...) before using this LensFlare
* @param lightPos the position of the light source
*/
public CustomLensFlare(final SimpleVector lightPos) {
this.sunPos=new SimpleVector(lightPos);
this.types=new Texture[7];

scales = new float[7][2];
scales[0][0]=1;
scales[0][1]=1;
scales[1][0]=2;
scales[1][1]=0.5f;
scales[2][0]=3;
scales[2][1]=0.25f;
scales[3][0]=8;
scales[3][1]=1;
scales[4][0]=-2;
scales[4][1]=0.5f;
scales[5][0]=-4;
scales[5][1]=0.25f;
scales[6][0]=-5.5f;
scales[6][1]=0.25f;

tmp1=new SimpleVector();
tmp2=new SimpleVector();
tmp3=new SimpleVector();
}
/**
* Create a new lens flare for a light source.
* @param lightPos the position of the light source
* @param burst the name of the burst texture as added to the TextureManager
* @param halo1 the name of the first halo texture as added to the TextureManager
* @param halo2 the name of the second halo as added to the TextureManager
* @param halo3 the name of the third halo texture added to the TextureManager
* @param halo4 the name of the fourth (repeating) halo texture added to the TextureManager
*/
public CustomLensFlare(final SimpleVector lightPos, final String burst, final String halo1, final String halo2, final String halo3, final String halo4) {
this(lightPos);
this.initializeLensFlare(burst, halo1, halo2, halo3, halo4);
}

/**
* Call this when you are sure the textures needed for this lensflare have been set
* @param burst the name of the burst texture as added to the TextureManager
* @param halo1 the name of the first halo texture as added to the TextureManager
* @param halo2 the name of the second halo as added to the TextureManager
* @param halo3 the name of the third halo texture added to the TextureManager
* @param halo4 the name of the fourth (repeating) halo texture added to the TextureManager
*/
public void initializeLensFlare(final String burst, final String halo1, final String halo2, final String halo3, final String halo4){
final TextureManager tm=TextureManager.getInstance();
final Texture repeatedHalo=tm.getTexture(halo4);

types[0]=tm.getTexture(burst);
types[1]=tm.getTexture(halo1);
types[2]=repeatedHalo;
types[3]=tm.getTexture(halo2);
types[4]=repeatedHalo;
types[5]=tm.getTexture(halo3);
types[6]=repeatedHalo;
}

/**
* Sets the transparency of the effect.
* @param trans the transparency. 0 is lowest,
*/
public void setGlobalTransparency(int trans) {
this.trans=trans;
}

/**
* Sets the transparency of the burst effect.
* @param trans the transparency. 0 is lowest,
*/
public void setBurstTransparency(int trans) {
this.burstTrans=trans;
}


/**
* Sets a new light position.
* @param lightPos the new position
*/
public void setLightPosition(SimpleVector lightPos) {
sunPos.set(lightPos);
}

/**
* Sets the burst scale of the effect.
* @param scale the scale
*/
public void setBurstScale(float scale) {
burstScale=scale;
}

/**
* Sets the global scale of the effect.
* @param scale the scale
*/
public void setGlobalScale(float scale) {
globalScale=scale;
}

/**
* If true (default), all geometry that is a potential collider hides the effect if it's located in
* a direct line between the camera and the light source.
* @param hides should geometry hide it or not?
*/
public void setHiding(boolean hides) {
cover=hides;
}

/**
* If hiding is enabled, this value specifies how far away from the camera a polygon can maximally be
* to be considered as a blocker. Anything farer away can't hide the effect. Lowering this value can improve
* performance but may lead to flares where non should be. -1 is default, which means no limits.
* @param distance the distance
*/
public void setMaximumDistance(float distance) {
this.maxDistance=distance;
}

/**
* If hiding is enabled, the visibility calculations can be done camera->light (default) or light->camera. Depending
* on the scene, one or the other will be faster.
* @param lightToCam do it light->camera or vice versa
*/
public void setDirection(boolean lightToCam) {
revertDirection=lightToCam;
}

/**
* Updates the lens flare. Skipping this method and calling render only will cause the lens flare to remain static.
* This method should be called if either the camera or, if hiding is enabled, the hiding objects are moving.
* @param buffer the frame buffer
* @param world the world
*/
public void update(FrameBuffer buffer, World world) {
Camera cam=world.getCamera();
light2D=Interact2D.project3D2D(cam, buffer, sunPos, tmp3);
visible=true;
if (cover) {
SimpleVector camPos=cam.getPosition(tmp1);
if (!revertDirection) {
// From camera to light
SimpleVector delta=camPos;
tmp2.set(camPos);
delta.scalarMul(-1);
delta.add(sunPos);
float dlen=delta.length();
float dist=world.calcMinDistance(tmp2, delta.normalize(delta), maxDistance!=-1?Math.min(maxDistance, dlen*1.05f):dlen*1.05f);
//System.out.println("1: "+ dist+"/"+(dlen-5));
visible=(dist==Object3D.COLLISION_NONE || dist>dlen-5);
} else {
// From light to camera
tmp2.set(sunPos);
tmp2.scalarMul(-1);
SimpleVector delta=camPos;
delta.add(tmp2);
float dlen=delta.length();
float dist=world.calcMinDistance(sunPos, delta.normalize(delta), maxDistance!=-1?Math.min(maxDistance, dlen*1.05f):dlen*1.05f);
visible=(dist==Object3D.COLLISION_NONE || dist>dlen-5);
//System.out.println("2: "+ dist+"/"+(dlen-5));
}
}
}

/**
* Renders the effect.
* @param buffer the frame buffer
*/
public void render(FrameBuffer buffer) {

if (light2D!=null && visible) {
SimpleVector lp=tmp1;
lp.set(light2D);
float mx=buffer.getCenterX();
float my=buffer.getCenterY();
lp.z=0;
SimpleVector cp=tmp2;
cp.set(mx,my,0);
cp.scalarMul(-1);
lp.add(cp);
SimpleVector dir=lp;
float len=dir.length();
dir=dir.normalize(dir);
SimpleVector d=tmp2;
d.set(0, 0, 0);

for (int i=0; i<types.length; i++) {
d.set(dir);
Texture t=types[i];
float l=scales[i][0];
float scale=scales[i][1]*(i==0? burstScale:globalScale);
int trans2 = (i==0? this.burstTrans:this.trans);
d.scalarMul((1f/l)*len);
int tw=t.getWidth();
int th=t.getHeight();
int x=(int)(d.x-((tw>>1)*scale))+(int)mx;
int y=(int)(d.y-((th>>1)*scale))+(int)my;
int dw = (int)((float)tw*scale*0.5f);
int dh = (int)((float)th*scale*0.5f);
// upper-left
buffer.blit(t, 0, 0, x, y, tw, th, dw, dh, trans2, true, RGBColor.WHITE);
// upper-right
buffer.blit(t, 0, 0, x+2*dw, y, tw, th, -dw, dh, trans2, true, RGBColor.WHITE);
// bottom-left
buffer.blit(t, 0, 0, x, y+2*dh, tw, th, dw, -dh, trans2, true, RGBColor.WHITE);
// bottom-right
buffer.blit(t, 0, 0, x+2*dw, y+2*dh, tw, th, -dw, -dh, trans2, true, RGBColor.WHITE);
}
}
}
}

I hope it's okay to share this; if not then I guess you can delete my post :P
This modified class should be suitable for circular shaped lensflare textures.
So your texture images can be reduced to this part of the circular texture image: http://etc.usf.edu/clipart/40500/40550/pie_01-04n_40550_lg.gif :)
I guess the original lens flare textures don't take up that much memory anyway but oh well...

75
Support / Re: Why does jPCT-AE need to keep the texture in the VM memory?
« on: December 25, 2016, 04:16:16 am »
I see, thanks for answering :)
And eh, nevermind the 16k resolution textures...
I guess I just got curious there

I have a small request however...
May I have the source code of the LensFlare class, learn from it, modify it and use it? (I'll probably end up writing my own class then)
So why?...
Well there's a few things I want to change/add I guess:
-> I want to use 5 textures in total
-> I don't want the burst texture to be repeated in the lens flare (that's where the 5th texture comes in)
-> I want to give the burst it's own scaling which isn't done with the global scaling
-> I don't really know how to get the 2D coordinates for blitting from this 3D world
-> I want to use 1/4th part of a 'complete texture'

My lens flare images are all spherical so...
I basically could just use 1/4th of this texture and blit it 4 times (by flipping the blit). (relying on the assumption that the LensFlare class uses blits and not it's own Object3D's)

And Merry Christmas by the way :D

Pages: 1 ... 3 4 [5] 6 7 ... 13