Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2 3 ... 12
1  Java Game APIs & Engines / OpenGL Development / Re: [batching] How to transform drawing primitives on: 2014-09-26 19:47:02
The problem with batching is that you can't really batch together meshes with different transforms because you have to modify the modelview matrix between draws, which is not batching. So if you want to do something like that then the best option really depends on what gives the best performance and is easiest to implement.

You can either compute the transforms cpu side as you have said. Or it might give better performance to give up on batching all together. Ultimately batching is a performance improvement and if your requirements mean that it isn't increasing performance then what is the point.
2  Game Development / Newbie & Debugging Questions / Re: Collada format interleaved index buffer? on: 2014-09-26 19:43:53
Ah sorry. Haven't used Blender in a while, turns out it was the Wavefront export that had those options. Well the other thing is that in the asset node in the COLLADA document, you will find an element called <up-axis> which, exporting from Blender, has the value "Z_UP". You can read this element to work out how to transform the data to get it into the y-up format.

And I would recommend transforming the vertices as you parse them. As @basil_ says, best to get it in the format you like and are used to. Otherwise you are just adding another layer of complexity which is wholly unnecessary and can only lead to bad things.
3  Game Development / Newbie & Debugging Questions / Re: LWJGL - 2D Image not rendering right on: 2014-09-26 19:22:28
I've got two issues to be starting you off for.

1) You should be calling glTexCoordf() before the corresponding glVertex() call. When you call glVertex() it sends the currently set tex coords as the ones for the vertex it creates if that makes sense. The same goes for every similar call like glColor, glNormal, glFogCoords everything. And if you are using custom attributes then index 0 takes the place of glVertex() and works the same way.

2) OpenGL used to only work with power of two dimension textures. Nowadays (since OpenGL 3.0 I think) implementations are required to support them but Slick2D still works with pot textures. So it pads out non-pot textures to make them up to pot textures. Fine except it leaves you with black borders like the ones you have.

Fix these two things and see how many of your problems go away.
4  Game Development / Newbie & Debugging Questions / Re: Using a FrameBuffer object on: 2014-09-23 09:44:05
LWJGL specific, good FBO tutorial:

http://lwjgl.org/wiki/index.php?title=Using_Frame_Buffer_Objects_(FBO)

LWJGL example of render to texture:

http://lwjgl.org/wiki/index.php?title=Render_to_Texture_with_Frame_Buffer_Objects_(FBO)
5  Game Development / Newbie & Debugging Questions / Re: Collada format interleaved index buffer? on: 2014-09-23 09:41:48
Two things to think about.

1) By default, Blender exports with a z-up system whereas chances are you want a y-up system. In the export screen in Blender, look over the options in the bottom right hand corner.

