We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Rotate each Letter around its axis
Page Index Toggle Pages: 1
Rotate each Letter around its axis (Read 645 times)
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]);



  }
}
Re: Rotate each Letter around its axis
Reply #1 - May 19th, 2008, 3:20pm
 
Yeah! I got it on my own now.
Solution: void drawLetter()
{

  letter = 0;
  for(int j = 0; j<model.getVertexsize(); j++){
  letter++;
    pushMatrix();
    translate(xCoords[j], yCoords[j], zCoords[j]);
   
   
    if (letter >=39){letter = 0;}
    rotateY(radians(90));
    text(alphabet[letter], xCoords[j], yCoords[j], zCoords[j]);
    rotateY(radians(-90));
   
    translate(-xCoords[j], -yCoords[j], -zCoords[j]);
    popMatrix();
  }
Page Index Toggle Pages: 1