wishkah353
09-16-2008, 09:55 PM
can someone pls help? at the bottom of the code i thought i was initializing the array correctly, but compiler doesn't like me =(
import java.lang.Math;
public class VMath {
public static void main(String[] args) {
float[] v0 = { 0f, 5f, 10f };
float[] v1 = { 5f, 6f, 7f };
float[] v2 = { 2f, 3f, 0f };
System.out.println ("Len(v0): " + length(v0));
System.out.println ("Len(v1): " + length(v1));
System.out.println ("Len(v2): " + length(v2));
System.out.print ( "\nNormal(v0): " );
print ( normalize( v0 ) );
System.out.print ( "Normal(v1): " );
print ( normalize( v1 ) );
System.out.print ( "Normal(v2): " );
print ( normalize( v2 ) );
System.out.println ( "\nv0.v1: " + dot_product(v0, v1));
System.out.println ( "v0.v2: " + dot_product(v0, v2));
System.out.println ( "v1.v2: " + dot_product(v1, v2));
System.out.print ( "\nv0 x v1: " );
print ( cross_product ( v0, v1 ) );
}
static void print(float[] vertex){
System.out.print("[");
System.out.print(vertex[0]);
System.out.print(", ");
System.out.print(vertex[1]);
System.out.print(", ");
System.out.print(vertex[2]);
System.out.print("]\n");
}
static float length( float[] vertex ) {
return ( float )Math.sqrt( dot_product( vertex, vertex ) );
}
static float[] normalize( float[] vertex ) {
float l = length(vertex);
float[] rtn = { vertex[0] / l, vertex[1] / l, vertex[2] / l };
return rtn;
}
static float dot_product( float[] v0, float[] v1) {
return ( v0[0] * v1[0] + v0[1] * v1[1] + v0[2] * v1[2] );
}
static float cross_product( float[] vertex0, float[] vertex1 ) {
float[] rtn = new float[3];
rtn[0] = { vertex0[1] * vertex1[2] - vertex0[2] * vertex1[1] }; //illegal start of expression
rtn[1] = { vertex0[2] * vertex1[0] - vertex0[0] * vertex1[2] }; //illegal start of expression
rtn[2] = { vertex0[0] * vertex1[1] - vertex0[1] * vertex1[0] }; //illegal start of expression
return rtn;
}
}
import java.lang.Math;
public class VMath {
public static void main(String[] args) {
float[] v0 = { 0f, 5f, 10f };
float[] v1 = { 5f, 6f, 7f };
float[] v2 = { 2f, 3f, 0f };
System.out.println ("Len(v0): " + length(v0));
System.out.println ("Len(v1): " + length(v1));
System.out.println ("Len(v2): " + length(v2));
System.out.print ( "\nNormal(v0): " );
print ( normalize( v0 ) );
System.out.print ( "Normal(v1): " );
print ( normalize( v1 ) );
System.out.print ( "Normal(v2): " );
print ( normalize( v2 ) );
System.out.println ( "\nv0.v1: " + dot_product(v0, v1));
System.out.println ( "v0.v2: " + dot_product(v0, v2));
System.out.println ( "v1.v2: " + dot_product(v1, v2));
System.out.print ( "\nv0 x v1: " );
print ( cross_product ( v0, v1 ) );
}
static void print(float[] vertex){
System.out.print("[");
System.out.print(vertex[0]);
System.out.print(", ");
System.out.print(vertex[1]);
System.out.print(", ");
System.out.print(vertex[2]);
System.out.print("]\n");
}
static float length( float[] vertex ) {
return ( float )Math.sqrt( dot_product( vertex, vertex ) );
}
static float[] normalize( float[] vertex ) {
float l = length(vertex);
float[] rtn = { vertex[0] / l, vertex[1] / l, vertex[2] / l };
return rtn;
}
static float dot_product( float[] v0, float[] v1) {
return ( v0[0] * v1[0] + v0[1] * v1[1] + v0[2] * v1[2] );
}
static float cross_product( float[] vertex0, float[] vertex1 ) {
float[] rtn = new float[3];
rtn[0] = { vertex0[1] * vertex1[2] - vertex0[2] * vertex1[1] }; //illegal start of expression
rtn[1] = { vertex0[2] * vertex1[0] - vertex0[0] * vertex1[2] }; //illegal start of expression
rtn[2] = { vertex0[0] * vertex1[1] - vertex0[1] * vertex1[0] }; //illegal start of expression
return rtn;
}
}