2) With COLLADA you cannot just look at a single isolated element. This <float-array> will be accessed from an <input> (well actually a <vertices> which is referenced from a <polylist> (or similar) inside a <mesh> inside a <geometry> referenced by an <instance-geometry> inside a tree of <node>s inside a <visual-scene> referenced by an <instance-visual-scene> inside the <scene> (That was from memory and some of it might be wrong). And every step along the way there can be stuff that will change the way it works. I expect that one or more of the <node>s of the scenegraph contains a transform which is distorting your quad because you are ignoring it.

So COLLADA isn't that complex but there is a lot of work to do to make a full parser. If you are going to make a fully functional parser, then you have to start in the <scene> node and follow the references all the way down to the actual data collecting all the information along the way. It is no simple matter.

However there is (I believe) another option in the Blender export screen that lets you pre-apply any kind of transform to the geometry before exporting. I believe this will mean that any transforms will be applied to the geometry rather than defined in the scenegraph.

Hope this helps, Quew8
6  Game Development / Newbie & Debugging Questions / Re: Is it Possible to use Java and send sounds through the microphone? on: 2014-09-11 09:33:34
I don't know how but, if there is a way I'd expect you to find it in one of these websites:

http://docs.oracle.com/javase/tutorial/sound/sampled-overview.html
http://www.jsresources.org/index.html
7  Game Development / Game Mechanics / Re: Rendering pixel data from array in lwjgl on: 2014-09-02 18:31:49
Textures. You have an array of rgb values, also called an image. So you can wrap up the image in an OpenGL texture and render that. You can update individual pixels in the texture with glTexSubImage2D(): http://www.opengl.org/sdk/docs/man2/xhtml/glTexSubImage2D.xml.

Depending on how much this minimap is being updated, you might get more performance out of using glDrawPixels(): http://www.opengl.org/sdk/docs/man2/xhtml/glDrawPixels.xml to render those pixels directly. But I would always go with the texture option just for ease of use and simplicity.
8  Discussions / General Discussions / Re: Performance Test for the Voxel Thing on: 2014-08-30 13:18:57
Smooth 60 fps on
Windows 7 32 bit
4 GB RAM
Intel core i3-2100 @ 3.1 GHz
ATI Radeon HD 2400

So I don't think you have a performance issue.

Also ditto on @PandaMoniumHUN's bug if it matters.
9  Discussions / Miscellaneous Topics / Re: Music in games? on: 2014-08-30 09:51:13
Well I have a friend who is very capable with music production and has made and does make the kind of music I think you are looking for. He would I'm sure be happy to work on the basis of credit given and links provided. If you're interested, pm me and I can get in touch.
10  Java Game APIs & Engines / Android / Re: Hardware survey on: 2014-08-27 09:17:47
I think the point really is in comparing Android to ios. I find that people coming from an IPhone to a comparable Android phone are always complaining about how quickly their apps run. Since the phone's have fairly identical specs and the actual OSs run without a hiccup, I've always concluded that it is because a lot of Android apps cannot be optimized to the same degree as their equivalents on ios.

So yes we can deal with it, doesn't make it the best outcome (purely in terms of final product, I think the pros outweigh the cons in this case).
11  Game Development / Newbie & Debugging Questions / Re: GLSL Lighting a 3D box on: 2014-08-22 10:19:01
OK, here is your problem. Your shader is designed to work for directional lights. A directional light is one considered to be infinitely far away which has two effects: 1) It (can be considered to have) has a uniform intensity. 2) The rays of light (can be considered to be) are parallel. An example of a real world directional light is the sun. So obviously a directional light doesn't really have a position, only a direction.

Now in fixed function pipeline OpenGL lighting, the direction of a directional light was set with the light's position. I don't know why this is, probably to ease the implementation, but whoever wrote your shader has emulated this behaviour, getting the light's direction from it's position. Now you setting the position to (0, 0, 0) essentially kills the light. But that isn't your only problem, hence why setting it to (10E3, 10E3, 10E3) didn't work either. And it is capital 'E' btw. Lower case e is natural logarithm base.

The dot product only works in the way you are using it when both vectors are normalized. (10E3, 10E3, 10E3) is obviously not normalized giving you undefined results. Either normalize it in the shader or better yet normalize it cpu side before setting it.

Two last things. Since you are using your own shaders, enabling GL_LIGHTING and GL_LIGHT0 does absolutely nothing. And if you want to read about how OpenGL used to do these lighting calculations: http://www.glprogramming.com/red/chapter05.html. It is a good read for explaining lighting things.

Hope I've helped.
12  Java Game APIs & Engines / OpenGL Development / Re: Applying transformations to vertices on: 2014-08-21 22:14:45
Specifications are the programmers holy texts. Well if your tutorial explains the maths, I'll sure as hell read it.
13  Game Development / Newbie & Debugging Questions / Re: GLSL Lighting a 3D box on: 2014-08-21 18:58:53
I think this is more of a problem with how you have set up the light rather than the shader.
14  Java Game APIs & Engines / OpenGL Development / Re: Applying transformations to vertices on: 2014-08-21 18:53:23
I'm afraid it is not obvious. I tried to extract the right numbers from a file to test it out and that came out as a no, but I am almost certain that I didn't get it right. Sorry. What you're saying definitely makes a lot of sense in any case.

COLLADA files are XML based and I am told that technically makes them "human readable." But I think that just means text based rather than pure data. It is certainly possible to follow them once you know what they are about but data is essentially split up into several great long lists of numbers and you have to jump to the right index in that list the whole time. The format is also a bit "all over the place" to allow for great flexibility. Fine for a computer, bit confusing for a human. So in short: us humans can read them but, only with experience and then only with difficulty. Quicker to write a program to read them for you frankly even if it's just one or two models.
15  Java Game APIs & Engines / OpenGL Development / Re: Applying transformations to vertices on: 2014-08-20 10:31:31
I'm afraid I cannot be much help here. I create my models in Blender and export them as COLLADA (.dae) files. Parsing through them gives you the bindShapeMatrix and invBindMatrices.

