### Show Posts

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.

### Messages - Knuffi

Pages: [1] 2
1
##### Support / Re: Rotating a cylinder in a direction given by a simple vector
« on: April 17, 2012, 07:14:09 am »
Thanks, it worked!

I tried rotating around x-axis, but I did not know that I had to clear the Rotation.

2
##### Support / Rotating a cylinder in a direction given by a simple vector
« on: April 16, 2012, 10:40:51 pm »
I don't get it.

I have a cylinder representing a line. And on building it, I want to translate it to a certain point (working) and rotate it, that it looks into the same direction as a given vector. The last thing does not work.
When I give the vector
* (1/0/0), the cylinder's direction is the z-axis (or -z, I could not see),
* (0/1/0) the cylinder's direction is also the z-axis (or -z)
* (0/0/1) the cylinde's direction is the x-axis.

I changed the coordinate system to an "upright" as needed in school.

Code: [Select]
`public 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(); }`

Almost the same code works fine with points (as already said, translating works) and even planes (translating and rotating so that the normal vector looks into a given direction.

Can anybody help?

3
##### Support / Re: Rotating the Camera up an down around the Origin
« on: April 08, 2012, 09:16:30 pm »
Ok, that is much shorter, and the axis could be set as in my source by a cross product.

4
##### Support / Re: Planes only visible from the upper side?
« on: April 08, 2012, 08:36:21 pm »
Thanks a lot!

5
##### Support / Planes only visible from the upper side?
« on: April 08, 2012, 07:27:00 pm »
Are planes in wireframe view only visible from the upper side? When I move my camera blow a plane, it disappears.

6
##### Support / Re: Rotating the Camera up an down around the Origin
« on: April 08, 2012, 07:25:41 pm »
Ok, got it. I'm sure, there is a easier way
I used a rotation matrix that rotates the camera position around a normalized cross-vector of the camera position and the y-axis. That stops working when I'm directly above the origin, but that does not matter to me.

Code: [Select]
`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(); }`

7
##### Support / Re: Rotating the Camera up an down around the Origin
« on: April 08, 2012, 06:36:28 pm »
Ok, I'm blind - just found the RotateCameraAxis() Method.

Edit: Nope, that's not it. The camera rotates around itself instead around the origin.

8
##### Support / Re: Software Renderer in Swing Component and swapping out the jPCT class
« on: April 08, 2012, 05:54:46 pm »
I could also implement the action listener into the class, where the world and the frame buffer reside?

9
##### Support / Re: Software Renderer in Swing Component and swapping out the jPCT class
« on: April 08, 2012, 05:34:02 pm »
Eclipse tells me so, when I write the rotation method and put it in the Actionlistener.

10
##### Support / Rotating the Camera up an down around the Origin
« on: April 08, 2012, 12:42:34 pm »
I have Objects siting at the origin and want to rotate the camera around that point.

Rotating left and right is no problem, as it is always a rotation around the y-axis. But Rotating up and down is quite difficult, as it is no rotation around a fixed axis. I looked into the methods of the camera, the SimpleVector and the Matrixc, but did not really find something to work with.

Can anyone give me a tip?

11
##### Support / Re: Software Renderer in Swing Component and swapping out the jPCT class
« on: April 08, 2012, 12:22:10 pm »
With the permission of Egon, I could put it into the wiki.

12
##### Support / Re: Software Renderer in Swing Component and swapping out the jPCT class
« on: April 08, 2012, 11:11:11 am »
Got it working

There are two problems I still have:
1. Camera rotation left-right is ok, as it is a rotation around the z-axis, but rotation up-down is quite difficult. I will open up a new thread for this.
2. Why do the world and the frame buffer to be static?

GUI:
Code: [Select]
`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); }}`
RenderPanel Class
Code: [Select]
`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);    }    }`

13
##### Support / Re: Software Renderer in Swing Component and swapping out the jPCT class
« on: April 07, 2012, 08:55:45 pm »
Yeah, you are right, I want to rotate at least the camera around the scene ...

Ok, then I will go this way further. Mysteriously WindowBuilder opens the GUI correctly.

How do I update the component, e.g. when I add new objects or rotate something? How do I force the paint-method of my component?

14
##### Support / Re: Software Renderer in Swing Component and swapping out the jPCT class
« on: April 07, 2012, 08:22:44 pm »
Is there a way to do it without extending a JPanel or JLabel or ...
because otherwise I cannot use WindowsBuilder ...

Got it at least working :
Code: [Select]
`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);    }    }`

15
##### Support / Re: Software Renderer in Swing Component and swapping out the jPCT class
« on: April 07, 2012, 07:00:13 pm »
I thought the framebuffer method getGraphics does the job ...

so the jPCT Class has to be an extension of an component?

Pages: [1] 2