Scaling an object (Self Created)

Started by sushobhit, August 11, 2016, 07:10:28 AM

Previous topic - Next topic

sushobhit

 :D

Can anybody plz help with this problem I am stuck with .
I have created a simple cube using
Object3D.addtriangle(sv....)
The problem is I DK how to add scaling capability to it .What are the vec calcs to be applied to make it scalable . Plz .

Here is the code :

      SimpleVector upperLeftFront=new SimpleVector(-0.8,-0.8f,-1);
      SimpleVector upperRightFront=new SimpleVector(0.8,-0.8f,-1);
      SimpleVector lowerLeftFront=new SimpleVector(-0.8,0.8f,-1);
      SimpleVector lowerRightFront=new SimpleVector(0.8,0.8f,-1);
      
      SimpleVector upperLeftBack = new SimpleVector( -0.8, -0.8, 1);
      SimpleVector upperRightBack = new SimpleVector(0.8, -0.8, 1);
      SimpleVector lowerLeftBack = new SimpleVector( -0.8, 0.8, 1);
      SimpleVector lowerRightBack = new SimpleVector(0.8, 0.8, 1);
      
      SimpleVector upperLeftLeft=new SimpleVector(-1,-0.8,0.8 );
      SimpleVector upperRightLeft=new SimpleVector(-1,-0.8,-0.8 );
      SimpleVector lowerLeftLeft=new SimpleVector(-1,0.8,0.8 );
      SimpleVector lowerRightLeft=new SimpleVector(-1,0.8,-0.8 );

      SimpleVector upperLeftRight = new SimpleVector( 1, -0.8, -0.8 );
      SimpleVector upperRightRight = new SimpleVector(1, -0.8, 0.8 );
      SimpleVector lowerLeftRight = new SimpleVector( 1, 0.8, -0.8 );
      SimpleVector lowerRightRight = new SimpleVector(1, 0.8, 0.8 );

      SimpleVector upperLeftUp=new SimpleVector(-0.8,-1,0.8 );
      SimpleVector upperRightUp=new SimpleVector(0.8,-1,0.8 );
      SimpleVector lowerLeftUp=new SimpleVector(-0.8,-1,-0.8 );
      SimpleVector lowerRightUp=new SimpleVector(0.8,-1,-0.8 );

      SimpleVector upperLeftBottom = new SimpleVector( -0.8, 1, 0.8 );
      SimpleVector upperRightBottom = new SimpleVector(0.8, 1, 0.8 );
      SimpleVector lowerLeftBottom = new SimpleVector( -0.8, 1, -0.8 );
      SimpleVector lowerRightBottom = new SimpleVector(0.8, 1, -0.8 );
      
Object3D sample = new Object3D(44);


sushobhit

// Front
      sample.addTriangle(upperLeftFront,0,0, lowerLeftFront,0,1, upperRightFront,1,0);
      sample.addTriangle(upperRightFront,1,0, lowerLeftFront,0,1, lowerRightFront,1,1);

      // Back
      sample.addTriangle(upperLeftBack,1,1, upperRightBack,0,1, lowerLeftBack,1,0);
      sample.addTriangle(upperRightBack,0,1, lowerRightBack,0,0, lowerLeftBack,1,0);

      // Upper
      sample.addTriangle(upperLeftUp,0,0, lowerLeftUp,0,1, upperRightUp,1,0);
      sample.addTriangle(lowerLeftUp,0,1, lowerRightUp,1,1, upperRightUp,1,0);

      // Lower
      sample.addTriangle(upperLeftBottom,0,1, upperRightBottom,1,1, lowerLeftBottom,0,0);
      sample.addTriangle(upperRightBottom,1,1, lowerRightBottom,1,0, lowerLeftBottom,0,0);

      // Left
      sample.addTriangle(upperLeftLeft,0,0, lowerLeftLeft,0,1, upperRightLeft,1,0);
      sample.addTriangle(upperRightLeft,1,0, lowerLeftLeft,0,1, lowerRightLeft,1,1);

      // Right
      sample.addTriangle(upperLeftRight,0,0, lowerLeftRight,0,1, upperRightRight,1,0);
      sample.addTriangle(upperRightRight,1,0, lowerLeftRight, 0,1, lowerRightRight,1,1);


