Show Posts
|
|
Pages: [1] 2
|
|
2
|
Java Game APIs & Engines / Xith3D Forums / Rotation about a node, another problem...
|
on: 2006-05-26 09:38:17
|
I got a camera rotation code that is a little jerky. The camera is "shaking" as it rotates. It is so slight that you cant notice it unless you are close to the object you are rotating about. The shaking also moves the view a very small amount in a direction that is equal to an axis shooting out from the object's parent transformgroup origin towards the object. The shaking i could almost live with but not the gradual unwanted translation that will eventually move the camera right trough the object if facing it from the "front" side. If facing it from the "back" the camera is moved away from the object. So it's really simply translating along an axis shooting from the objects parent transformgroup right trough the object. If facing it from the side there seems to be no translation but maybe it just cant be detected from that perspective. I previously had a rotation code that didnt have this side effect but on the other hand had other bugs. What i try to do and how im thinking of the rotation is as follows: 1) Move the camera (view) to the virtual world origin. 2) Move further to the object that i want to rotate about. 3) Make the rotation 4) Move back from the rotation center. 5) Move back from virtual world origin. The following code has a simplified version for just rotating about the virtual world origin and then the "full" version about an object. In the code the following variables explained: m_root --> BranchGroup, root of the scengraph. m_view --> View, the view. m_nodeSelected --> Node, pointer to a node that has been selected. There is also the old rotation code commented out that doesnt have the shake but doesnt account for everything properly (weird rotation). /** * Rotates the camera about the selected node.<br> * Direction of the rotation is taken from <code>x</code> and <code>y</code>. * * @param x * @param y */ public void rotateCameraAboutSelectedNode(float x, float y) { Transform3D rotationLocation = new Transform3D(); Transform3D cameraLocation = new Transform3D(); Transform3D traslateLocation = new Transform3D(); Matrix3f rotation1 = new Matrix3f(); Matrix3f rotation2 = new Matrix3f(); // Determine camera location m_view.getTransform(cameraLocation);
// Determine rotation point (node or vworld) if (m_nodeSelected == null) { // for rotating about origo this works m_root.getLocalToVworld(rotationLocation);
// "invert" -> transform to origin cameraLocation.invert(); // make a rotation rotation1.setIdentity(); rotation2.rotX(y / 100.0f); rotation1.mul(rotation2); rotation2.rotY(x / 100.0f); rotation1.mul(rotation2); // multiply with current rotation cameraLocation.getRotation(rotation2); rotation1.mul(rotation2); rotation1.normalize(); // set new rotation cameraLocation.setRotation(rotation1); // "invert" -> transform back from origin cameraLocation.invert(); /* // <-- this is the old rotation // rotate rotation1.setIdentity();
rotation2.rotX(y / 100.0f); rotation1.mul(rotation2); rotation2.rotY(x / 100.0f); rotation1.mul(rotation2); rotationLocation.setRotation(rotation1); rotationLocation.mul(cameraLocation); // set new camera transform cameraLocation.set(rotationLocation); */
} else {
(This is where to look for the bug...) 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
| m_root.getLocalToVworld(rotationLocation); m_nodeSelected.getLocalToVworld(traslateLocation); cameraLocation.invert(); cameraLocation.mul(traslateLocation); rotation1.setIdentity(); rotation2.rotX(y / 100.0f); rotation1.mul(rotation2); rotation2.rotY(x / 100.0f); rotation1.mul(rotation2); cameraLocation.getRotation(rotation2); rotation1.mul(rotation2); rotation1.normalize(); cameraLocation.setRotation(rotation1); traslateLocation.invert(); cameraLocation.mul(traslateLocation); cameraLocation.invert(); |
/* // <-- old rotation code // translate to rotation point rotationLocation.mul(traslateLocation); // rotate rotation1.setIdentity(); rotation2.rotX(y / 100.0f); rotation1.mul(rotation2); rotation2.rotY(x / 100.0f); rotation1.mul(rotation2); rotation1.normalize(); rotationLocation.setRotation(rotation1); // translate away from rotation point traslateLocation.invert(); rotationLocation.mul(traslateLocation); rotationLocation.mul(cameraLocation); // set new camera transform cameraLocation.set(rotationLocation);*/ }
try { m_view.setTransform(cameraLocation); } catch (Exception e) { e.printStackTrace(); } } If you can spot the bug or point out any other mistakes like fundamentally wrong use of matrices, please help.
|
|
|
|
|
5
|
Java Game APIs & Engines / Xith3D Forums / Re: MultiPassView - Can I add it as a package to xith.tk?
|
on: 2006-03-12 08:09:02
|
|
I just committed a test program to this. Basically it just mixes parallel and perspective by rendering a cube in each mode. The cubes are rotating so that the difference can be seen.
I'll continue maintaining this so feel free to suggest improvements, other requests and of course notify bugs.
For now im leaving this as it is and head back to finalize the GUI system im working on...
Jaakko
|
|
|
|
|
8
|
Java Game APIs & Engines / Xith3D Forums / Re: MultiPassView - Can I add it as a package to xith.tk?
|
on: 2006-02-23 00:49:06
|
Ok, i tought i was at developer status but well then.. Thanks for adding me! Sorry for my recent absence but i relocated to San Francisco last week for a six weeks assignment by my company ( to learn J2ME to BREW porting  ) and im getting over the jetlag slowly. I will commit the package as soon as possible - when im fully recovered and not falling asleep at once when entering my hotel room.
|
|
|
|
|
10
|
Java Game APIs & Engines / Xith3D Forums / Re: MultiPassView - Can I add it as a package to xith.tk?
|
on: 2006-02-12 22:41:13
|
Still cant add...  I'll make a complete example when i can commit properly, unitll that here is a quick incomplete example:
// create the render peer renderPeer = new RenderPeerImpl(); canvasPeerImpl = (CanvasPeerImpl) renderPeer.makeCanvas(frame, frame.getWidth(), frame.getHeight(), graphicsMode.getBitDepth(), graphicsDevice.getFullScreenWindow() != null); canvas3d = new Canvas3D(); canvas3d.set3DPeer(canvasPeer);
// create the virtual universe virtualUniverse = new VirtualUniverse();
// create a locale for the universe locale = new Locale(); virtualUniverse.addLocale(locale);
// create a view for the universe view = new MultiPassView(canvasPeer, locale);
virtualUniverse.addView(view);
// This far all looks pretty normal, but now comes the multiview setup
RenderPass background = new RenderPass(View.PERSPECTIVE_PROJECTION, 0.1f, 10.0f, new Background(new Color3f(0,0,0))); view.addRenderPass(background);
RenderPass scene = new RenderPass(View.PERSPECTIVE_PROJECTION, 0.1f, 3000.0f, new BranchGroup(), RenderPass.ALIGN_Z_CLOSEST); view.addRenderPass(scene);
RenderPass hud = new RenderPass(View.PARALLEL_PROJECTION, 0.1f, 100.0f, new Foreground(new BranchGroup(), View.VIEW_FIXED), RenderPass.ALIGN_Z_CLOSEST); view.addRenderPass("gui", hud); // <-- Note that we add a name for this pass so that we can refer to it easily later
// add the canvas to the view view.addCanvas3D(canvas3d);
// the render loop while(true) { // Any scenegraphg updates ... // for example: // Node gui = view.getRenderPass("gui").getNode(); // do something with the gui, update for example a FPS counter ... // render in multi pass view.renderAll(); }
|
|
|
|
|
13
|
Java Game APIs & Engines / Xith3D Forums / Re: about updateData
|
on: 2006-02-09 08:39:00
|
Im not sure about how the update should/could be made but have you tried the GeomDataInterface for setting the floats in the geometry. If you check this http://xith.org/tutes/GettingStarted/html/more_fun_with_textures.html tutorial you see how its done in that way. Its updating textureCoordinates, but im sure it works for all geometry data, at least all that i have tried ( coordinates, colors ). So i geuss that instead of doing this //point geom[TMPsurff].setCoordinate((ff*3)+2, new Point3f( ((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][0])))[0], ((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][0])))[1], ((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][0])))[2]));
geom[TMPsurff].setCoordinate((ff*3)+1,...
geom[TMPsurff].setCoordinate((ff*3)+0,... ...
you could try doing this //point GeomDataInterface coords = ((GeometryArray)geom[TMPsurff]).getCoordinateData(0); coords.setFloats((ff*3)+6, ((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][0])))[0], ((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][0])))[1], ((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][0])))[2]);
coords.setFloats((ff*3)+3,...
coords.setFloats((ff*3)+0,... ...
Hope it works 
|
|
|
|
|
14
|
Java Game APIs & Engines / Xith3D Forums / Re: Small Gui System (SGS for short) for Xith
|
on: 2006-02-07 00:20:39
|
Here is a screenshot, although its not intended to be pretty yet, you can see that it actually does work  There are some more stuff visible since from my last post; the button and a "panel" showing the wireframe of a shape from the scene selected by picking. [size=8pt] Edit: Dont pay attention to the FPS of 77. That has nothing to do with the gui but with the scene... It's ~750 without the scene and only the gui.[/size]
|
|
|
|
|
15
|
Java Game APIs & Engines / Xith3D Forums / Re: Small Gui System (SGS for short) for Xith
|
on: 2006-02-06 10:51:53
|
Some update from my progress: I have a very well working system for the basis of any kind of gui. I have made two abstract classes (component and container) that are capable of handling the positioning, sizing, and such. Infact they handle everything exept two things that they require a subclass to implement; first they need to provide a method returning a node that will be used to render the component, second they need to provide a geometryUpdater method that can handle updating the geometries in the node it provided. Both can be left empty, of course you wouldnt want to leave the first one empty, if you leave the latter empty then the component will not be able to for example resize should it be needed. In addition to those two forming the base of the system i have extended one container (UIPanel) and one component (FPSCounter). In the FPSCounter i used the DText2D class from the toolkit but i had to do a lot of customization so i might have to make a new one (maybe UIText) just for the gui. Last night i squeezed in one more thing; support for layout managers. I made the interface and implemented a swinglike GridLayout. Im still just beginning to think about the layoutmanagers so ill elaborate on that when i know im doing it the right way (maybe taking a peek at awt sources  ). Oh, i almost forgot; the gui is interactable by implementing a listener on your topmost gui container and then delivering events from your input layer. The methods return boolen so you can know weather the gui "consumed" the event or was it targeted at the scenegraph. The components are currently draggable and clickable, and some attributes can be defined to them that changes the behaviour they react to these events: they can be draggable or not draggable, they can cross the screen borders or not cross, they can dock to the screen borders or not dock, they can be auto resizing or not. Lastly, using the multipass rendering the screen scale is set relative to that of the screen pixel size (for a 800x600 window the screen scale is set to 400) in the pass when rendering the gui. This enables to position and size the components in pixel scale. This also enables the gui components to remain of constant pixel size even if the window is resized. I made the first prototype without this feature, it worked fine but i had to do a lot of extra computing to get the locations right and the components were also resized when the window resized. Maybe i will provide both options. Ill clean up the code, javadoc it and post some screens next. 
|
|
|
|
|
16
|
Java Game APIs & Engines / Xith3D Forums / Re: Small Gui System (SGS for short) for Xith
|
on: 2006-01-31 14:44:07
|
Whats your progress <MagicSpark.org [ BlueSky ]>? Communication has been almost zero between us during the project, and as a matter of fact all that there is is on this forum... I have progressed to a good start on my behalf and now i wonder weather to recheck and try to bring up some cooperation or should i just burn more gas and head on out finishing one GUI system by myself. I dont really mind working alone, infact i prefer now that since i feel that i have formed a good start by myself and feel confident in developing it alone and the way that i want it to be. Do you have any comments on this before i start my own thread about it?  Cheers,
|
|
|
|
|
17
|
Java Game APIs & Engines / Xith3D Forums / Re: rotation question
|
on: 2006-01-27 17:20:38
|
Dunno if this thread is still "alive" but there is a neat function i made for doing that. It rotates about a Node but you can easily extract the relevant parts of it to suit your needs. public BrachGroup rootBG; // <-- The root of your scenegraph...
/** * Rotates the camera about the selected node. * * If <code>node</code> is null then rotation will be performed about the VirtualWorld origo. * Direction of the rotation is taken from <code>x</code> and <code>y</code>. * * @param camera * @param node * @param x * @param y */ public void rotateCameraAboutNode(View camera, Node node, float x, float y) { Transform3D rotationLocation = new Transform3D(); Transform3D cameraLocation = new Transform3D(); Transform3D traslateLocation = new Transform3D(); Matrix3f rotation1 = new Matrix3f(); Matrix3f rotation2 = new Matrix3f(); // Determine camera location camera.getTransform(cameraLocation);
// Determine rotation point (node or vworld) if (node == null) { // for rotating about origo this works rootBG.getLocalToVworld(rotationLocation); // <-- rootBG is your scenegraph root
// rotate rotation1.setIdentity(); rotation2.rotX(y / 100.0f); rotation1.mul(rotation2); rotation2.rotY(x / 100.0f); rotation1.mul(rotation2); rotationLocation.setRotation(rotation1); rotationLocation.mul(cameraLocation); // set new camera transform cameraLocation.set(rotationLocation); } else { // for rotating about something else than origo we need slight // modifications to rotation code rootBG.getLocalToVworld(rotationLocation); node.getLocalToVworld(traslateLocation);
// translate to rotation point rotationLocation.mul(traslateLocation); // rotate rotation1.setIdentity(); rotation2.rotX(y / 100.0f); rotation1.mul(rotation2); rotation2.rotY(x / 100.0f); rotation1.mul(rotation2); rotation1.normalize(); rotationLocation.setRotation(rotation1); // translate away from rotation point traslateLocation.invert(); rotationLocation.mul(traslateLocation); rotationLocation.mul(cameraLocation); // set new camera transform cameraLocation.set(rotationLocation); }
// In Java3D the transform sometimes got non-congruent but that hasnt happened in Xith3D.. Is it normalized in the xith core  // the transform gets non-congruent so often that we might as well // normalize it every time // cameraLocation.normalize();
try { camera.setTransform(cameraLocation); } catch (Exception e) { e.printStackTrace(); } }
Note that this rotation will be applied as if the x and y parameters were in the node's coordinate space. I guess it would require a quaternion rotation to get it work right in all cases, but that is something that is still beyond my comprehension...
|
|
|
|
|
19
|
Java Game APIs & Engines / Xith3D Forums / Re: MultiPassView - Can I add it as a package to xith.tk?
|
on: 2006-01-26 10:40:15
|
As Yuri mentions in Issue #101, one thing you lose when using a Scenegraph is more direct control over the rendering, etc.
Depending on how you use your new MultiPassView class, you could have much more control over the render order which is nice.
I have been thinking about that too, and i came up with an idea which im not sure if it would work, but here it is: Make a Node (I used extending from Group) that doesnt get drawn when its getting processed during render time. Instead it executes a code snippet provided by the programmer. I overided the getChildren() method so that it calls its own run() method -- containing the code you wanna execute in the middle of render time -- then it returns a empty ArrayList. I havent really tested this since im not so good at immediate mode rendering ( which i think this could be used to ). I guess it could be used for just about anything you usually would like to do in the midst of the rendering. Does this sound like a awful hack? If it does, i better shut my mouth and keep the wild ones to my self... 
|
|
|
|
|
23
|
Java Game APIs & Engines / Xith3D Forums / Re: HOw to load a simple one group ASE file using getModel ()
|
on: 2006-01-26 06:12:45
|
I have not used the ASELoader but it looks like something is not initialized in the correct order. Try moving the line where you get the model a few lines down the code so it looks like this: try { af = new AseFile(); BufferedReader br = null;
try { br = new BufferedReader(new FileReader("tri_leged.ASE")); } catch (IOException e) { URL url = this.getClass().getClassLoader().getResource("tri_leged.ASE"); br = new BufferedReader(new InputStreamReader(url.openStream())); }
AseReader r = new AseReader(br); af.parse(r);
tri_legBG = af.getModel("tri_legged.ase"); }
Atleast it looks a bit more like it could work...  Then again i havent used the ASELoader so i dont know how its supposed to work.
|
|
|
|
|
25
|
Java Game APIs & Engines / Xith3D Forums / MultiPassView - Can I add it as a package to xith.tk?
|
on: 2006-01-25 01:25:01
|
I made these two classes for the multipass rendering that got spawned from this thread: http://www.java-gaming.org/forums/index.php?topic=10611.0MultiPassView.java1 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
| import java.util.ArrayList;
import com.xith3d.render.jogl.*; import com.xith3d.scenegraph.*;
public class MultiPassView extends View { private CanvasPeerImpl m_peerImpl; private ArrayList<RenderPass> m_renderPasses; private BranchGroup m_sceneGraph; public MultiPassView(CanvasPeerImpl peerImpl, Locale locale) { super(); m_peerImpl = peerImpl; m_renderPasses = new ArrayList<RenderPass>(128); m_sceneGraph = new BranchGroup(); m_sceneGraph.setPickable(true); locale.addBranchGraph(m_sceneGraph); } public void addRenderPass(RenderPass pass) { if (m_renderPasses.size() == 0) { m_renderPasses.add(pass); } else { switch (pass.getZAlignment()) { default: case RenderPass.ALIGN_Z_FAR : m_renderPasses.add(0, pass); break; case RenderPass.ALIGN_Z_CLOSE : m_renderPasses.add(m_renderPasses.size() - 1, pass); break; case RenderPass.ALIGN_Z_CLOSEST : m_renderPasses.add(pass); break; } }
m_sceneGraph.addChild(pass.getNode()); } public void removeRenderPass(RenderPass pass) { int index = m_renderPasses.indexOf(pass); m_renderPasses.set(index, null); m_sceneGraph.removeChild(pass.getNode()); } public void renderAll() { for (int i = 0; i < m_renderPasses.size(); i++) { RenderPass pass = m_renderPasses.get(i); pass.getNode().setRenderable(true);
if (pass.getProjectionPolicy() == View.PARALLEL_PROJECTION) { setProjectionPolicy(View.PARALLEL_PROJECTION); } else { setProjectionPolicy(View.PERSPECTIVE_PROJECTION); } if (i == 0) { m_peerImpl.setDisableClearBuffer(false); } else { m_peerImpl.setDisableClearBuffer(true); } if (i < m_renderPasses.size() - 1) { m_peerImpl.setForceNoSwap(true); } else { m_peerImpl.setForceNoSwap(false); } renderOnce(); pass.getNode().setRenderable(false); } } } |
and RenderPass.java1 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
| import com.xith3d.scenegraph.Node;
public class RenderPass {
public static final int ALIGN_Z_FAR = 0; public static final int ALIGN_Z_CLOSE = 1; public static final int ALIGN_Z_CLOSEST = 2;
private int m_projectionPolicy; private float m_nearClip; private float m_farClip; private Node m_node; private int m_zAlignment; public RenderPass(int projectionPolicy, float nearClip, float farClip, Node node) { this(projectionPolicy, nearClip, farClip, node, ALIGN_Z_CLOSE); } public RenderPass(int projectionPolicy, float nearClip, float farClip, Node node, int zAlignment) { m_projectionPolicy = projectionPolicy; m_nearClip = nearClip; m_farClip = farClip; m_node = node; m_zAlignment = zAlignment; m_node.setRenderable(false); } public int getZAlignment() { return m_zAlignment; }
public void setZAlignment(int zAlignment) { m_zAlignment = zAlignment; }
public float getFarClip() { return m_farClip; } public void setFarClip(float clip) { m_farClip = clip; } public float getNearClip() { return m_nearClip; } public void setNearClip(float clip) { m_nearClip = clip; } public Node getNode() { return m_node; } public void setNode(Node node) { m_node = node; } public int getProjectionPolicy() { return m_projectionPolicy; } public void setProjectionPolicy(int policy) { m_projectionPolicy = policy; } } |
Now can I add them as a new package to the toolkit? I'll provide good javadoc comments and make a test program as required. 
|
|
|
|
|
28
|
Java Game APIs & Engines / Xith3D Forums / Re: Xith toolkit role
|
on: 2006-01-25 00:11:21
|
Well I'm certainly still a nOOb around here but still I dare to say that the stuff in xith-tk should not be depending on any extra libraries/APIs. In my opinion they should be allowed only to depend on other xith-tk packages and the standard Java API (like the swingui for example). Ofcourse also jogl and lwjgl as xith itself depends on them!  Im not sure if this is what you asked, but thats my opinion about what should go there and what not...
|
|
|
|
|
30
|
Java Game APIs & Engines / Xith3D Forums / Re: Loading Terragen OBJ
|
on: 2006-01-24 11:33:00
|
Obviously you're parsing an HTTP-header... why?
Please, download the obj and the mtl to the hard disk. Verify the obj don“t have HTTP-header inserted by the web server. Ok, so thats the problem, ill remove the header and test again 
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|