(What follows is guess work)
I've just looked through the COLLADA files for a couple of my models and in all of them the bindShapeMatrix was the identity matrix. Now these are models with a very simple rigging (it was more to test my COLLADA parser than anything else) so perhaps the bindShapeMatrix is only necessary for more complex skeletons? But the invBindMatrices were not identity matrices which leads me to conclude that your original idea which I shot down in flames is probably mostly right. So perhaps the invBindMatrix is the combination of the joint's default transform with the inverse of the bindShapeMatrix and so when the BSM is the identity matrix, the IBM is just the joint's default transform.

Pure speculation, but speculation that makes sense to me.
16  Java Game APIs & Engines / OpenGL Development / Re: Applying transformations to vertices on: 2014-08-19 16:34:25
am I correct in assuming that the mat4 jointMatrices are the current matrices for each joint? (not the default, but their transforms in the current frame?

Yes. The jointMatrix is the joint's transformation in the current frame.

What is the bindShapeMatrix? is this the current joint's default pose(TPose)?
...
If my assumptions are correct what are the invBindMatrices? are those the default pose matrices as well?

So first off, I don't entirely understand the maths behind skeletal animation (and I don't know what TPose is) but I will share what understanding I do have. Essentially, the joint's transformation is not calculated in object space but in joint space. Joint space is a unique space for each skeleton. The bindShapeMatrix takes the vertex into joint space, where you apply the joint's transform, then the invBindMatrix takes the vertex back into object space. Why the invBindMatrix is unique to each joint, I could not tell you.

That is my understanding - incomplete or flawed as it may be. I am ashamed to say that this is one of the (few) things where I succeeded in implementing something and therefore did not question the maths behind it.

Again, I hope I have been of some help.

Quew8
17  Java Game APIs & Engines / OpenGL Development / Re: Applying transformations to vertices on: 2014-08-16 09:19:18
Well perhaps I can help with that. I'll post a few pertinent sections of my own skeletal animation code.

The vertex program. Or at least a section of it. Because of my in-app shader build process, I don't have direct access to the entire shader.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
attribute vec4 inPos;
attribute vec4 jointWeights;
attribute ivec4 jointIndices;
uniform mat4 bindShapeMatrix;
uniform mat4[~nJointMatrices~] jointMatrices;
uniform mat4[~nJointMatrices~] invBindMatrices;

void main() {
    vec4 vbsm = inPos * bindShapeMatrix;
   
    outPos =
        ( ( vbsm * invBindMatrices[jointIndices[0]] * jointMatrices[jointIndices[0]] ) * jointWeights[0] ) +
        ( ( vbsm * invBindMatrices[jointIndices[1]] * jointMatrices[jointIndices[1]] ) * jointWeights[1] ) +
        ( ( vbsm * invBindMatrices[jointIndices[2]] * jointMatrices[jointIndices[2]] ) * jointWeights[2] ) +
        ( ( vbsm * invBindMatrices[jointIndices[3]] * jointMatrices[jointIndices[3]] ) * jointWeights[3] );
}

Where "~nJointMatrices~" should take the value of the maximum number of joints a model of yours has.

The onPreRendering() method from my SkeletalRenderMode which is called before a batch of skeletal renders. (VertexData.vertexAttribPointer()) mirrors the OpenGL function in parameters)
1  
2  
3  
4  
5  
6  
7  
8  
public void onPreRendering(VertexData vd) {
    shaderProgram.use();
    vd.vertexAttribPointer(0, 3, GL_FLOAT, false, 52, 0); //inPos
   vd.vertexAttribPointer(1, 3, GL_FLOAT, false, 52, 12); //Normal Vector - not shown in shader
   vd.vertexAttribPointer(2, 2, GL_FLOAT, false, 52, 24); //Tex Coords - not shown in shader
   vd.vertexAttribPointer(3, 4, GL_BYTE, false, 52, 36); //jointIndices
   vd.vertexAttribPointer(4, 4, GL_FLOAT, false, 52, 50); //jointWeights
}


The onPreDraw() from same. This is called before each individual skeletal model's render. (The value of bindShapeMatrixVar, invBindShapeMatrix and jointMatrix in this instance would be "bindShapeMatrix", "invBindMatrices", "jointMatrices". The variable names in the shader)
1  
2  
3  
public void onPreDraw(Skeleton data) {
    data.uploadSkeleton(shaderProgram.getId(), bindShapeMatrixVar, invBindShapeMatrix, jointMatrix);
}


