public void norm(float x, float y, float z) { Vec3 v = mVert.mNorm; v.x = x; v.y = y; v.z = z; }
public void move() { Vec3 cross = VecMath.Normalize(VecMath.CrossProduct(phone_n, init_phone_n)); Vec3 ny = new Vec3(0, 0, 1); Vec3 cross2 = VecMath.CrossProduct(init_phone_n, ny); float ang2 = (float) Math.asin(VecMath.Norm(cross2) / (VecMath.Norm(init_phone_n))); ; Mat4 rotmat2 = VecMath.ArbRotate(cross2, ang2); // Mat4 rotmat = VecMath.ArbRotate(cross, MainActivity.phone_ang); float phone_ang = MainActivity.phone_ang; Mat4 rotmat = VecMath.ArbRotate(cross, MainActivity.phone_ang); if (Math.abs(init_phone_n.z) > Math.abs(init_phone_n.y)) rotmat = VecMath.ArbRotate( VecMath.MultVec3(VecMath.Rx(-(float) Math.PI / 2), VecMath.Normalize(cross)), MainActivity.phone_ang); Mat4 rotmatf = VecMath.Mult(rotmat, rotmat2); float nx = VecMath.MultVec3(rotmat, new Vec3(0, 1, 0)).x; // float nx = -VecMath.MultVec3(rotmat, VecMath.Normalize(init_phone_n)).x; // float nx = VecMath.MultVec3(rotmat, new Vec3(1,0,0)).x; float nz = VecMath.MultVec3(rotmat, new Vec3(0, 1, 0)).z; // float nz = -VecMath.MultVec3(rotmat, VecMath.Normalize(init_phone_n)).z; // float phone_ang = MainActivity.phone_ang; // float nx = VecMath.DotProduct(VecMath.Normalize(init_phone_n), new Vec3(0,0,0)); // Vec3 init_n = VecMath.Normalize(init_phone_n); // float nx = phone_n.x * init_n.y; // float nz = phone_n.z * init_n.y; // Vec3 normn = VecMath.Normalize(init_phone_n); // Vec3 world_n = new Vec3(init_phone_n.x - phone_n.x, init_phone_n.y-phone_n.y, init_phone_n.z // - phone_n.z); // Vec3 xy = new Vec3(world_n.x, world_n.y, 0); // Vec3 xz = new Vec3((phone_n.x-init_phone_n.x), 0, (phone_n.z-init_phone_n.z)); // Vec3 y = new Vec3(0,init_phone_n.y,0); // Vec3 x = new Vec3(init_phone_n.x,0,0); GLES20.glUniform3f( GLES20.glGetUniformLocation(Shader.program, "spaceship_pos"), pos.x, pos.y, pos.z); GLES20.glUniform3f( GLES20.glGetUniformLocation(Shader.program, "spaceship_fin_pos0"), fin_pos[0].x, fin_pos[0].y, fin_pos[0].z); GLES20.glUniform3f( GLES20.glGetUniformLocation(Shader.program, "spaceship_speed"), speed.x, speed.y, speed.z); GLES20.glUniform3f( GLES20.glGetUniformLocation(Shader.program, "spaceship_speedf"), speed.x, speed.y, speed.z); float ang = MainActivity.phone_ang; if (isthrusting && fuel > 0.0f) { if (fuel > 0.0f) fuel -= .3; GLES20.glUniform1f(GLES20.glGetUniformLocation(Shader.program, "fuel"), fuel); acc.x = thrust * nx; // /5.0f; acc.y = thrust * (float) Math.cos(ang) + gravity; acc.z = thrust * nz; // /5.0f; } else acc.y = gravity; speed.x += acc.x; speed.y += acc.y; speed.z += acc.z; pos.x += speed.x; pos.y += speed.y; pos.z += speed.z; T = VecMath.T(pos); speed.x *= 0.97f; speed.z *= 0.97f; }