sushobhit

   // Connectors
      sample.addTriangle(lowerLeftUp,0,0,upperLeftFront,0,0.1f,lowerRightUp,0.1f,0);
      sample.addTriangle(lowerRightUp,0.1f,0,upperLeftFront,0,0.1f,upperRightFront,0.1f,0.1f);

      sample.addTriangle(lowerLeftFront,0,0,lowerLeftBottom,0,0.1f,lowerRightFront,0.1f,0);
      sample.addTriangle(lowerRightFront,0.1f,0,lowerLeftBottom,0,0.1f,lowerRightBottom,0.1f,0.1f);
      
      sample.addTriangle(upperLeftBottom,0,0,lowerLeftBack,0,0.1f,upperRightBottom,0.1f,0);
      sample.addTriangle(upperRightBottom,0.1f,0,lowerLeftBack,0,0.1f,lowerRightBack,0.1f,0.1f);//
      
      sample.addTriangle(upperRightUp,0,0,upperRightBack,0,0.1f,upperLeftUp,0.1f,0);
      sample.addTriangle(upperLeftUp,0.1f,0,upperRightBack,0,0.1f,upperLeftBack,0.1f,0.1f);

      sample.addTriangle(lowerRightFront,0,0,lowerLeftRight,0,0.1f,upperRightFront,0.1f,0);
      sample.addTriangle(upperRightFront,0.1f,0,lowerLeftRight,0,0.1f,upperLeftRight,0.1f,0.1f);
      
      sample.addTriangle(lowerRightRight,0,0,lowerRightBack,0,0.1f,upperRightRight,0.1f,0);
      sample.addTriangle(upperRightRight,0.1f,0,lowerRightBack,0,0.1f,upperRightBack,0.1f,0.1f);   

      sample.addTriangle(lowerLeftBack,0,0,lowerLeftLeft,0,0.1f,upperLeftBack,0.1f,0);
      sample.addTriangle(upperLeftBack,0.1f,0,lowerLeftLeft,0,0.1f,upperLeftLeft,0.1f,0.1f);

      sample.addTriangle(lowerRightLeft,0,0,lowerLeftFront,0,0.1f,upperRightLeft,0.1f,0);
      sample.addTriangle(upperRightLeft,0.1f,0,lowerLeftFront,0,0.1f,upperLeftFront,0.1f,0.1f);
      
      sample.addTriangle(upperLeftUp,0,0,upperLeftLeft,0,0.1f,lowerLeftUp,0.1f,0);
      sample.addTriangle(lowerLeftUp,0.1f,0,upperLeftLeft,0,0.1f,upperRightLeft,0.1f,0.1f);

      sample.addTriangle(upperRightRight,0,0,upperRightUp,0,0.1f,upperLeftRight,0.1f,0);
      sample.addTriangle(upperLeftRight,0.1f,0,upperRightUp,0,0.1f,lowerRightUp,0.1f,0.1f);   

      sample.addTriangle(lowerLeftRight,0,0,lowerRightBottom,0,0.1f,lowerRightRight,0.1f,0);
      sample.addTriangle(lowerRightRight,0.1f,0,lowerRightBottom,0,0.1f,upperRightBottom,0.1f,0.1f);

      sample.addTriangle(lowerLeftLeft,0,0,upperLeftBottom,0,0.1f,lowerRightLeft,0.1f,0);
      sample.addTriangle(lowerRightLeft,0.1f,0,upperLeftBottom,0,0.1f,lowerLeftBottom,0.1f,0.1f);
      
      //Fillers
      sample.addTriangle(lowerLeftUp,0,0,upperRightLeft,0,0.1f,upperLeftFront,0.1f,0);
      sample.addTriangle(lowerRightUp,0.1f,0,upperRightFront,0,0.1f,upperLeftRight,0.1f,0.1f);
      sample.addTriangle(upperRightUp,0,0,upperRightRight,0,0.1f,upperRightBack,0.1f,0);
      sample.addTriangle(upperLeftLeft,0.1f,0,upperLeftUp,0,0.1f,upperLeftBack,0.1f,0.1f);
      sample.addTriangle(lowerLeftFront,0,0,lowerRightLeft,0,0.1f,lowerLeftBottom,0.1f,0);
      sample.addTriangle(lowerRightFront,0.1f,0,lowerRightBottom,0,0.1f,lowerLeftRight,0.1f,0.1f);
      sample.addTriangle(upperRightBottom,0,0,lowerRightBack,0,0.1f,lowerRightRight,0.1f,0);
      sample.addTriangle(upperLeftBottom,0.1f,0,lowerLeftLeft,0,0.1f,lowerLeftBack,0.1f,0.1f);
      
sample.build();

EgonOlsen

By calling setScale(...) on the cube? Or does it have to be permanent in the vertors? If so, just multiply every SimpleVector with a constant (SimpleVector.scalarMul()).
Or for non-uniform scaling, multiply the x,y and z coordinates with different constants.

sushobhit

#4
Hi Egon ,

It's working I wanted permanent scaling so I used the second method .

P.S : Just downloaded Naroth from Play Store , just want to congratulate you {Sir} for such excellent graphics and game . As I am following this forum for about 2years now I know how much hard work you have put in it.
:)