The uploadSkeleton() method from Skeleton. (matrixBuffer is just a FloatBuffer that is reused for uploading skeletal matrices)
1  
2  
3  
4  
5  
6  
7  
public void uploadSkeleton(int programId, String bsmVar, String ibmVar, String jmVar) {
    bindShapeMatrix.putIn(matrixBuffer);
    ShaderUtils.setUniformMatrix(programId, bsmVar, matrixBuffer);
    for(int i = 0; i < joints.length; i++) {
        joints[i].uploadJoint(programId, ibmVar, jmVar, matrixBuffer);
    }
}


And the uploadJoint() methods from Joint. (the value of indexString is "[index]" where "index" is the flattened index of this joint)
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
public void uploadJoint(int programId, String ibmVar, String jmVar, Matrix parentWJM, FloatBuffer matrixBuffer) {
    Matrix.times(tempMatrix, parentWJM, jointMatrix);
    tempMatrix.putIn(matrixBuffer);
    ShaderUtils.setUniformMatrix(programId, jmVar + indexString, matrixBuffer);
    invBindMatrix.putIn(matrixBuffer);
    ShaderUtils.setUniformMatrix(programId, ibmVar + indexString, matrixBuffer);
    for(int i = 0; i < children.length; i++) {
        children[i].uploadJoint(programId, ibmVar, jmVar, tempMatrix, matrixBuffer);
    }
}
   
public void uploadJoint(int programId, String ibmVar, String jmVar, FloatBuffer matrixBuffer) {
    uploadJoint(programId, ibmVar, jmVar, new Matrix(), matrixBuffer);
}


The are a couple of caveats to this code. Firstly - there are a maximum of four joints that any vertex can be influenced by. My models are simple so this is fine for me, if you need more then you can move to arrays rather than vec4s.  Secondly - there is a fixed size to the joint matrix arrays. This could be fine, or it could be a waste of space. Variable arrays can be achieved by using textures to send data, or you could be clever and send the matrices of several small models in one go. I'm sure there are more caveats but it has been a while since I wrote this so I forget.

My apologies for the somewhat convoluted nature of this code - I have a framework I have to conform to - but I hope it should serve as a concept example.
18  Java Game APIs & Engines / OpenGL Development / Re: Applying transformations to vertices on: 2014-08-15 13:00:41
Well firstly, the absolute simplest and best way of doing this as you have described it is (as with most things) to use shaders. You pass a uniform array of joint matrices and attribute joint weights for each vertex. The shader is actually pretty simple.

But doing it your way, also possible. You can transform the vertices cpu side and put them in the cpu pre-transformed. I would counsel against making the matrix in OpenGL and retrieving it to do the transformations. If you are going to do things on the cpu, do it all on the cpu. Or rather better "cpu -> gpu" than "cpu -> gpu -> cpu -> gpu" because in these sort of situations, "->" ie transferring data to (and even more so) from OpenGL is actually the slowest part by quite a bit despite the gpu being able to do processes faster.

Doing matrix calculation cpu side also allows the possibility of caching animation matrices which depending on animation and model size/detail can be the better option.

I don't recognize the library you are using but certainly LWJGL has it's own Vector and Matrix classes which are fully capable of doing these operations and I expect others such as LibGDX and JOGL are similar; so doing the calculations yourself isn't even that complex.
19  Java Game APIs & Engines / OpenGL Development / Re: interleaved VBO and textures (Solved) on: 2014-08-15 11:31:36
That's looking very pretty. It's nice to know that I am actually helping projects along.
20  Games Center / WIP games, tools & toy projects / Re: I like smell of polygons in the morning on: 2014-08-12 11:07:07
It's elegant. But I kind of feel there should be a step 6 of rendering a navigable, 3D view of the terrain you create, otherwise what is the point of working out all those oh so pretty polygons. Also some of them look a little odd; I think I see some edges crossing terrain borders and maybe a couple of t-junctions (I presume you are meaning to avoid them). Looking at it in 3D is the only way to be sure they are working well I think.
21  Game Development / Newbie & Debugging Questions / Re: Should I move to LWJGL on: 2014-08-04 14:51:18
It's easier to use if you want to do anything remotely fancy but look what the OP is creating.

Well the example is something the OP created. The reason for the post is because he wants to move beyond that. And really you can do anything 2D in Java2D but you have to move on at some point, why not when you aren't too ambitious to overreach yourself in OpenGL straight away. I really don't think more experience with Java2D helps with learning OpenGL.

