wolle
YaBB Newbies
Offline
Posts: 14
Rotate each Letter around its axis
May 17th , 2008, 10:27pm
Hello. I have a sketch here, that gets the coordinates of the vertices of an imported 3d object (Wavefront , obj., exported with cinema 4d) and places a random letter. Now i want to rotate each Letter around its y-axis. Can anyone help me with that? BTW: Is there a better way to place letters in space than that? thx import saito.objloader.*; import processing.opengl.*; OBJModel model; float rotX = 0; float rotY = 0; float transY; float transX; Vertex myVert; PFont fontA; float x; float y; float z; float[] xCoords; float[] yCoords; float[] zCoords; int letter; char[] alphabet = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T' ,'U','V','W','X','Y','Z','&','$','!','@','1','2', '3','4','5','6','7','8','9','0'}; char[] alphabet2 = new char[40]; void setup () { size(900, 900, OPENGL); frameRate(30); model = new OBJModel(this); model.load("test.obj"); // test.obj in data folder fontA = loadFont("UniversLTStd.vlw"); textFont(fontA, 6); background(51); noStroke(); lights(); calculateLetter(); for(int k = 0; k<40; k++) { alphabet2[k] = alphabet[int(random(39))]; } } void draw() { background(51); noStroke(); lights(); /*pushMatrix(); translate(width/2, height/2, 0); scale(0.5); model.drawMode(POLYGON); model.draw(); popMatrix(); */ pushMatrix(); translate(transX, height/2, transY); scale(2); rotateX(-rotY); rotateY(-rotX); drawLetter(); popMatrix(); } void mouseDragged() { if(key == 'c'){ transX -= (mouseY - pmouseY) * 0.5; transY += (mouseX -pmouseX) * 0.5; } else{ rotX += (mouseX - pmouseX) * 0.01; rotY -= (mouseY - pmouseY) * 0.01; } } void calculateLetter() { xCoords = new float[model.getVertexsize()]; yCoords = new float[model.getVertexsize()]; zCoords = new float[model.getVertexsize()]; for(int i = 0; i<model.getVertexsize(); i++) { xCoords[i] = model.getVertex(i).vx; yCoords[i] = model.getVertex(i).vy; zCoords[i] = model.getVertex(i).vz; } } void drawLetter() { letter = 0; for(int j = 0; j<model.getVertexsize(); j++){ letter++; if (letter >=39){letter = 0;} text(alphabet[letter], xCoords[j], yCoords[j], zCoords[j]); } }