Thanks, it worked!
I tried rotating around x-axis, but I did not know that I had to clear the Rotation.
I tried rotating around x-axis, but I did not know that I had to clear the Rotation.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menupublic static void addGerade(Gerade g){
Object3D gt = Primitives.getCylinder(6, 0.1f, 150);
// Changing the ccordinates from the calculated line to the ones needed to draw it
double ax = g.getA().getX1();
double ay = -g.getA().getX3();
double az = g.getA().getX2();
double rx = g.getV().getX();
double ry = -g.getV().getZ();
double rz = g.getV().getY();
SimpleVector Aufpunkt = new SimpleVector (ax, ay, az);
SimpleVector Richtung = new SimpleVector(rx, ry, rz);
Matrix r = Richtung.getRotationMatrix();
gt.setRotationMatrix(r);
gt.translate(Aufpunkt);
gt.setTexture("linet");
gt.build();
world.addObject(gt);
buffer.clear(java.awt.Color.DARK_GRAY);
world.renderScene(buffer);
// world.drawWireframe(buffer, Color.WHITE);
world.draw(buffer);
buffer.update();
}
public static void rotateupdown(float v){
SimpleVector cam = world.getCamera().getPosition();
SimpleVector y = new SimpleVector(0,1,0);
SimpleVector rot = cam.calcCross(y);
rot = rot.normalize();
float n1 = rot.x;
float n2 = rot.y;
float n3 = rot.z;
float r = v*(float)Math.PI/30;
float c =(float) Math.cos(r);
float s =(float) Math.sin(r);
Matrix m = new Matrix();
m.set(0, 0, n1*n1*(1-c) + c);
m.set(0,1, n1*n2*(1-c) - n3*s);
m.set(0,2, n1*n3*(1-c) + n2*s);
m.set(1,0, n1*n2*(1-c) + n3*s);
m.set(1,1, n2*n2*(1-c) + c);
m.set(1,2, n2*n3*(1-c)- n1*s);
m.set(2,0, n1*n3*(1-c)- n2*s);
m.set(2,1, n2*n3*(1-c) + n1*s);
m.set(2,2, n3*n3*(1-c) + c);
cam.rotate(m);
world.getCamera().setPosition(cam);
world.getCamera().lookAt(new SimpleVector(0,0,0));
buffer.clear(java.awt.Color.DARK_GRAY);
world.renderScene(buffer);
world.drawWireframe(buffer, Color.WHITE);
buffer.update();
}
package jPCT;
import java.awt.EventQueue;
public class HelloGui extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
HelloGui frame = new HelloGui();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public HelloGui() throws Exception {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 800, 600);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton btnTest = new JButton("Test 1");
btnTest.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
RenderPanel.rotateleft();
repaint();
}
});
btnTest.setBounds(10, 11, 89, 23);
contentPane.add(btnTest);
JButton btnTest_1 = new JButton("Test 2");
btnTest_1.setBounds(10, 45, 89, 23);
contentPane.add(btnTest_1);
JButton btnTest_2 = new JButton("Test 3");
btnTest_2.setBounds(10, 79, 89, 23);
contentPane.add(btnTest_2);
JPanel panel = new JPanel();
panel.setBounds(109, 11, 665, 540);
contentPane.add(panel);
panel.setLayout(new BorderLayout(0, 0));
RenderPanel panel_1 = new RenderPanel();
panel.add(panel_1, BorderLayout.CENTER);
}
}
package jPCT;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JPanel;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Matrix;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.World;
public class RenderPanel extends JPanel {
private static final long serialVersionUID = 1L;
static World world;
static FrameBuffer buffer;
Object3D box;
{
world = new World();
// world.setAmbientLight(200, 255, 200);
// TextureManager.getInstance().addTexture("box", new Texture("box.jpg"));
box = Primitives.getBox(3f, 2f);
// box.setTexture("box");
// box.setEnvmapped(Object3D.ENVMAP_ENABLED);
box.build();
world.addObject(box);
world.getCamera().setPosition(50, -20, -5);
world.getCamera().lookAt(box.getTransformedCenter());
buffer = new FrameBuffer(660, 530, FrameBuffer.SAMPLINGMODE_NORMAL);}
public RenderPanel() {
setPreferredSize(new Dimension(buffer.getOutputWidth(), buffer.getOutputHeight()));
setFocusable(true);
setLayout(null);
buffer.clear(java.awt.Color.DARK_GRAY);
world.renderScene(buffer);
world.drawWireframe(buffer, Color.WHITE);
buffer.update();
}
public static void rotateleft(){
SimpleVector temp = world.getCamera().getPosition();
float rotation = (float) Math.PI/30;
temp.rotateY(-rotation);
world.getCamera().setPosition(temp);
world.getCamera().lookAt(new SimpleVector(0,0,0));
buffer.clear(java.awt.Color.DARK_GRAY);
world.renderScene(buffer);
world.drawWireframe(buffer, Color.WHITE);
buffer.update();
}
@Override
public void paintComponent(Graphics g) {
buffer.display(g);
}
}
package jPCT;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JPanel;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.World;
public class RenderPanel extends JPanel {
private static final long serialVersionUID = 1L;
private World world;
private FrameBuffer buffer;
private Object3D box;
public RenderPanel() {
world = new World();
// world.setAmbientLight(200, 255, 200);
// TextureManager.getInstance().addTexture("box", new Texture("box.jpg"));
box = Primitives.getBox(3f, 2f);
// box.setTexture("box");
// box.setEnvmapped(Object3D.ENVMAP_ENABLED);
box.build();
world.addObject(box);
world.getCamera().setPosition(50, -50, -5);
world.getCamera().lookAt(box.getTransformedCenter());
buffer = new FrameBuffer(660, 530, FrameBuffer.SAMPLINGMODE_NORMAL);
setPreferredSize(new Dimension(buffer.getOutputWidth(), buffer.getOutputHeight()));
setFocusable(true);
setLayout(null);
buffer.clear(java.awt.Color.DARK_GRAY);
world.renderScene(buffer);
world.drawWireframe(buffer, Color.WHITE);
buffer.update();
}
@Override
public void paintComponent(Graphics g) {
buffer.display(g);
}
}
Page created in 0.020 seconds with 11 queries.