In terms of LibGDX (used as a general graphics abstraction library) vs LWJGL (used as a general OpenGL binding/windowing library), and this is a general statement not necessarily applicable here: it's all very well saying that using LibGDX makes your life easier because you don't have to cope with learning OpenGL or writing boilerplate code, but someone has to learn OpenGL and someone has to write the boilerplate code. And if you don't then you will never know what you are missing.
22  Game Development / Newbie & Debugging Questions / Re: OpenGL Fragments on: 2014-07-28 19:53:58
The min function in GLSL works component wise for any type of vector (except booleans). So:

1  
gl_FragColor = min(existing, calculated);


will result in the darkest colour (Manhattan distance style, not absolute magnitude).
23  Game Development / Newbie & Debugging Questions / Re: Using the Java ServiceLoader to load from a Jar inside another Jar. on: 2014-07-24 16:31:07
For future reference, my solution to this was not to do it. I now load my services' jars as external resources. This way makes more sense anyway and was always going to be the final method. The only reason I didn't do it in the first place was to save me writing external resource loading into my resource loading system then and there.

But the question still stands, as a query of interest and potentially to help out others in the future, if someone does know the answer.
24  Discussions / General Discussions / Re: Java Swing GUI Creator on: 2014-07-17 19:44:55
I agree the 3D is fairly poor. It's still very new and I don't doubt it will be improved in time. I was just trying to give an example of the extra features in JavaFX. I also agree that the charting API is a better example.
25  Discussions / General Discussions / Re: Java Swing GUI Creator on: 2014-07-17 09:53:48
JavaFX isn't the panacea even though now what you can do with Swing has become doable with JavaFX but there is not yet any dialog API.

Originally I thought this was a major problem, but then I threw together my own dialog api in a few minutes. It's not the most feature heavy thing (basically just takes a scene and puts it into a dialog box) but it was the simplest thing in the world to make and it works perfectly. And then there are some really good dialog libraries out there.

But as I said in my last post, the great advantage of JavaFX over Swing (for me) is that it is just so much nicer to work with. The API is similar enough to Swing that it is easy to pick up, but with far greater usability and a whole load of features stuck in. JavaFX even has 3D graphics and I'm not talking about beveled buttons.

But I digress.
26  Game Development / Newbie & Debugging Questions / Using the Java ServiceLoader to load from a Jar inside another Jar. on: 2014-07-16 18:43:38
I am using the java.util.ServiceLoader to load plugins/extensions (call them what you want) from a series of Jar files which I store as resources inside my main executable Jar file. I generate an array of URLs which list the locations of the Jar files. I create an URLClassLoader and create a ServiceLoader around this class loader, and then the ServiceLoader does its stuff. Running this from my IDE (NetBeans if it makes a difference) but as soon as I build the project, the ServiceLoader fails to recognize any implementations.

