Author Topic: Applying VertexController causes the model to dark-out  (Read 2253 times)

Offline Darai

  • byte
  • *
  • Posts: 45
    • View Profile
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;
}
}
 ...

Offline AeroShark333

  • float
  • ****
  • Posts: 319
    • View Profile
Re: Applying VertexController causes the model to dark-out
« Reply #1 on: October 15, 2016, 01:24:13 pm »
Looks fine to me...

Would it help to add this after this.touch() in the pulse method?
Code: [Select]
this.calcNormals();
this.calcTangentVectors();

Offline Darai

  • byte
  • *
  • Posts: 45
    • View Profile
Re: Applying VertexController causes the model to dark-out
« Reply #2 on: October 15, 2016, 02:11:22 pm »
That worked,  :)
thank you.