196
Support / Re: how to rotate a model base on euler angle (pitch, yaw, roll)?
« on: April 02, 2017, 11:03:46 am »
I think pretty much everything in jpct works with radians rather than degrees...
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.
the camera took the spaceships centerposition so it put itself on the spaceship so I cant see him . Here is my code https://1drv.ms/u/s!AvWnW88CHl4QhQ3HZryfAKLpa139That was kind of the idea of the code I gave you...
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?
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...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);
}
}
}
}