Author Topic: 2nd object  (Read 4845 times)

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
2nd object
« on: February 11, 2008, 07:10:38 am »
I'm starting with the cartoon network code for a framework because it's small and a little easier to understand and I'm rusty with my Java.  Anyway, I have an object loaded from this code:

Code: [Select]
Object3D[] obj= Loader.load3DS("Shadow.3DS", 1);


      Object3D Toy=new Object3D(0);
       
       
        for (int i=0; i<obj.length; i++) {
           Object3D part=obj[i];

           part.setCenter(SimpleVector.ORIGIN);
           part.rotateX((float)-Math.PI);
           part.rotateMesh();
           part.setRotationMatrix(new Matrix());
         
          Toy=Object3D.mergeObjects(Toy, part);
        }
           
           
  Toy.translate(0, 0, 0);

What I don't quite understand is it starts out with this Object3d array named obj, loads the model, and doesn't mention it again until it's rotating some parts.  What I'd like to know is how would I load the next object and would that rotation code that  sets it aright with the world work for the second object also, or is that just parts of one object and it has to be redone?

So, this code was made for some kind of cartoon effect, but I want to modify it so it just loads multiple objects and sets them right side up.
« Last Edit: February 11, 2008, 07:56:35 am by fireside »
click here->Fireside 7 Games<-

Offline Jonas

  • byte
  • *
  • Posts: 41
    • View Profile
Re: 2nd object
« Reply #1 on: February 11, 2008, 01:13:15 pm »
Hi

Loading a 3ds model may result in more than one Object3D(e.g. in the cartoon example theres an object for the hand, one for the body and so on...).

So what that code does is to rotate all these parts of the loaded model. It is then merged into one bigger object3d representing the whole model.

If you want to load multiple models that way, just pack it into a method. Like

Code: [Select]
public Object3D loadModel(String filename, float scale)
{
Object3D[] model = Loader.load3DS(filename, scale);

Object3D o3d = new Object3D(0);
 
Object3D temp = null;
     
  for (int i=0; i<obj.length; i++)
{
temp=model[i];
temp.setCenter(SimpleVector.ORIGIN);
  temp.rotateX((float)-Math.PI);
  temp.rotateMesh();
  temp.setRotationMatrix(new Matrix());
  o3d=Object3D.mergeObjects(o3d, temp);
  }
return o3d;           
}

and use this one in your code.
Simple things should be simple, complex things should be possible - Alan Kay

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: 2nd object
« Reply #2 on: February 11, 2008, 02:40:18 pm »
O.K.  Thanks.
I'm having a kind of rendering problem, now.  This is a mouse on a platform.  The platform is, you know, like any platform, but it seems like it doesn't look right.  It should be lighter on top.  The light is above and in front.  The mouse looks right, but the platform looks funny.

click here->Fireside 7 Games<-

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: 2nd object
« Reply #3 on: February 11, 2008, 02:56:48 pm »
That's caused by the low tesselation of the platform. Vertex lighting is calculated for vertices only and linear interpolated across the polygon. Therefore, no part of a polygon can be brighter than the brightest vertex. In your case, the vertices are quite far away from the light compared to the mouse which is why the whole platform appears quite dark. Use more polygons for the platform an see how it gets brighter...at least it should... ;)

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: 2nd object
« Reply #4 on: February 11, 2008, 09:59:37 pm »
The normals were turned around on the model, which didn't help either.  It looks pretty good when the normals are the right way.
click here->Fireside 7 Games<-