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 › for everyone here easy, for me impossible.. help
Page Index Toggle Pages: 1
for everyone? here easy, for me impossible.. help? (Read 1029 times)
for everyone? here easy, for me impossible.. help?
May 25th, 2010, 7:11am
 
Now I'd been trying for months to realize my idea and also have posted so many threads and got a lot of help of you. but even though it wasn't possible to work it out..

It's still the same: a window that has got two frames (I think napplet makes sense).. the height of the upper frame should be fixed, the width should be the actual width..(frame.setResizable(true))

in the under frame there should be a 3-dimensional coordinate system.. Is this also possible with P3D or do I have to take OpenGL? There translation and rotation and zooming should be possible.. Can I make this like this or do I have to work with a matrix? (I would like to work with reflections and so on, too.. there I work with a matrix to calculate the things, but it isn't necessary to draw with a matrix, too. or not?)


AND THE MAIN PROBLEM:


When I have a 3d area.. How can I get the x,y and z coordinates. It's impossible to get the z or not? and do I have to project the whole thing to get the x,y-coordinates? or is there another possibilty?
Re: for everyone? here easy, for me impossible.. help?
Reply #1 - May 25th, 2010, 7:16am
 
that's the way you helped me to make a drawing area, but it should be transformed to a napplet.. but I just can't make it work..

Code:
PGraphics drawingArea;
int DA_X = 0, DA_Y = 200;
int lastWidth, lastHeight;
int DA_WIDTH, DA_HEIGHT;

void setup(){
size(500, 500);
frame.setResizable(true);
registerPre(this);
smooth();
background(0);
lastWidth = width;
lastHeight = height;
ReCreateDrawingArea(lastWidth, lastHeight); // Create a new graphical context
}

void draw(){
// Update display
image(drawingArea, DA_X, DA_Y);
}


void mousePressed(){
if (mouseX < DA_X || mouseX >= DA_X + DA_WIDTH || mouseY < DA_Y|| mouseY >= DA_Y + DA_HEIGHT)
return;
drawingArea.beginDraw();
for (int i = 0; i < 10; i++) {
drawingArea.ellipse(random(DA_WIDTH), random(DA_HEIGHT),
5 + random(20), 5 + random(20)); } drawingArea.endDraw();}


void pre(){ if(width != lastWidth || height != lastHeight){
lastWidth = width; lastHeight = height;
ReCreateDrawingArea(lastWidth, lastHeight); }}

void ReCreateDrawingArea(int daWidth, int daHeight){
DA_WIDTH = daWidth;
DA_HEIGHT = daHeight - DA_Y;

drawingArea = createGraphics(DA_WIDTH, DA_HEIGHT, P3D);
drawingArea.beginDraw(); drawingArea.background(#FFFFFF);
drawingArea.endDraw();}



and this is the code I worked out for translating/rotating/...
Code:
void mouseDragged() {  float factor = 0.01;  
if (key==CODED){ // Alt + Maus --> Rotation
if(keyCode==ALT){
rotx += (pmouseY-mouseY) * factor;
roty += (mouseX-pmouseX) * factor; }

if(keyCode==CONTROL){ // Ctrl + Maus --> Translation
transx+=(mouseX-pmouseX); transy+=(mouseY-pmouseY); } }}





void keyPressed(){
if(key!=CODED){
if (key=='1'){
rotx=0;
roty=0;
transx=width/2;
transy=height/2;
transz=-300;
}

if (key=='3'){
rotx=0;
roty=radians(-90);
transx=width/2;
transy=height/2;
transz=-300;
}

if (key=='7'){
rotx=radians(-90);
roty=0;
transx=width/2;
transy=height/2;
transz=-300;
}
}

if (key == CODED) {
if(keyCode==CONTROL){
if(key=='1'){
rotx=0;
roty=PI;
}

if(key=='3'){
rotx=0;
roty=radians(90);
}

if(key=='7'){
rotx=radians(90);
roty=0;
}
}
}
}


is it possible like this? I think it should work but I have no idea whether it's sensible to work with this.. I've seen a controlp5-file that works with a peasy camera.. is this more sensible? do you have some advise for me?
Re: for everyone? here easy, for me impossible.. help?
Reply #2 - May 25th, 2010, 7:31am
 
if someone is interested in what I did and could help me to make it work better.. it would be nice..

Code:
import napplet.*;
NAppletManager nappletManager;

void setup() {
size(600, 600);
nappletManager = new NAppletManager(this);
nappletManager.createNApplet("Menu", 0,0);
nappletManager.createNApplet("Zeichnen", 0,100);

}


void draw()
{ background(0);
}







public class Menu extends NApplet {

public void setup() { size(600, 100);
}
public void draw() {
background(0, 100, 0);
stroke(255); fill(255);
}


}

public class Zeichnen extends NApplet {
float rotx=.1, roty=.1;
int achl=600;
int a=100, offx=0, offy=0,offz=0;
int transx, transy, transz=-300;
int lastWidth, lastHeight;
int pfeil=6;
public void setup() { size(600, 500,P3D);
stroke(0);
strokeWeight(1);
strokeJoin(MITER);
transx=width/2;
transy=height/2;
}


public void draw() {
background(255);
pushMatrix();
translate(transx,transy,transz);
rotateX(rotx);
rotateY(roty);
koordinatensystem();
popMatrix();
}


public void koordinatensystem(){
strokeWeight(1.5);
beginShape(LINES);
stroke(255,0,0); //z-achse rot
vertex(0,0,-achl);
vertex(0,0,achl);

vertex(0,0,-achl); // Pfeil 1
vertex(pfeil,0,-achl+pfeil);
vertex(0,0,-achl);
vertex(-pfeil,0,-achl+pfeil);

vertex(0,0,achl); //Pfeil 2
vertex(pfeil,0,achl-pfeil);
vertex(0,0,achl);
vertex(-pfeil,0,achl-pfeil);

stroke(0,255,0); //y-achse grün
vertex(0,-achl,0);
vertex(0,achl,0);
vertex(0,achl,0); // Pfeil 1
vertex(0,achl-pfeil,pfeil);
vertex(0,achl,0);
vertex(0,achl-pfeil,-pfeil);

vertex(0,-achl,0); // Pfeil 2
vertex(pfeil,-achl+pfeil,0);
vertex(0,-achl,0);
vertex(-pfeil,-achl+pfeil,0);



stroke(0,0,255); //x-achse blau
vertex(-achl,0,0);
vertex(achl,0,0);

vertex(-achl,0,0); // Pfeil 1
vertex(-achl+pfeil,0,pfeil);
vertex(-achl,0,0);
vertex(-achl+pfeil,0,-pfeil);

vertex(achl,0,0); // Pfeil 2
vertex(achl-pfeil,0,pfeil);
vertex(achl,0,0);
vertex(achl-pfeil,0,-pfeil);
endShape();}

public void mouseDragged() { float factor = 0.01;
if (key==CODED){ // Alt + Maus --> Rotation
if(keyCode==ALT){
rotx += (pmouseY-mouseY) * factor;
roty += (mouseX-pmouseX) * factor; }

if(keyCode==CONTROL){ // Ctrl + Maus --> Translation
transx+=(mouseX-pmouseX); transy+=(mouseY-pmouseY); } }}

public void keyPressed(){
if(key!=CODED){
if (key=='1'){
rotx=0;
roty=0;
transx=width/2;
transy=height/2;
transz=-300;
}

if (key=='3'){
rotx=0;
roty=radians(-90);
transx=width/2;
transy=height/2;
transz=-300;
}

if (key=='7'){
rotx=radians(-90);
roty=0;
transx=width/2;
transy=height/2;
transz=-300;
}
}

if (key == CODED) {
if(keyCode==CONTROL){
if(key=='1'){
rotx=0;
roty=PI;
}

if(key=='3'){
rotx=0;
roty=radians(90);
}

if(key=='7'){
rotx=radians(90);
roty=0;
}
}
}
}



}

Re: for everyone? here easy, for me impossible.. help?
Reply #3 - May 25th, 2010, 7:52am
 
is it now possible to add a toggle (controlp5) in the menu-frame to activate/deactivate the "koordinatensystem" in the zeichnen-frame?

if yes.. how? I tried to work with it but theres the mistake:

Quote:
java.lang.NullPointerException
     at processing.app.debug.Compiler.contentsToClassPath(Unknown Source)
     at processing.app.Sketch.preprocess(Unknown Source)
     at processing.app.Sketch.preprocess(Unknown Source)
     at processing.app.Sketch.build(Unknown Source)
     at processing.app.Sketch.build(Unknown Source)
     at processing.app.Editor$DefaultRunHandler.run(Unknown Source)
     at java.lang.Thread.run(Thread.java:619)
Page Index Toggle Pages: 1