Show Posts
|
|
Pages: [1]
|
|
1
|
Java Game APIs & Engines / Xith3D Forums / Re: new Text2D implementation
|
on: 2005-09-18 22:32:38
|
|
Thanks Florian, I plan on using this but am having a few problems. I'm new at this so it could very well be user error.
First of all when you call the constructor "public Text ( String newText )" it doesn't initialize user data so you get null pointer exceptions. Second, when I use the other constructor to initialize everything I set font to "Arial" but all I get out is rectangle polygons where the text should be. Do I need to set up the fonts somehow?
Last I was wondering if you could add a feature to have the text always facing the screen even when you rotate view. That's how the old static Text2D worked. I might be able to figure this out myself, not too sure yet though, like I said I'm new at this. Thanks!
|
|
|
|
|
3
|
Java Game APIs & Engines / Xith3D Forums / Re: Loading animations?
|
on: 2005-06-26 01:32:20
|
|
Thanks kev, this loader rocks! Although I do have a question. I'm using Milkshape 3d, I just started learning it. There doesn't appear to be a way to save multiple animations in one .md2 file. It appears in your example with the alien you call both the run and stand animations from the same file, how is this possible? Am I missing something or do I need to find a better modeling program?
|
|
|
|
|
4
|
Java Game APIs & Engines / Xith3D Forums / Re: Loading animations?
|
on: 2005-06-25 03:16:26
|
I finally got a chance to check out the newdawn MD2 loader... looks pretty easy to use although there are some compilation errors: 1 2 3 4 5 6 7 8 9 10 11
| java.lang.Error: Unresolved compilation problems: BranchGroup.ALLOW_CHILDREN_READ cannot be resolved BranchGroup.ALLOW_CHILDREN_EXTEND cannot be resolved BranchGroup.ALLOW_CHILDREN_WRITE cannot be resolved
at org.newdawn.xith3d.loaders.md2.MD2ModelInstance.<init>(MD2ModelInstance.java:72) at org.newdawn.xith3d.loaders.md2.MD2Model.getInstance(MD2Model.java:101) at MD2Test.loadModel(MD2Test.java:200) at MD2Test.<init>(MD2Test.java:117) at MD2Test.main(MD2Test.java:275) Exception in thread "main" |
I don't seem to have a definition for those BranchGroup constants? Can anyone give me information on how to resolve? Thanks!
|
|
|
|
|
6
|
Java Game APIs & Engines / Xith3D Forums / Loading animations?
|
on: 2005-05-09 18:02:02
|
|
I'm looking for information on how to load a model and animations for my game. I need a soldier with animations such as run, grenade, shoot, etc. Obviously I'll start off with something simpler, but that's my ultimate goal.
I'm new to this so I'm wondering what format models I should use and if there are any free modeling programs I can use to make models that will load easily. Basically any information to help me get started with adding animated models to my game. Thanks!
|
|
|
|
|
8
|
Java Game APIs & Engines / Xith3D Forums / Re: Picking
|
on: 2005-03-08 04:25:10
|
I found another post mentioning Canvas3D.createPickRay(). I had to download the method from CVS but it was worth it, helped me a ton I think I got it figured out now. Thanks guys! createPickRay() from CVS 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
| public void createPickRay(int x, int y, Point3f o, Vector3f d) { float w = (float) canvas.getWidth(); float h = (float) canvas.getHeight(); float a = h / w; if (view.getProjectionPolicy() == View.PERSPECTIVE_PROJECTION) { float rx = (2.0f * (float) x / w - 1.0f) / a; float ry = 2.0f - 2.0f * (float) y / h - 1.0f;
float vpd = 1.0f / (float) Math.tan(view.getFieldOfView());
o.set(0.0f, 0.0f, 0.0f); d.set(rx, ry, -vpd); d.normalize(); } else { float rx = 2.0f * (float) x / w - 1.0f; float ry = a * (2.0f - 2.0f * (float) y / h - 1.0f);
float s = view.getScreenScale(); o.set(s * rx, s * ry, 0.0f); d.set(0.0f, 0.0f, -1.0f); }
view.getTransform().transform(o); view.getTransform().transform(d); } |
|
|
|
|
|
9
|
Java Game APIs & Engines / Xith3D Forums / Re: Picking
|
on: 2005-03-05 15:53:25
|
I have got a flat shape... a quad. So I should try DonCrudelis' code or is that just for terrain object? Here is what I'm doing now, I changed Global.terrain.getY to 0, and I pass in Z for Y and Y for Z since I have Y as up. 1 2 3 4 5 6 7 8 9
| public void mouseClicked(MouseEvent e) { Vector3f vect = new Vector3f(); vect = getTerrainIntersection(e.getPoint(), new Point3f(camX, camZ, camY), new Point3f(viewX, 0, viewY)); System.out.println(vect.x); System.out.println(vect.z); isViewChangeScheduled = true; } |
What I get out of this are values very close to my viewX and viewY I put into it. My viewX=5 and viewY=5 i get output like: X = 5.0227056 Y = 4.992122 X = 5.004961 Y = 5.0184546 X = 4.9696717 Y = 5.014441 clicking in various places - this is obviously not what I want =/ oh yeah, and this is with the camera overhead looking straight down, if I change the angle of it then it gives me different numbers, but still nothing close to what I want
|
|
|
|
|
10
|
Java Game APIs & Engines / Xith3D Forums / Re: Picking
|
on: 2005-03-05 13:03:14
|
I am getting so frustrated with this, I can't get this to work. Most of this stuff I am not following. I either need a detailed tutorial to follow or some code I can plug in and run with. I have my eye at (camX, camY, camZ) and I have it looking at (viewX, viewY, 0) I'm just trying to get the X,Y coords where the user clicked Z will always be 0 its a flat terrain... I've spent so much time on this and still have nothing  please help!
|
|
|
|
|
11
|
Java Game APIs & Engines / Xith3D Forums / Re: Picking
|
on: 2005-03-05 00:55:12
|
|
Thanks Macca, I've had some more time to look at this and realized Globals.terrain.getY is also undefined. Any ideas about that one?
Globals.terrain.getY(pointerPos.x, pointerPos.z)
|
|
|
|
|
15
|
Java Game APIs & Engines / Xith3D Forums / Re: Picking terrain
|
on: 2005-02-27 14:16:36
|
|
I am having major problems with this. I cannot seem to find any clear examples anywhere and all the explanations I find just go over my head. I have an XY plane where Z is 0 and I need the XY coords of where they click on that plane. Can anyone help?
|
|
|
|
|
18
|
Java Game APIs & Engines / Xith3D Forums / understanding branchgroup and transformgroup
|
on: 2005-02-05 04:37:36
|
|
I've been playing with Xith3D off and on for several months now and I'm trying to get my mind around how the BranchGroup and TransformGroup are best used.
So as I understand it you make a universe and add a locale and a scene (branchgroup), one of each right? Now if I have several Shape3d's to add at different translations and rotations, do I need to create two new TransformGroup's (one for translation one for rotation) for every shape? Or am I supposed to just keep using the original objTranslate and objRotate and "reset" them after drawing each shape?
Hopefully I am making some sense here, its possible I'm just entirely confused and no one will understand me.
|
|
|
|
|
19
|
Java Game APIs & Engines / Xith3D Forums / box feature?
|
on: 2004-11-15 04:40:29
|
|
The create cube function used in the tutorials is very simple I like it, there wouldn't happen to be a similar function for drawing a 3d box with different length, height, and width would there? It would be much easier than plotting coords for 6 different quads to get a box.
|
|
|
|
|
20
|
Java Game APIs & Engines / Xith3D Forums / Re: rotation question
|
on: 2004-11-12 08:39:02
|
To rotate around a particular axis, this is one way. 1
| hero.getTransform().setRotation(new AxisAngle4f(new Vector3f(0, 0, 1), 3.14f)) |
It sounds to me like you have two transform3d nodes (one for rotation and one for translation) and that you have their positions in the scenegraph mixed up. To convert mouse coords to world coords, you might need to consider that the (0,0) is at the top left of the canvas for the mouse and (0,0,0) is at the center. You can always do a hack conversion like this "(e.getX() - canvas.getWidth()/2)/3;" till you can figure out the trig to get the correct values of depth Thank you for the reply, however I still can't seem to get it working the way I want. What is the "hero" in that line of code? Your saying the best way to get the X,Y coords in world is to convert from mouse coords using math? I'll play with that idea some more and see if I can figure something out. Here is my code so you get a better idea of what I'm trying to do, I want to rotate around viewX and viewY and it will only rotate around 0,0. If you notice any other problems, please comment. Thanks! 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 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
| import javax.vecmath.*; import java.awt.*; import java.awt.event.*;
import com.xith3d.scenegraph.*; import com.xith3d.test.*;
import com.xith3d.render.*; import com.xith3d.render.jogl.*; import com.xith3d.loaders.texture.*; public class Xith implements KeyListener { private int SCREEN_WIDTH = 1024; private int SCREEN_HEIGHT = 768; private int MAP_WIDTH = 10; private int MAP_HEIGHT = 10; private int STARTING_TILE_X = 5; private int STARTING_TILE_Y = 5; private VirtualUniverse universe; private View view; private BranchGroup scene;
private boolean isViewChangeScheduled = true; private TransformGroup objRotate; private Transform3D rotate; private boolean isRotationScheduled = true; private float rotX = 0; private float rotY = 0; private float rotZ = 0; private TransformGroup objTranslate; private Transform3D translate; private float camX = 0; private float camY = 0; private float camZ = 10f; private float viewX = STARTING_TILE_X; private float viewY = STARTING_TILE_Y; private static final float PI = 3.141592654f; 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 Xith(); }
public Xith() { Texture2D textureGrass = null; TextureLoader tl = new TextureLoader();
tl.registerPath("./");
textureGrass = (Texture2D) tl.getMinMapTexture("textures/grass.png");
createUniverse();
translate = new Transform3D(); objTranslate = new TransformGroup(translate); scene.addChild(objTranslate);
rotate = new Transform3D(); objRotate = new TransformGroup(rotate); objTranslate.addChild(objRotate); Geometry terrain = createMap(); Geometry wall = createWall(); Appearance a = new Appearance(); a.setTexture(textureGrass); Shape3D sh = new Shape3D(terrain, a); objRotate.addChild(sh); Shape3D sh2 = new Shape3D(wall, a); objRotate.addChild(sh2);
scene.compile();
RenderPeer rp = new RenderPeerImpl(); CanvasPeer cp = rp.makeCanvas(null, SCREEN_WIDTH, SCREEN_HEIGHT, 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);
cp.getComponent().addKeyListener(this);
view.addCanvas3D(canvas); view.startView();
while (true) { view.renderOnce();
if (isViewChangeScheduled ) handleView(); if (isRotationScheduled ) handleRotation(); } }
private void createUniverse() { universe = new VirtualUniverse();
view = new View(); universe.addView(view);
Locale locale = new Locale(); universe.addLocale(locale);
scene = new BranchGroup(); locale.addBranchGraph(scene); }
private void handleView() { float distance = camZ; camY = viewY; camX = viewX; view.getTransform().lookAt( new Vector3f(camX, camY, camZ), new Vector3f(viewX, viewY, 0), new Vector3f(0, 1, 0)); isViewChangeScheduled = false; }
private void handleRotation() { rotate.rotXYZ(rotX, rotY, rotZ); isRotationScheduled = false; objRotate.setTransform( rotate ); } public Geometry createMap() { Point3f[] coords = new Point3f[] { new Point3f(0, 0, 0), new Point3f(MAP_WIDTH, 0, 0), new Point3f(MAP_WIDTH, MAP_HEIGHT, 0), new Point3f(0, MAP_HEIGHT, 0)}; TexCoord2f[] texCoords = new TexCoord2f[] { new TexCoord2f(0f, 0f), new TexCoord2f(MAP_WIDTH, 0f), new TexCoord2f(MAP_WIDTH, MAP_HEIGHT), new TexCoord2f(0f, MAP_HEIGHT) }; QuadArray g = new QuadArray(coords.length, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2); g.setCoordinates(0, coords); g.setTextureCoordinates( 0, 0, texCoords );
return g; }
public Geometry createWall() { Point3f[] coords = new Point3f[] { new Point3f(5, 5, 0), new Point3f(6, 5, 0), new Point3f(6, 5, 3), new Point3f(5, 5, 3)}; TexCoord2f[] texCoords = new TexCoord2f[] { new TexCoord2f(0f, 0f), new TexCoord2f(1f, 0f), new TexCoord2f(1f, 1f), new TexCoord2f(0f, 1f) }; QuadArray g = new QuadArray(coords.length, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2); g.setCoordinates(0, coords); g.setTextureCoordinates( 0, 0, texCoords );
return g; } public void keyPressed(KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_INSERT : changeTilt(-0.1f); break; case KeyEvent.VK_HOME : changeTilt(0.1f); break; case KeyEvent.VK_END : changeRotation(+0.2f); break; case KeyEvent.VK_DELETE : changeRotation(-0.2f); break; case KeyEvent.VK_UP : changeViewY(+0.1f); break; case KeyEvent.VK_DOWN : changeViewY(-0.1f); break; case KeyEvent.VK_RIGHT : changeViewX(0.1f); break; case KeyEvent.VK_LEFT : changeViewX(-0.1f); break; case KeyEvent.VK_PAGE_UP : changeZoom(-0.1f); break; case KeyEvent.VK_PAGE_DOWN : changeZoom(0.1f); break; } }
public void mouseDragged(MouseEvent e) {}
private void mousePressed(MouseEvent e) { isViewChangeScheduled=true; }
private void mouseReleased(MouseEvent e) {} private void changeViewX( float change ) { changeView( change, 0 ); } private void changeViewY( float change ) { changeView( 0, change ); }
private void changeView( float xChange, float yChange ) { viewX += xChange; viewY += yChange; isViewChangeScheduled = true; }
private void changeZoom( float change ) { camZ += change; isViewChangeScheduled = true; } private void changeTilt( float change ) { rotX += change; isRotationScheduled = true; } private void changeRotation( float change ) { rotZ += change; isRotationScheduled = true; }
public void keyTyped(KeyEvent e) {}
public void keyReleased(KeyEvent e) {} } |
|
|
|
|
|
21
|
Java Game APIs & Engines / Xith3D Forums / rotation question
|
on: 2004-11-11 09:01:54
|
|
Hi, I have what is probably a simple question and I'm learning Xith3D to use to create a game so expect many more!
I'm wondering how I can use the rotate function to rotate around the Z axis at specified X and Y coords. Instead of always rotating around (0,0). Sorry if this is in the docs somewhere I must have missed it, thanks!
Ok, I have another question already, its along the same lines so I'll post it here as well:
I have my event listener set up already, and I'm wondering how I can get the X and Y coords of where the user clicks. I got the mouse coords using e.getX() and e.getY() however that doesn't help me I need the X,Y coords on my game map. Thanks again.
|
|
|
|
|
22
|
Java Game APIs & Engines / Xith3D Forums / Re: need texture help
|
on: 2004-08-07 19:53:53
|
Thanks hawk, I was trying to use the code from the simple texture tutorial, I guess it doesn't work with the quad. Here is my working code snippet if anyone else was having this problem: 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
| BranchGroup scene = new BranchGroup(); locale.addBranchGraph(scene); TexCoord2f[] texCoords = new TexCoord2f[] { new TexCoord2f(0f, 0f), new TexCoord2f(1f, 0f), new TexCoord2f(1f, 1f), new TexCoord2f(0f, 1f) }; Point3f[] coords = new Point3f[] { new Point3f(0, 0, 0), new Point3f(MAP_WIDTH, 0, 0), new Point3f(MAP_WIDTH, 0, MAP_HEIGHT), new Point3f(0, 0, MAP_HEIGHT), };
QuadArray g = new QuadArray(coords.length, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2); g.setCoordinates(0,coords); g.setTextureCoordinates(0,0,texCoords); Appearance a = new Appearance(); a.setTexture(textureTerrain); |
|
|
|
|
|
23
|
Java Game APIs & Engines / Xith3D Forums / need texture help
|
on: 2004-08-07 06:52:30
|
Hi all, I'm new to Xith and still fairly new to 3D programming. Using the tutorials I came up with this simple program. I'm trying to display texture on a quad instead of the cube used in the tutorial, it changes the quad's color, but the texture doesn't show. I'm using the glass.png texture from the tutorial: 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
| package xith;
import javax.vecmath.*;
import com.xith3d.scenegraph.*; import com.xith3d.test.*;
import com.xith3d.render.*; import com.xith3d.render.jogl.*; import com.xith3d.loaders.texture.*;
public class Xith { private int SCREEN_WIDTH = 1024; private int SCREEN_HEIGHT = 768; private int MAP_WIDTH = 40; private int MAP_HEIGHT = 40; private int STARTING_VIEW_X = 10; private int STARTING_VIEW_Z = 10; public static void main (String[] args) { new Xith(); } public Xith() { Texture2D textureTerrain = null; TextureLoader tl = new TextureLoader(); tl.registerPath("./textures"); textureTerrain = (Texture2D)tl.getMinMapTexture("glass.png"); VirtualUniverse universe = new VirtualUniverse(); View view = new View(); universe.addView(view); Locale locale = new Locale(); universe.addLocale(locale); BranchGroup scene = new BranchGroup(); locale.addBranchGraph(scene); Point3f[] coords = new Point3f[] { new Point3f(0, 0, 0), new Point3f(MAP_WIDTH, 0, 0), new Point3f(MAP_WIDTH, 0, MAP_HEIGHT), new Point3f(0, 0, MAP_HEIGHT), };
QuadArray g = new QuadArray(coords.length, GeometryArray.COORDINATES); g.setCoordinates(0,coords); Appearance a = new Appearance(); a.setTexture(textureTerrain); Shape3D Terrain = new Shape3D(g, a); scene.addChild(Terrain); scene.compile(); RenderPeer rp = new RenderPeerImpl(); CanvasPeer cp = rp.makeCanvas(null,SCREEN_WIDTH,SCREEN_HEIGHT,16,false); Canvas3D canvas = new Canvas3D(); canvas.set3DPeer(cp); view.addCanvas3D(canvas); view.getTransform().lookAt( new Vector3f( STARTING_VIEW_X, 15, STARTING_VIEW_Z), new Vector3f( STARTING_VIEW_X, 0, STARTING_VIEW_Z+3), new Vector3f( 0, 1, 0)); view.startView(); } } |
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|