To give an example (they don't add any info but perhaps state it more clearly than I did), here is the log output after running from NetBeans:
Quote
d | PRE_INIT | URL passed to URLClassLoader[0] = file:/.../ARBShaderServiceImpl.jar
d | PRE_INIT | URL passed to URLClassLoader[1] = file:/.../DefaultFramebufferServiceImpl.jar
d | PRE_INIT | URL passed to URLClassLoader[2] = file:/.../DefaultShaderServiceImpl.jar
d | PRE_INIT | URL passed to URLClassLoader[3] = file:/.../EXTFramebufferServiceImpl.jar
v | PRE_INIT | Loader: java.util.ServiceLoader[com.quew8.gutils.desktop.opengl.services.ShaderServiceImpl]
v | PRE_INIT | Loader Found: class com.quew8.gutils.desktop.opengl.services.arb.ARBShaderServiceImpl
v | PRE_INIT | Loader Found: class com.quew8.gutils.desktop.opengl.services.def.DefaultShaderServiceImpl
v | PRE_INIT | Looking At: class com.quew8.gutils.desktop.opengl.services.arb.ARBShaderServiceImpl
v | PRE_INIT |     Is Applicable: true
v | PRE_INIT |     Precedence: 2
v | PRE_INIT |     Setting As Top Implementation
v | PRE_INIT | Looking At: class com.quew8.gutils.desktop.opengl.services.def.DefaultShaderServiceImpl
v | PRE_INIT |     Is Applicable: true
v | PRE_INIT |     Precedence: 1
v | PRE_INIT |     Setting As Top Implementation
v | PRE_INIT | Looking At: class com.quew8.gutils.desktop.opengl.services.NoShaderServiceImpl
v | PRE_INIT |     Is Applicable: true
v | PRE_INIT |     Precedence: -1

And then from running it from the Jar.

Quote
v | PRE_INIT | URL passed to URLClassLoader[0] = jar:file:/.../StellarColony.jar!/.../ARBShaderServiceImpl.jar
v | PRE_INIT | URL passed to URLClassLoader[1] = jar:file:/.../StellarColony.jar!/.../DefaultFramebufferServiceImpl.jar
v | PRE_INIT | URL passed to URLClassLoader[2] = jar:file:/.../StellarColony.jar!/.../DefaultShaderServiceImpl.jar
v | PRE_INIT | URL passed to URLClassLoader[3] = jar:file:/.../StellarColony.jar!/.../EXTFramebufferServiceImpl.jar
v | PRE_INIT | Loader: java.util.ServiceLoader[com.quew8.gutils.desktop.opengl.services.ShaderServiceImpl]
v | PRE_INIT | Looking At: class com.quew8.gutils.desktop.opengl.services.NoShaderServiceImpl
v | PRE_INIT |     Is Applicable: true
v | PRE_INIT |     Precedence: -1
v | PRE_INIT |     Setting As Top Implementation

Obviously the difference between these is the URLs and the fact that the loader doesn't find any services (the NoShaderServiceImpl is loaded outside of the ServiceLoader in my own code)

So my question is: has anyone else experienced this and can anyone shed some light on why it is happening?

Thank you in advance.
27  Discussions / General Discussions / Re: Java Swing GUI Creator on: 2014-07-16 13:40:46
JavaFX I think is a pretty decent way to go. Tons of features, a lot of which are purely "make the coders life easier" features like the whole properties library. But the important thing here is that it has an XML format called FXML like Android's, with Java controllers (but you can access elements straight from in-class fields you define rather than looking them up from ids, so one up on Android) and there is a very decent FXML editor (coded with JavaFX of course) which I think is easier to use than any other GUI editor I've used.

I'm not particularly sure why JavaFX is having such a slow adoption but if there is a reason then that reason is the downside.
28  Game Development / Game Mechanics / Re: 2D Rigid Body Rope Physics on: 2014-07-15 20:26:57
There certainly is.

vx = w * cos(theta)
vy = -w * sin(theta)


Where w is angular velocity and v is tangential velocity. You may notice that position and angle share the same relationship as angular velocity and velocity. Just a little aside because it makes me smile to see maths work.
29  Game Development / Game Mechanics / Re: 2D Rigid Body Rope Physics on: 2014-07-13 12:11:01
OK, I just felt like trying this out for myself; really there is something very satisfying at watching a ball swing back and forth on a string. So here: http://pastebin.java-gaming.org/d0bb2981a0e14 (I don't know how to embed JGO pastebins). I made it using LWJGL so if you don't use LWJGL, then you won't have the libraries and natives to run it and you probably won't understand the rendering parts of it. But the simulation bits should still help.

Now as soon as I had it, I realized that the thing just kept swinging infinitely so I had to add in a little (very) simplistic friction. That is the " - ( av * FRICTION_COEFFICIENT / mass )" term in the SwingingBody.update() method. That friction bit is the only reason the mass of the body affects the motion.

One last thing - it is very crude in places. I was trying to do it quickly, and shortly whilst making it self-contained. Sorry.
30  Game Development / Game Mechanics / Re: 2D Rigid Body Rope Physics on: 2014-07-13 10:48:02
Sure, so you use angular acceleration and velocity to calculate the angle as in my code snippet, then you can use trig to work out the actual position.

Essentially

px = cx + r * cos(theta)
py = cy - r * sin(theta)

Where p is the position of the swinging body, c is the centre of the swing where the rope is attached, r is the length of the rope and theta is the angle.

Edit: Fixed, because stuff falls down, not up.
Pages: [1] 2 3 ... 12
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (40 views)
2014-09-24 16:13:29

Pippogeek (31 views)
2014-09-24 16:12:22

Pippogeek (21 views)
2014-09-24 16:12:06

Grunnt (47 views)
2014-09-23 14:38:19

radar3301 (29 views)
2014-09-21 23:33:17

BurntPizza (65 views)
2014-09-21 02:42:18

BurntPizza (37 views)
2014-09-21 01:30:30

moogie (43 views)
2014-09-21 00:26:15

UprightPath (53 views)
2014-09-20 20:14:06

BurntPizza (55 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!