How to approximate an object?

How to approximate an object using acceleration function and formulas from physics? Here is my program now. For some reasons it doesn't approximate my box correctly like in the real life.

camX = map(m, 0, width,-200,200);
camY = map(k, 0, width,-200,200);
camZ = map(n, 0, width,-200,200);   
camera(-camY+300,0,-camY+200,-camZ,camX,0,0,-1,0)
fill (0,0,255);
box(150);

t1 =  0.7
aZ = accelerationZ;
S1 = Vox*t1 + (aZ*t1*t1)/2;
if (aZ>-0.2 && aZ<0.2) {Vox = 0}
else {Vox = Vox + aZ*t1;}
k = k + S1;
S1 = 0;

I need to do it more realistic. Could you help me?

Answers

  • Post all the code. That is not enough.

  • var camX;
    var camY;
    var camZ;
    var Vox = 0;
    var aZ = 0;
    var k = 400;
    var m = 400;
    var n = 400;
    var t1 = 0;
    
    function setup() 
    {createCanvas(windowWidth, windowHeight, WEBGL);}
    
    function draw(){
    background(90); 
    camX = map(m, 0, width,-200,200);
    camY = map(k, 0, width,-200,200);
    camZ = map(n, 0, width,-200,200);   
    camera(-camY+300,0,-camY+200,-camZ,camX,0,0,-1,0)   
    fill (0,0,255);
    box(150);
    
    t1 =  0.7
    aZ = accelerationZ;
    S1 = Vox*t1 + (aZ*t1*t1)/2;
    if (aZ>-0.2 && aZ<0.2) {Vox = 0}
    else {Vox = Vox + aZ*t1;}
    k = k + S1;
    S1 = 0;}
    
  • What do you mean by approximate?

    Movement pattern?

  • Yes, I move my device and I want the camera in the program simulate the movement to and from the cube

  • Answer ✓

    I found out the problem: my acceleration becomes negative when I move to the cube and it becomes positive when I move away from the cube. After this according to formula it changes the variable S1

  • remember that you can press ctrl-t in processing to get better indents (auto-format)

Sign In or Register to comment.