Show Posts
|
|
Pages: [1]
|
|
1
|
Java Game APIs & Engines / Java 3D / Re: How to draw a line between two points
|
on: 2004-09-02 14:09:42
|
|
masterX,
Thanks but it still doesn't do the trick. It is still off by 90 degrees for the first two, and for the points: (0,0,0) & (1,1,1) is still off by 45 degrees, but with a 90 degree extra rotation as compared to one without the invert call on the transform
Best, RDL
|
|
|
|
|
2
|
Java Game APIs & Engines / Java 3D / Re: How to draw a line between two points
|
on: 2004-09-02 04:58:07
|
misterX, I don't know if you tried it out but it doesn't work for me. I did stop getting the NaNs in the rotation matrix which I changed the up axis, but the rotations still end up being off -- looking a lot like how they were off when I tried coding it myself. For: (0,1,0) it was off by 90 on the x axis For: (0,1,1) it was off by 90 again, being essentially perpendicular to the two points For: (1,1,1) it was off by about 45 degrees I did come accross this website which explains it in openGL but when I tried to implement it in Java it wouldn't work for me: http://www.mfcogl.com/OpenGL%20-%20draw%20cylinder%20between%202%20pts.htm
|
|
|
|
|
3
|
Java Game APIs & Engines / Java 3D / Re: How to draw a line between two points
|
on: 2004-09-01 04:28:52
|
|
I tried the lookAt function but I get the following translation matrix which has NaN numbers (?):
NaN, NaN, NaN, NaN NaN, NaN, NaN, NaN 0.0, 1.0, 0.0, -1.0 0.0, 0.0, 0.0, 1.0
Point3d p1 = new Point3d(0,0,0); Point3d p2 = new Point3d(0,1,0); Vector3d mag = new Vector3f(); mag.sub(p2, p1); Transform3D translate = new Transform3D(); Point3d eye = new Point3d(mag); Point3d center = new Point3d(0,0,0); translate.lookAt(eye, center, new Vector3d(0,1,0));
I am guesing I am getting this because there is some divide by 0s going on in the lookAt function and so this will be no good for me then?
Thanks RDL
|
|
|
|
|
4
|
Java Game APIs & Engines / Java 3D / Performing consecutive rotations
|
on: 2004-08-31 23:14:07
|
I am trying to perform consecutive rotations on a cylinder but once I do the first rotation my coordinate space changes and it messes everything up for consecutive rotations. I would like to keep rotating the object with reference to world space. I find it frustrating that if I use Transform3D that I can do a rotZ OR a rotY for instance, but they are not cumulative which is what I would like to accomplish. Basically I have to take a cylinder and orientate it properly with the correct rotation so I need to perform rotations for roll pitch and yaw to get it correct. I am using the following code to fgure this out. As you can see, if I want to rotate the cylinder along the x axis, and then turn it on its side by rotating (world coord) on the Y axis it doesn't work because it rotates on its own axis. Matrix3f m3f1 = new Matrix3f(); m3f1.setIdentity(); //Z axis double zRot = Math.atan2(delta.y, delta.x); m3f1.m00 = (float)Math.cos(zRot); m3f1.m01 = (float)Math.sin(zRot); m3f1.m10 = -(float)Math.sin(zRot); m3f1.m11 = (float)Math.cos(zRot); // Y axis Matrix3f m3f2 = new Matrix3f(); m3f2.setIdentity(); double yRot = -Math.PI/2 + Math.atan2(delta.z, delta.x); m3f2.m00 = (float)Math.cos(yRot); m3f2.m02 = -(float)Math.sin(yRot); m3f2.m20 = (float)Math.sin(yRot); m3f2.m22 = (float)Math.cos(yRot); //X Axis Matrix3f m3f3 = new Matrix3f(); m3f3.setIdentity(); double xRot = -Math.PI/2 + Math.atan2(delta.z, delta.y); m3f3.m11 = (float)Math.cos(xRot); m3f3.m12 = (float)Math.sin(xRot); m3f3.m21 = -(float)Math.sin(xRot); m3f3.m22 = (float)Math.cos(xRot); Matrix3f inverse = new Matrix3f(m3f3); m3f3.mul(m3f3, m3f2); m3f3.mul(m3f3, m3f1);
Thanks in advance.
|
|
|
|
|
5
|
Java Game APIs & Engines / Java 3D / Re: How to draw a line between two points
|
on: 2004-08-31 03:22:29
|
I tried the following (see function below) but when I setRotation on the Transform3D matrix of the object I get absolutly no change. 1 2 3 4 5 6 7 8 9 10 11 12 13
| public static Matrix3f getRotationMatrixBetweenPoints(Vector3f p1, Vector3f p2){ Transform3D t3d = new Transform3D(); Vector3f midpoint = midPoint(p1, p2); System.out.println(t3d); t3d.lookAt(new Point3d(p1), new Point3d(p2), new Vector3d(0,1,0) ); System.out.println(t3d); Matrix3f transformationMatrix = new Matrix3f(); t3d.get(transformationMatrix); return transformationMatrix; } |
RDL
|
|
|
|
|
6
|
Java Game APIs & Engines / Java 3D / Re: How to draw a line between two points
|
on: 2004-08-30 19:37:01
|
|
Any chance of anyone being a little more explicit on how to accomplish this whether using the lookAt function or just basic maths. I have been playing around with this and my Transform3D matrix ends up with NaN in the matrix or there doesn't seem to be any transformation going on at all when I try it.
I imagine this is a pretty straight forward procedure but my lack of graphics experience and a lack of understanding of the Java API is making this difficult to accomplish.
Thanks RDL
|
|
|
|
|
7
|
Java Game APIs & Engines / Java 3D / How do I orientate a cylinder between two points
|
on: 2004-08-28 23:15:04
|
|
I need to draw a line (actually a cylinder) between two points. I know that the length of the clinder will just be the distance between the two points, and the center of the cylinder will be at the midpoint of the two points: ((x2-x1)/2, (y2-y1)/2, (z2-z1)/2); but how do I go about figuring out what the transformation matix will be. Sorry, I know this is basic 3d math stuff.
Thanks in advance, RDL
|
|
|
|
|
8
|
Game Development / Game Mechanics / Re: ALife , Sodaplay & Springs
|
on: 2004-07-22 19:48:05
|
|
P.S. I am on a bit of a tight deadline her as I am trying to get my implementation in a suitible form as I would like to show what I have to some people at the upcomming alife conference.
That said, if anyone wants to make some extra money I would gladly pay because I know this is going to take me awhile to figure out!
Thanks, RDL
|
|
|
|
|
9
|
Game Development / Game Mechanics / Re: ALife , Sodaplay & Springs
|
on: 2004-07-22 19:44:47
|
|
One thing I am thinking about with the "standard" spring solution is that this is a "cellular" system and not a particle system and I would like the "springs" to act kind of like muscles. One thing I noticed with regular springs implementations is that if I have something like a box, where each vertex is a point and each edge is a spring you also need to apply springs on the cubes diameter so that it doesn't collapse.
Joints are different however because they kind of weld the connecting objects along an axis. I would like to keep that (doesn't matter if they spin) but I would like them to have some push-pull flexibility as well as some "bending" capability.
Thanks RDL
|
|
|
|
|
10
|
Game Development / Game Mechanics / Re: ALife , Sodaplay & Springs
|
on: 2004-07-21 19:56:14
|
|
Thanks. That is pretty interesting. I am looking over the source code now to see if it would be easier to use java ODE or try to integrate this.
Oh, one more thing. If I was to implement this in odejava would I need to use the lowlevel api or would there be enough there to use the highlevel api?
|
|
|
|
|
11
|
Game Development / Game Mechanics / ALife , Sodaplay & Springs
|
on: 2004-07-20 18:06:07
|
My research is in ALife and I have used ODE and Vortex so I have some familiarity with physics engines. Currently I am looking to move away from "joint" driven creatures to "spring" driven creatures. An example of this are the creatures of sodayplay: http://www.sodaplay.com/. I am hoping someone might be able to give me some advice on this before I begin to tackle this problem. It seems to me that slider joints would be insufficient and ODE doesn't seem to have "multi-point tension spring" which seem to be what is used in Sodayplay ( http://www.sodaplaycentral.com/articles/tension1.php) I would be *very* interested in hearing anything anyone would have to offer on this. Thanks, RDL
|
|
|
|
|
15
|
Java Game APIs & Engines / Xith3D Forums / Re: Panning with the mouse
|
on: 2004-06-14 21:25:37
|
Don, I am not sure about you, but implementing the function the way you suggest is giving me really strange behavior and it gets hard to control the camera as the object moves to the edge of the field of view. In addition, it still suffers from the problem that when you move from a zoom to a pan that it resets the camera position. Am I the only one who finds it strange that this should be so hard? Previously when I was using Vortex and ODE (physics engines written in C) this kind of mouselook was already implemente into the system. Not wanting to indulge in masochism anymore, I am moving to Java, but in ode4java none of the example code has the mouselook implementation. I had assumed this would have been a fairly standard tool in a 3d library? Best RDL P.S. If you are interested, you my website has movies of some of my previous work. http://www.cpsc.ucalgary.ca/~leclerc
|
|
|
|
|
16
|
Java Game APIs & Engines / Xith3D Forums / Mouselook
|
on: 2004-06-14 19:51:32
|
Hi all, I seem to be getting closer to getting a working demo of a cameralook. I pulled some code from another post which was doing something similar and added it into a modified version of MouseInteraction.java which I am basing the demo on http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=xith3d;action=display;num=1077631615. The code more or less does what I am asking except it has two bugs still which I can't figure out. 1) It seems to reset the camera perspective when you move to a different kind of camera movement. I tried updating the "trans" values with the new location but this didn't work for me. 2) If you look carefully I think I am getting gimbel lock (I think this is what it is called) which is causing some problems on the rotations around 90degrees. The code below has a main method and can be run without modification. Anyone have any suggestions for how to fix these two problems? I think this would be a valuable demo for the xith3d project since it seems other people have both A) had similar problems B) are interested in some demo code which addresses this. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
| import java.awt.*; import java.awt.event.*;
import javax.vecmath.*;
import com.xith3d.scenegraph.*; import com.xith3d.test.*;
import com.xith3d.loaders.texture.TextureLoader; import com.xith3d.render.*; import com.xith3d.render.jogl.*;
public class MouseInteraction { private float rotX = 0; private float rotY = 0; private float rotZ = 0;
private float rotXTmp = 0; private float rotYTmp = 0; private float rotZTmp = 0;
private TransformGroup objRotate; private Transform3D rotate;
private float transX = 0; private float transY = 0; private float transZ = 0;
private float transXTmp = 0; private float transYTmp = 0; private float transZTmp = 0;
private TransformGroup objTranslate; private Transform3D translate; View view = null; VirtualUniverse universe = null; private int startDragX; private int startDragY;
private boolean isRotationScheduled = false; private boolean isTranslationScheduled = false;
BranchGroup scene = null; class EventListener implements AWTEventListener { public void eventDispatched(AWTEvent event) { if(event instanceof MouseEvent) { MouseEvent e = (MouseEvent) event; switch(e.getID()) { case MouseEvent.MOUSE_PRESSED: mousePressed(e); break; case MouseEvent.MOUSE_RELEASED: mouseReleased(e); break; case MouseEvent.MOUSE_DRAGGED: mouseDragged(e); break; } } else if(event instanceof KeyEvent) { KeyEvent e = (KeyEvent) event; switch(e.getID()) { case KeyEvent.KEY_TYPED: keyTyped(e); break; } } } } public static void main(String[] args) { new MouseInteraction(); }
public MouseInteraction() { universe = new VirtualUniverse(); view = new View(); universe.addView(view); Locale locale = new Locale(); universe.addLocale(locale); scene = new BranchGroup(); locale.addBranchGraph(scene); translate = new Transform3D(); objTranslate = new TransformGroup(translate); scene.addChild(objTranslate);
rotate = new Transform3D(); objRotate = new TransformGroup(rotate); objTranslate.addChild(objRotate); Geometry g = Cube.createCubeViaTriangles(0, 0, 0, 1, true); Shape3D cube = new Shape3D(g, new Appearance()); objRotate.addChild(cube); addPlane(); scene.compile();
RenderPeer rp = new RenderPeerImpl(); CanvasPeer cp = rp.makeCanvas(null, 640, 480, 32, false); Canvas3D canvas = new Canvas3D(); canvas.set3DPeer(cp); Toolkit.getDefaultToolkit().addAWTEventListener( new EventListener(), AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK);
view.addCanvas3D(canvas);
transX = 0; transY = 0; transZ = 10; view.getTransform().lookAt(new Vector3f( transXTmp, transYTmp, transZ), new Vector3f( 0, 0, 0), new Vector3f( 0, 1, 0)); while(true) { view.renderOnce(); if(isRotationScheduled) { performRotation(); isRotationScheduled = false; } if(isTranslationScheduled) { performTranslation(); isTranslationScheduled = false; } }
}
private void keyTyped(KeyEvent e) { switch(e.getKeyChar()) { case 27: System.exit(0); break; } }
public void addPlane(){ Appearance groundApp = new Appearance(); groundApp.setPolygonAttributes( new PolygonAttributes( PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0)); float k = 2f; float w = 2f; float x1 = -2f; float x2 = 2f; float y = 0f; float z1 = -w; float z2 = w; float tsx = k * 1f; float tsy = k * 1f; Shape3D shape = new Shape3D(); Geometry geom = TestUtils.createQuad( new Point3f(x1, z1, y), new Point3f(x1, z2, y), new Point3f(x2, z2, y), new Point3f(x2, z1, y), tsx, tsy); shape.setAppearance(groundApp); shape.setGeometry(geom); objRotate.addChild(shape); } public void mouseDragged(MouseEvent e) { switch(e.getModifiers()) { case MouseEvent.BUTTON1_MASK: leftDrag(e); break; case MouseEvent.BUTTON2_MASK: middleDrag(e); break; case MouseEvent.BUTTON3_MASK: rightDrag(e); break; } }
private void mousePressed(MouseEvent e) { startDragX = e.getX(); startDragY = e.getY(); }
private void mouseReleased(MouseEvent e) { rotX = rotXTmp; rotY = rotYTmp; rotZ = rotZTmp; transX = transXTmp; transY = transYTmp; transZ = transZTmp; }
private void leftDrag(MouseEvent e) { rotXTmp = rotY + (e.getY() - startDragY)/100f; rotYTmp = rotX + (e.getX() - startDragX)/100f; isRotationScheduled = true; }
private void middleDrag(MouseEvent e) { transZTmp = (transZ + (e.getY() - startDragY)/100f); isTranslationScheduled = true; }
private void rightDrag(MouseEvent e) { transXTmp = -(transX + (e.getX() - startDragX)/100f); transYTmp = -(transY - (e.getY() - startDragY)/100f); isTranslationScheduled = true; }
private void performRotation() { float cos = (float)Math.cos(rotXTmp); float x = cos*(float)Math.cos(rotYTmp) * transZTmp; float y = (float)Math.sin(rotXTmp) * transZTmp; float z = cos*(float)Math.sin(rotYTmp) * transZTmp; view.getTransform().lookAt(new Vector3f(x,y,z), new Vector3f( 0, 0, 0), new Vector3f( 0, 1, 0)); }
private void performTranslation() { view.getTransform().setTranslation(new Vector3f(transXTmp, transYTmp, transZTmp)); } } |
P.S. Don: One of the only problems with thre rotation the way you suggested is it doesn't maintain a camera perspective based on the origin. Thanks, Rob Leclerc
|
|
|
|
|
17
|
Java Game APIs & Engines / Xith3D Forums / Re: Panning with the mouse
|
on: 2004-06-14 09:27:03
|
Don, Thanks, I will take a closer look at the robot tomorrow. I have been spending time with the MouseInteraction.java, which moves the cube. This bascally does exactly what I want from a camera perspective but it moves the location of the *box* and not the location of the *camera*, which is not what I want. Playing with it I figured out that I could pan and zoom with the camera view simply by changing the code in the example to: 1 2 3 4 5
| private void performTranslation() { view.getTransform().setTranslation(new Vector3f(transXTmp, transYTmp, transZTmp));
} |
Thus I am moving the translation vector of the view object. However, when I tried to rotate view in a similar way (see below) I wasn't able to get the desired behaviour and I just end up resetting my camera position to (0,0,0) whenever I do a left mouse drag. I had hoped I could just do the following, or something like it but no luck. 1 2 3
| private void performRotation() { view.getTransform().rotXYZ(rotXTmp, rotYTmp, 0); } |
Anyone have any idea why this isn't working for me? Thanks again Rob Leclerc
|
|
|
|
|
18
|
Java Game APIs & Engines / Xith3D Forums / Re: Panning with the mouse
|
on: 2004-06-13 21:05:12
|
Don, Thanks for the code -- this seems to be doing some of the job but it has some weird behaviour -- maybe I haven't implemented this correctly -- my work has mostly been scientific and I haven't had much experience using AWT so I am probably doing something wrong. Running this I get some mouselook behaviour but it is limited to the transform group rotating around my camera view in a clockwhise manner, moving down, around behind the camera, and then showing up again at the top of the screen. I am unable to pan, or zoom around the root transform group. Is this what the behaviour is suppose to be like? I had kind of assumed that moving the mouse would have moved various properties of the camera view . I set the middleScreenX and middleScreenY to 320x240 as I am using a 640x480 screen. I am assuming this is correct. As well, other than initializingthe robot, is there anything else I need to do to it? Finally, I was playing around with the various case statements: do I need more than just the following code in the mouse portion of the event listener? 1 2
| case MouseEvent.MOUSE_DRAGGED : mouseMoved(e); break; |
Thanks Rob Leclerc P.S. I just came accros the MouseInteraction tutorial: http://xith.org/tutes/GettingStarted/html/interaction.html
This was basically what I have in mind, but do you know if this is moving the *object* or is this moving the *camera view* while the objects position is maintained? Thanks, RDL
|
|
|
|
|
19
|
Java Game APIs & Engines / Xith3D Forums / Panning with the mouse
|
on: 2004-06-13 00:21:38
|
|
I appologize if this is a newbie question, but I am trying to find where in xith3d I enable the ability to use the mouse to pan around the origin or another specified point? This seems like it would be a fairly standard feature, but I haven't been able to find it anywhere.
Thanks, RDL
|
|
|
|
|
20
|
Game Development / Performance Tuning / Fastest JVM?
|
on: 2004-06-11 22:56:20
|
|
Anyone had any "real world" experience with various JVMs on different platforms? I have been using JRockit for awhile now and found it to run about 60-100% faster than suns for what I am using it for. Anyone have any expierience with blackcomb or any other JVM's one might want to look at?
RDL
|
|
|
|
|
21
|
Game Development / Game Mechanics / Never mind
|
on: 2004-06-11 21:23:42
|
|
When I imported the file system I mounted everything under the the ode directory that includes the logging property file. Once that was in the path I had no problems.
Best RDL
|
|
|
|
|
22
|
Game Development / Game Mechanics / java.lang.ExceptionInInitializerError
|
on: 2004-06-11 17:59:22
|
|
I am trying to intall java for ode into eclipse -- I added all the jars and put all the dll's in C:/Windows/system32. I was able to run some of the xith3d tests but as soon as I tried running the ode tests I started getting errors (see below). Anyone know what is causing these errors? I am guessing that this is a PATH problem of sorts but I am running out of solutions. I tried just dumping the dlls into the Project root as well but it didn't affect anything.
Odejava version 0.2.4 java.lang.ExceptionInInitializerError at org.odejava.Space.addGeom(Space.java:125) at org.odejava.test.car.Car.createRamps(Car.java:204) at org.odejava.test.car.Car.initStaticObjects(Car.java:178) at org.odejava.test.car.Car.initWorld(Car.java:169) at org.odejava.test.car.Car.<init>(Car.java:123) at org.odejava.xith3d.test.CarExample.<init>(CarExample.java:130) at org.odejava.xith3d.test.CarExample.main(CarExample.java:109) Caused by: java.lang.NullPointerException at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:424) at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:327) at org.odejava.Odejava.<clinit>(Odejava.java:82) ... 7 more Exception in thread "main"
And for the TriMesh example: java.lang.ExceptionInInitializerError at org.odejava.test.simple.TriMesh.<init>(TriMesh.java:94) at org.odejava.xith3d.test.TriMeshExample.<init>(TriMeshExample.java:111) at org.odejava.xith3d.test.TriMeshExample.main(TriMeshExample.java:90) Caused by: java.lang.NullPointerException at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:424) at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:327) at org.odejava.Odejava.<clinit>(Odejava.java:82) ... 3 more Exception in thread "main"
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|