public static double pt(double t, double df) { // ALGORITHM AS 3 APPL. STATIST. (1968) VOL.17, P.189 // Computes P(T<t) double a, b, idf, im2, ioe, s, c, ks, fk, k; double g1 = 0.3183098862; // =1/pi; if (df < 1) throw new IllegalArgumentException("Illegal argument df for pt(t,df)."); idf = df; a = t / Math.sqrt(idf); b = idf / (idf + t * t); im2 = df - 2; ioe = idf % 2; s = 1; c = 1; idf = 1; ks = 2 + ioe; fk = ks; if (im2 >= 2) { for (k = ks; k <= im2; k += 2) { c = c * b * (fk - 1) / fk; s += c; if (s != idf) { idf = s; fk += 2; } } } if (ioe != 1) return 0.5 + 0.5 * a * Math.sqrt(b) * s; if (df == 1) s = 0; return 0.5 + (a * b * s + Math.atan(a)) * g1; }
/* CALCULATE VALUES QUADRANTS: Calculate x-y values where direction is not parallel to eith x or y axis. */ public static void calcValuesQuad(int x1, int y1, int x2, int y2) { double arrowAng = Math.toDegrees(Math.atan((double) haw / (double) al)); double dist = Math.sqrt(al * al + aw); double lineAng = Math.toDegrees(Math.atan(((double) Math.abs(x1 - x2)) / ((double) Math.abs(y1 - y2)))); // Adjust line angle for quadrant if (x1 > x2) { // South East if (y1 > y2) lineAng = 180.0 - lineAng; } else { // South West if (y1 > y2) lineAng = 180.0 + lineAng; // North West else lineAng = 360.0 - lineAng; } // Calculate coords xValues[0] = x2; yValues[0] = y2; calcCoords(1, x2, y2, dist, lineAng - arrowAng); calcCoords(2, x2, y2, dist, lineAng + arrowAng); }
public static void drawLine(Graphics g, int x1, int y1, int x2, int y2, int lineWidth) { if (lineWidth == 1) g.drawLine(x1, y1, x2, y2); else { double angle; double halfWidth = ((double) lineWidth) / 2.0; double deltaX = (double) (x2 - x1); double deltaY = (double) (y2 - y1); if (x1 == x2) angle = Math.PI; else angle = Math.atan(deltaY / deltaX) + Math.PI / 2; int xOffset = (int) (halfWidth * Math.cos(angle)); int yOffset = (int) (halfWidth * Math.sin(angle)); int[] xCorners = {x1 - xOffset, x2 - xOffset + 1, x2 + xOffset + 1, x1 + xOffset}; int[] yCorners = {y1 - yOffset, y2 - yOffset, y2 + yOffset + 1, y1 + yOffset + 1}; g.fillPolygon(xCorners, yCorners, 4); } }
/** * Places the car. The car has to follow the ground. This is done by casting 4 rays (one from each * wheel) to the ground and calculating the resulting rotation angles to let the car follow the * ground as close as possible. * * @param ground the ground * @return if it was possible to place the car or not */ public boolean place(Object3D ground) { SimpleVector dropDown = new SimpleVector(0, 1, 0); /** * To cast the rays, the car will be rotated in horizontal position first, rotated around the * y-axis according to the cars direction and moved 10 units up. */ Matrix rotMat = getRotationMatrix(); rotMat.setIdentity(); setRotationMatrix(rotMat); rotateY(yRot); translate(0, -10, 0); /** Cast the rays... */ float rightFrontHeight = ground.calcMinDistance(rightFront.getTransformedCenter(), dropDown, 4 * 30); float rightRearHeight = ground.calcMinDistance(rightRear.getTransformedCenter(), dropDown, 4 * 30); float leftFrontHeight = ground.calcMinDistance(leftFront.getTransformedCenter(), dropDown, 4 * 30); float leftRearHeight = ground.calcMinDistance(leftRear.getTransformedCenter(), dropDown, 4 * 30); /** Correct the movement we did above. */ translate(0, 10, 0); /** Reset the rotation matrix again. */ rotMat = getRotationMatrix(); rotMat.setIdentity(); setRotationMatrix(rotMat); /** The rays all hit the ground, the car can be placed */ if (rightFrontHeight != Object3D.COLLISION_NONE && rightRearHeight != Object3D.COLLISION_NONE && leftFrontHeight != Object3D.COLLISION_NONE && leftRearHeight != Object3D.COLLISION_NONE) { /** Correct the values (see translation above) */ rightFrontHeight -= 10; rightRearHeight -= 10; leftFrontHeight -= 10; leftRearHeight -= 10; /** * Calculate the angles between the wheels and the ground. This is done four times: for the * front and the rear as well as for left and right. Front/rear and left/right are averaged * afterwards. */ double angleFront = rightFrontHeight - leftFrontHeight; double as = (angleFront / (16d)); angleFront = Math.atan(as); double angleRear = rightRearHeight - leftRearHeight; as = (angleRear / (16d)); angleRear = Math.atan(as); float rot = (float) ((angleFront + angleRear) / 2d); rotateZ(rot); double angleLeft = leftFrontHeight - leftRearHeight; as = (angleLeft / (16d)); angleLeft = Math.atan(as); double angleRight = rightFrontHeight - rightRearHeight; as = (angleRight / (16d)); angleRight = Math.atan(as); rot = (float) ((angleLeft + angleRight) / 2d); rotateX(rot); /** * The car is correctly rotated now. But we still have to adjust the height. We are simply * taking the minimum distance from all wheels to the ground as the new height. */ float down = rightFrontHeight; if (leftFrontHeight < down) { down = leftFrontHeight; } if (rightRearHeight < down) { down = rightRearHeight; } if (leftRearHeight < down) { down = leftRearHeight; } dropDown.scalarMul(down - 4); translate(dropDown); } else { return false; } /** And finally, rotate the car around Y (that's the car's direction) */ rotateY(yRot); return true; }
private int[] Translated_Point(double constant, int[] arrow_x, int[] arrow_y, double gradient) { double[] translated = new double[2]; double[][] trans_matrix = new double[2][2]; double ang_rot; double[] point2_temp = new double[4]; int cnt, row, col; int[] pt = new int[2]; translated[0] = 0.00; translated[1] = 0.00; trans_matrix[0][0] = 0.00; trans_matrix[0][1] = 0.00; trans_matrix[1][0] = 0.00; trans_matrix[1][1] = 0.00; point2_temp[0] = 0.00; point2_temp[1] = 0.00; point2_temp[2] = 0.00; point2_temp[3] = 0.00; cnt = 0; row = 0; col = 0; ang_rot = 0.00; // translate the line to the origin // thus the translated points to be found are: translated[0] = arrow_x[1]; if (constant < 0) { translated[1] = arrow_y[1] + Math.abs(constant); } else { translated[1] = arrow_y[1] - Math.abs(constant); } // find the angle of rotation ang_rot = Math.atan(gradient); if ((end_x - start_x) == 0) { if (arrow_x[0] > 0) { translated[0] = arrow_x[1] - arrow_x[0]; } else { translated[0] = arrow_x[1] + arrow_x[0]; } translated[1] = arrow_y[1]; trans_matrix[0][0] = -1; trans_matrix[0][1] = 0; trans_matrix[1][0] = 0; trans_matrix[1][1] = 1; } else { // declare the transformation matrix trans_matrix[0][0] = Math.cos(2 * ang_rot); trans_matrix[0][1] = Math.sin(2 * ang_rot); trans_matrix[1][0] = Math.sin(2 * ang_rot); trans_matrix[1][1] = Math.cos(2 * ang_rot) * (-1); } // multiply the transformation matrix with the point // store it in an array for (row = 0; row < 2; row++) { for (col = 0; col < 2; col++) { point2_temp[cnt] = trans_matrix[row][col] * translated[col]; cnt++; } } if ((end_x - start_x) == 0) { if (arrow_x[0] > 0) { arrow_x[2] = (int) Math.round(point2_temp[0] + point2_temp[1] + arrow_x[0]); } else { arrow_x[2] = (int) Math.round(point2_temp[2] + point2_temp[1] - arrow_x[0]); } arrow_y[2] = (int) Math.round(point2_temp[2] + point2_temp[3]); } else { // from the array, get the reflected point arrow_x[2] = (int) Math.round(point2_temp[0] + point2_temp[1]); if (constant < 0) { arrow_y[2] = (int) Math.round(point2_temp[2] + point2_temp[3] - Math.abs(constant)); } else { arrow_y[2] = (int) Math.round(point2_temp[2] + point2_temp[3] + Math.abs(constant)); } } pt[0] = arrow_x[2]; pt[1] = arrow_y[2]; return pt; }
private int decodeChunk(int prof) { int offset = 6; int id = getUShort(); int longueur = getInt(); if (longueur < 0) return 0; this.pushChunk(id); /* for(int x=0;x<prof;x++) System.out.print(" "); Log.log(prof + " - ID=" + Integer.toHexString(id) + " LONGUEUR=" + longueur ); */ switch (id) { case FILE_VERSION: { long ver = getUInt(); this.fileVersion = (int) ver; // System.out.println("FILE VERSION="+this.fileVersion); offset += 4; } break; case KEYFRAME_VERSION: { long ver = getUInt(); this.keyFrameVersion = (int) ver; offset += 4; // System.out.println("KEYFRAME VERSION="+this.keyFrameVersion); } break; case MESH_VERSION: { long ver = getUInt(); this.meshVersion = (int) ver; offset += 4; // System.out.println("MESH VERSION="+this.meshVersion); } break; /* case 0x0100: { double scl=(double) getFloat(); offset+=4; System.out.println("MASTER SCALE="+scl); } break; */ case UNIT: // MASTER_SCALE 1.0 <=> 1==1inch this.unit = getFloat(); offset += 4; while (offset < longueur) offset += decodeChunk(prof + 1); break; case BGCOLOR: do { int colorBId = getUShort(); int lBColor = getInt(); offset += 6; switch (colorBId) { case RGBF: case RGBFG: this.backgroundColor = readFloatColor(); offset += 12; break; case RGBB: case RGBBG: this.backgroundColor = readByteColor(); offset += 3; break; } } while (offset < longueur); break; case OBJECT: lastObjectName = getString(); offset += lastObjectName.length() + 1; while (offset < longueur) offset += decodeChunk(prof + 1); // TODO: 3DS LOADING MAY BE IT IS NOT NEEDED if (cObjet instanceof Mesh3D) { // ((Mesh3D)cObjet).buildVertexId(); // ((Mesh3D)cObjet).buildFaceId(); // ((Mesh3D)cObjet).removeDuplicateVertices(); // ((Mesh3D)cObjet).buildFacesNormals(); // ((Mesh3D)cObjet).buildSphereBoxAndCenter(); // Auto octree // ((Mesh3D)cObjet).buildMesh3DOctree(); } // if(cObjet!=null) // cObjet.build(); break; case OBJECT_HIDDEN: ((Mesh3D) cObjet).setVisible(false); break; case OBJECT_DONT_CAST_SHADOW: if (cObjet instanceof Mesh3D) ((Mesh3D) cObjet).setCastShadow(false); break; case OBJECT_DONT_RECV_SHADOW: if (cObjet instanceof Mesh3D) ((Mesh3D) cObjet).setRecvShadow(false); break; case CAMERA_ATMOS_RANGE: float nearAtmosRange = getFloat(); float farAtmosRange = getFloat(); offset += 8; break; case CAMERA: { cObjet = new Camera3D(); cObjet.id = -1; cObjet.nom = lastObjectName; cAxe = new Axis3D(); cObjet.axes = cAxe; tObjets3D[nbObjet] = cObjet; nbObjet++; float x = getFloat(); float y = getFloat(); float z = getFloat(); float tx = getFloat(); float ty = getFloat(); float tz = getFloat(); float rz = getFloat(); float focus = getFloat(); // System.out.println("focal lenght="+focus); double FOV = 180.0 * 2.0 * Math.atan(44.1828 / (focus * 2)) / Math.PI; // System.out.println("FOV CALC="+FOV); cObjet.position.set(x, z, y); // cObjet.axes.add(x,z,y); // Log.log(cObjet.position.toString()); cObjet.axes.origine.set(x, z, y); cObjet.axes.axeZ.set(tx - x, tz - z, ty - y); cObjet.axes.axeX.set(ty - y, 0, -(tx - x)); cObjet.axes.axeY.copy(cObjet.axes.axeZ).cross(cObjet.axes.axeX); cObjet.axes.axeX.normalize(); cObjet.axes.axeY.normalize(); cObjet.axes.axeZ.normalize(); cObjet.rotation.z = rz; cObjet.pivot.set(0, 0, 0); if (this.meshVersion == 0) focus = (float) ((Camera3D) cObjet).width; ((Camera3D) cObjet).focus = focus; // rotation.rz=rz; offset += 32; // tObjets3D[nbObjet]=new Scene3DObject(); // nbObjet++; while (offset < longueur) offset += decodeChunk(prof + 1); } break; case LIGHT: { float x = getFloat(); float y = getFloat(); float z = getFloat(); offset += 12; while (offset < longueur) offset += decodeChunk(prof + 1); } break; case TRIMESH: cObjet = new Mesh3D(); cObjet.nom = lastObjectName; cObjet.id = -1; tObjets3D[nbObjet] = cObjet; nbObjet++; cAxe = new Axis3D(); while (offset < longueur) offset += decodeChunk(prof + 1); cObjet.axes = cAxe; break; case VERTEXL: int nbV = getUShort(); offset += 2; cPoints3D = new Vertex3D[nbV]; mappingU = new float[nbV]; mappingV = new float[nbV]; for (int nV = 0; nV < nbV; nV++) { float x = getFloat(); float y = getFloat(); float z = getFloat(); cPoints3D[nV] = new Vertex3D(x, z, y); offset += 12; } while (offset < longueur) offset += decodeChunk(prof + 1); break; case FACEL: int nbP = getUShort(); offset += 2; cPolygones3D = new Face3D[nbP]; for (int nP = 0; nP < nbP; nP++) { int p1 = getUShort(); int p2 = getUShort(); int p3 = getUShort(); int info = getUShort(); Vertex3D p3D[] = new Vertex3D[3]; p3D[0] = cPoints3D[p3]; p3D[1] = cPoints3D[p2]; p3D[2] = cPoints3D[p1]; cPolygones3D[nP] = new Face3D(p3D[0], p3D[1], p3D[2]); cPolygones3D[nP].u0 = mappingU[p3]; cPolygones3D[nP].v0 = mappingV[p3]; cPolygones3D[nP].u1 = mappingU[p2]; cPolygones3D[nP].v1 = mappingV[p2]; cPolygones3D[nP].u2 = mappingU[p1]; cPolygones3D[nP].v2 = mappingV[p1]; offset += 8; } ((Mesh3D) cObjet).vertices3D = cPoints3D; ((Mesh3D) cObjet).faces3D = cPolygones3D; while (offset < longueur) offset += decodeChunk(prof + 1); break; case SMOOTHL: int nbpoly = cPolygones3D.length; for (int nP = 0; nP < nbpoly; nP++) { int nbSmooth = getInt(); cPolygones3D[nP].smoothGroupMask = nbSmooth; offset += 4; } break; case FACEM: String nom = getString(); offset += nom.length() + 1; cMateriau = getTempMateriauByName(nom); int nbF = getUShort(); offset += 2; for (int nF = 0; nF < nbF; nF++) { int numF = getUShort(); cPolygones3D[numF].material = cMateriau; offset += 2; } while (offset < longueur) offset += decodeChunk(prof + 1); break; case MAPPINGVL: int nbMV = getUShort(); offset += 2; for (int nV = 0; nV < nbMV; nV++) { float u = getFloat(); float v = getFloat(); mappingU[nV] = u; mappingV[nV] = -v; offset += 8; } while (offset < longueur) offset += decodeChunk(prof + 1); break; case OBJAXES: double x = getFloat(); double y = getFloat(); double z = getFloat(); cAxe.axeX.set(x, z, y); x = getFloat(); y = getFloat(); z = getFloat(); cAxe.axeZ.set(x, z, y); x = getFloat(); y = getFloat(); z = getFloat(); cAxe.axeY.set(x, z, y); x = getFloat(); y = getFloat(); z = getFloat(); cAxe.origine.set(x, z, y); offset += 48; while (offset < longueur) offset += decodeChunk(prof + 1); break; case MATERIAL: cMateriau = new Material(); tMateriaux3D[nbMaterial] = cMateriau; nbMaterial++; while (offset < longueur) offset += decodeChunk(prof + 1); break; case MATERIALNAME: cMateriau.nom = getString(); offset += cMateriau.nom.length() + 1; while (offset < longueur) offset += decodeChunk(prof + 1); break; case MATERIALAMBIENTCOLOR: do { int colorAId = getUShort(); int lAColor = getInt(); offset += 6; switch (colorAId) { case RGBF: case RGBFG: cMateriau.ambientColor = readFloatColor(); offset += 12; break; case RGBB: case RGBBG: cMateriau.ambientColor = readByteColor(); offset += 3; break; } } while (offset < longueur); break; case MATERIALDIFFUSECOLOR: do { int colorDId = getUShort(); int lDColor = getInt(); offset += 6; switch (colorDId) { case RGBF: case RGBFG: cMateriau.diffuseColor = readFloatColor(); offset += 12; break; case RGBB: case RGBBG: cMateriau.diffuseColor = readByteColor(); offset += 3; break; } } while (offset < longueur); break; case MATERIALSPECULARCOLOR: do { int colorSId = getUShort(); int lSColor = getInt(); offset += 6; switch (colorSId) { case RGBF: case RGBFG: cMateriau.specularColor = readFloatColor(); offset += 12; break; case RGBB: case RGBBG: cMateriau.specularColor = readByteColor(); offset += 3; break; } } while (offset < longueur); break; case MATERIALSHINEPERCENT: int shineId = getUShort(); int lShine = getInt(); offset += 6; switch (shineId) { case PERCENTF: cMateriau.specularPower = readFloatPercent(); offset += 4; break; case PERCENTI: cMateriau.specularPower = readIntPercent(); offset += 2; break; } break; case MATERIALILLUMPERCENT: int illumId = getUShort(); int lIllum = getInt(); offset += 6; switch (illumId) { case PERCENTF: cMateriau.selfIlluminationLevel = readFloatPercent(); offset += 4; break; case PERCENTI: cMateriau.selfIlluminationLevel = readIntPercent(); offset += 2; break; } // Log.log(cMateriau.nom+" emi="+emi); break; case MATERIALSHINEFPERCENT: int shineFId = getUShort(); int lShineF = getInt(); offset += 6; switch (shineFId) { case PERCENTF: cMateriau.specularLevel = readFloatPercent() * 255 / 100; offset += 4; break; case PERCENTI: cMateriau.specularLevel = (readIntPercent() * 255) / 100; offset += 2; break; } break; case MATERIALTRANSPERCENT: int transId = getUShort(); int lTrans = getInt(); offset += 6; switch (transId) { case PERCENTF: cMateriau.alphaLevel = readFloatPercent() * 255 / 100; offset += 4; break; case PERCENTI: cMateriau.alphaLevel = (readIntPercent() * 255) / 100; offset += 2; break; } break; case MATERIALTRANSFPERCENT: int transFId = getUShort(); int lTransF = getInt(); offset += 6; switch (transFId) { case PERCENTF: cMateriau.alphaFalloff = readFloatPercent() * 255 / 100; offset += 4; break; case PERCENTI: cMateriau.alphaFalloff = (readIntPercent() * 255) / 100; offset += 2; break; } break; case MATERIALTEXTUREDIFF: cMapping = new MappingUV(); cMateriau.mapping = cMapping; while (offset < longueur) offset += decodeChunk(prof + 1); break; case MATERIALTEXTUREBUMP: cMapping = new MappingUV(); while (offset < longueur) offset += decodeChunk(prof + 1); break; case MATERIALTEXTUREENV: cMapping = new MappingUV(); while (offset < longueur) offset += decodeChunk(prof + 1); break; case MATERIALTEXTUREOPAC: cMapping = new MappingUV(); while (offset < longueur) offset += decodeChunk(prof + 1); break; case MATERIALTEXTURESPEC: cMapping = new MappingUV(); while (offset < longueur) offset += decodeChunk(prof + 1); break; case MATERIALTEXTURESHIN: cMapping = new MappingUV(); while (offset < longueur) offset += decodeChunk(prof + 1); break; case MATERIALTEXTUREILLUM: cMapping = new MappingUV(); while (offset < longueur) offset += decodeChunk(prof + 1); break; case MAPPINGFILE: String fileName = getString(); // System.out.println("MAPPINGFILE="+fileName); offset += fileName.length() + 1; String textureCacheKey = this.ressourcePath + fileName; URLTexture nTexture = (URLTexture) textureCache.get(textureCacheKey); if (nTexture == null) { nTexture = new URLTexture(); nTexture.nom = fileName; nTexture.sourceFile = fileName; nTexture.baseURL = this.ressourcePath; textureCache.put(textureCacheKey, nTexture); this.textures[this.nbTexture++] = nTexture; } // There cache will cause trouble if same texture used for different kind of map if (this.getLastParentChunk() == MATERIALTEXTUREDIFF) { nTexture.type = DzzD.TT_RGB; cMateriau.diffuseTexture = nTexture; } if (this.getLastParentChunk() == MATERIALTEXTUREBUMP) { nTexture.type = DzzD.TT_HNORMAL; cMateriau.bumpNormalTexture = nTexture; } if (this.getLastParentChunk() == MATERIALTEXTUREENV) { nTexture.type = DzzD.TT_ENV; cMateriau.envTexture = nTexture; } while (offset < longueur) offset += decodeChunk(prof + 1); break; case MAPPINGOFFSETU: float offseMappingU = getFloat(); offset += 4; cMapping.ofsU = offseMappingU; break; case MAPPINGOFFSETV: float offseMappingV = getFloat(); offset += 4; cMapping.ofsV = offseMappingV; break; /* * KEYFRAME BEGIN */ case KEYFHIER: // System.out.println("KEYFHIER"); lastObjectName = getString(); // Name in mesh section // System.out.println("Mesh section name="+lastObjectName); offset += lastObjectName.length() + 1; int info1 = getUShort(); int info2 = getUShort(); int idObjetParent = getShort(); // System.out.println("------- info1: "+info1); // System.out.println("------- info2: "+info2); // System.out.println("------- idObjetParent parent:("+idObjetParent+")"); offset += 6; if ((this.meshVersion >= 3) && ((info1 & 0x4000) == 0) && (!lastObjectName.equals("$$$DUMMY"))) { // Log.log("------------ Instance From Object" + lastObjectName); cObjet = (Scene3DObject) getTempObjetByName(lastObjectName).getClone(false); cObjet.nom = "Instance" + nbObjet; // lastObjectName; cObjet.id = this.cObjetId; tObjets3D[nbObjet] = cObjet; nbObjet++; } else { if (lastObjectName.equals("$$$DUMMY")) { // System.out.println("New object"); cObjet = new Mesh3D(); cObjet.nom = "$$$DUMMY"; cObjet.id = this.cObjetId; tObjets3D[nbObjet] = cObjet; nbObjet++; } else { this.cObjet = getTempObjetByName(lastObjectName); if (this.cObjet instanceof Camera3D) { if (getLastParentChunk() == KEYFCAMTARGETFRAME) { // System.out.println("TARGET FOR "+lastObjectName); // this.cObjet.setTarget(DzzD.newPoint3D()); } } } } // System.out.println("ID objet==" + cObjetId); this.cObjet.id = this.cObjetId; if (idObjetParent != 65535) { Scene3DObject parent = getTempObjetById(idObjetParent); if (parent != null) this.cObjet.parent = parent; // System.out.println(cObjet.getName()+" is child of "+cObjet.getParent().getName()); } /* if(this.cObjet.parent!=null && !lastObjectName.equals("$$$DUMMY")) System.out.println("-" + lastObjectName+"("+ this.cObjet.id +"):parent:("+idObjetParent+")"+this.cObjet.parent.nom); */ while (offset < longueur) offset += decodeChunk(prof + 1); break; case KEYFNAME: // - Instance objects name. String instanceName = getString(); // Log.log("instanceName="+instanceName); cObjet.nom = instanceName; offset += instanceName.length() + 1; break; case KEYFID: int idObjet = getUShort(); offset += 2; this.cObjetId = idObjet; // System.out.println("ID OBJ="+cObjetId); while (offset < longueur) offset += decodeChunk(prof + 1); break; case KEYFTRANS: // Read Track Header int info = getShort(); offset += 2; for (int niu = 0; niu < 8; niu++) { // Read Unknow TrackHeader info 8 byte byte infoUnknow = (byte) getByte(); offset += 1; } // Read number ok keys int nbKey = (int) getUInt(); offset += 4; Point3D cPosition = new Point3D(); Point3D lastPosition = new Point3D(); if (this.animators[cObjetId] == null) this.animators[cObjetId] = new Scene3DObjectAnimator(); // Read all track for (int xKey = 0; xKey < nbKey; xKey++) { // Read the frame number for this key int nKey = (int) getUInt(); offset += 4; // Read Spline flag int splinef = getShort(); offset += 2; // Read Spline info depending on spline flag if ((splinef & 1) != 0) { // Read tension getFloat(); offset += 4; } if ((splinef & 2) != 0) { // Read continuity getFloat(); offset += 4; } if ((splinef & 4) != 0) { // Read bias getFloat(); offset += 4; } if ((splinef & 8) != 0) { // Read ease to getFloat(); offset += 4; } if ((splinef & 16) != 0) { // Read ease from getFloat(); offset += 4; } // Read this key pos (global coordinate x = getFloat(); y = getFloat(); z = getFloat(); if (xKey == 0) this.key3DTrans[cObjetId] = new Point3D(x, z, y); cPosition.set(x, z, y); Point3D position = new Point3D(); position.copy(cPosition); /* if(cObjetId!=-1) { System.out.println(tObjets3D[cObjetId].getName()); System.out.println("pos="+position.toString()); } */ this.animators[cObjetId].addKeyPosition(nKey * 30, position); lastPosition.copy(cPosition); offset += 12; } break; case KEYFROT: int infor = getShort(); offset += 2; for (int niu = 0; niu < 8; niu++) { byte infoUnknow = (byte) getByte(); offset += 1; } int nbKeyr = (int) getUInt(); offset += 4; Axis3D cAxis = new Axis3D(); cAxis.init(); Point3D cRotation = new Point3D(); Point3D lastRotation = new Point3D(); if (this.animators[cObjetId] == null) this.animators[cObjetId] = new Scene3DObjectAnimator(); for (int xKey = 0; xKey < nbKeyr; xKey++) { int nKey = (int) getUInt(); offset += 4; int infoAcceleration = getShort(); offset += 2; double a = getFloat(); offset += 4; x = getFloat(); y = getFloat(); z = getFloat(); if (a > Math.PI && xKey != 0) a = 2.0 * Math.PI - a; if (xKey == 0) { this.key3DRotAng[cObjetId] = a; this.key3DRotAxe[cObjetId] = new Point3D(x, z, y); } cAxis.rotate(a, -x, -z, -y); cAxis.getRotationXZY(cRotation); Point3D rotation = new Point3D(); rotation.copy(cRotation); this.animators[cObjetId].addKeyRotation(nKey * 30, rotation, new Point3D(-x, -z, -y), a); offset += 12; } break; case KEYFZOOM: int infoz = getShort(); offset += 2; for (int niu = 0; niu < 8; niu++) { byte infoUnknow = (byte) getByte(); offset += 1; } int nbKeyz = (int) getUInt(); offset += 4; for (int xKey = 0; xKey < nbKeyz; xKey++) { int nKey = (int) getUInt(); offset += 4; int infoAcceleration = getShort(); offset += 2; x = getFloat(); y = getFloat(); z = getFloat(); if (xKey == 0) this.key3DZoom[cObjetId] = new Point3D(x, z, y); offset += 12; } break; case KEYFCAMFOVFRAME: int infof = getShort(); offset += 2; for (int niu = 0; niu < 8; niu++) { byte infoUnknow = (byte) getByte(); offset += 1; } int nbKeyf = (int) getUInt(); offset += 4; for (int xKey = 0; xKey < nbKeyf; xKey++) { int nKey = (int) getUInt(); offset += 4; int infoAcceleration = getShort(); offset += 2; float fov = getFloat(); if (this.cObjet instanceof Camera3D) { ((Camera3D) this.cObjet).setFOV(fov); } offset += 4; } break; case KEYFPIVOT: x = getFloat(); y = getFloat(); z = getFloat(); offset += 12; this.cObjet.pivot.set(x, z, y); break; case KEYFBOX: double x1 = getFloat(); double y1 = getFloat(); double z1 = getFloat(); offset += 12; double x2 = getFloat(); double y2 = getFloat(); double z2 = getFloat(); offset += 12; this.cObjet.center.set((x1 + x2) * 0.5, (z1 + z2) * 0.5, (y1 + y2) * 0.5); break; case KEYF3DS: this.isKeyFrame = true; // System.out.println("KEYF3DS"); this.cObjetId = 0; while (offset < longueur) offset += decodeChunk(prof + 1); break; case KEYFHEADERACTIVE: long startf = getUInt(); long endf = getUInt(); // System.out.println("KEYFRAME START FRAME="+ startf); // System.out.println("KEYFRAME END FRAME="+ endf); offset += 8; while (offset < longueur) offset += decodeChunk(prof + 1); break; case KEYFHEADERCURRENT: long currentf = getUInt(); // System.out.println("KEYFRAME CURRENT FRAME="+currentf); offset += 4; while (offset < longueur) offset += decodeChunk(prof + 1); break; case KEYFHEADERGLOBAL: this.keyFrameRevision = getShort(); this.keyFrameFileName = getString(); this.KeyFrameNbFrame = getUInt(); offset += 2; offset += this.keyFrameFileName.length() + 1; offset += 4; while (offset < longueur) offset += decodeChunk(prof + 1); break; case MAIN3DS: this.cObjetId = 0; while (offset < longueur) offset += decodeChunk(prof + 1); break; case EDIT3DS: while (offset < longueur) offset += decodeChunk(prof + 1); break; case KEYFOBJFRAME: this.cObjetId++; while (offset < longueur) offset += decodeChunk(prof + 1); break; case KEYFCAMFRAME: this.cObjetId++; // System.out.println("-----CAMERA-------"); // System.out.println("ID1="+cObjetId); while (offset < longueur) offset += decodeChunk(prof + 1); // System.out.println("-----END CAMERA-------"); break; case KEYFCAMTARGETFRAME: this.cObjetId++; // System.out.println("-----CAMERA TARGET-------"); // System.out.println("ID1="+cObjetId); // MUST DO SPECIAL DECODE OF CHILD TO NOT OVERWRITE CAMERA TRACK POS/ROT // while(offset<longueur) // offset+=decodeChunk(prof+1); // System.out.println("-----END CAMERA TARGET-------"); break; default: break; } this.setProgress(50 + (50 * this.nbBytesDecoded) / this.data.length); skip(id, offset, longueur - offset); this.popChunk(); return longueur; }
public static void main(String[] args) { double deg = 30; double rad = Math.toRadians(deg); double ans = Math.atan(rad); System.out.println(ans); }
/** * Calculate Cumulative Cauchy distribution function. * * @return the probability that a stochastic variable x is less than X * @author Klaus Meffert * @since 1.1 */ public double nextCauchy() { return 0.5 + Math.atan((m_rn.nextDouble() - m_location) / m_scale) / Math.PI; }