Show Posts
|
|
Pages: [1] 2
|
|
1
|
Game Development / Newbie & Debugging Questions / Re: KeyListener on an Array (2D Dungeon Crawler)
|
on: 2013-05-17 12:21:39
|
Try to use the recommendations from here: Note:
To fire keyboard events, a component must have the keyboard focus.
To make a component get the keyboard focus, follow these steps:
Make sure the component's isFocusable method returns true. This state allows the component to receive the focus. For example, you can enable keyboard focus for a JLabel component by calling the setFocusable(true) method on the label. Make sure the component requests the focus when appropriate. For custom components, implement a mouse listener that calls the requestFocusInWindow method when the component is clicked.
|
|
|
|
|
11
|
Game Development / Newbie & Debugging Questions / Re: Random Spazzes from the player.
|
on: 2013-01-24 07:23:58
|
These lines (#91-94, method move) look suspiciously: 1 2 3 4
| } else if (grid[temp.x][temp.y].state == "moveable") { Location temp2 = temp.translate(i, j); if (grid[temp2.x][temp2.y].state != "moveable" && grid[temp2.x][temp2.y].state != "solid") { |
Strings should be tested on equality via 'equals method.
|
|
|
|
|
13
|
Game Development / Game Mechanics / Re: Euler angles to quaternion: Is this correct?
|
on: 2012-12-18 08:33:32
|
This should work: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public static Quaternion4f eulerToQuaternion( float eulerX, float eulerY, float eulerZ ) { double sx = Math.sin( eulerX / 2 ); double sy = Math.sin( eulerY / 2 ); double sz = Math.sin( eulerZ / 2 ); double cx = Math.cos( eulerX / 2 ); double cy = Math.cos( eulerY / 2 ); double cz = Math.cos( eulerZ / 2 ); double cycz = cy * cz; double sysz = sy * sz; double d = cycz * cx - sysz * sx; double a = cycz * sx + sysz * cx; double b = sy * cz * cx + cy * sz * sx; double c = cy * sz * cx - sy * cz * sx;
Quaternion4f q = new Quaternion4f( ( float ) a, ( float ) b, ( float ) c, ( float ) d ); q.normalize();
return ( q ); } |
|
|
|
|
|
23
|
Java Game APIs & Engines / OpenGL Development / Re: Quat4f and rotation around local axis
|
on: 2012-03-16 19:24:39
|
Try to apply 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
| public static void mul(Vector4f q, Vector3f vCoord, Vector3f scale, Vector3f result) { Matrix3f m1 = new Matrix3f();
setFromQuat(q.getX(), q.getY(), q.getZ(), q.getW(), m1);
Matrix3f tmp = new Matrix3f();
tmp.setIdentity(); tmp.m00(scale.getX()); tmp.m11(scale.getY()); tmp.m22(scale.getZ());
m1.mul(tmp);
transform(m1, vCoord, result); }
private static void setFromQuat(float a, float b, float c, float d, Matrix3f m) { final float n = a * a + b * b + c * c + d * d; final float s = (n > 0.0f) ? (2.0f / n) : 0.0f;
final float xs = a * s, ys = b * s, zs = c * s; final float wx = d * xs, wy = d * ys, wz = d * zs; final float xx = a * xs, xy = a * ys, xz = a * zs; final float yy = b * ys, yz = b * zs, zz = c * zs;
m.m00(1.0f - (yy + zz)); m.m01(xy - wz); m.m02(xz + wy); m.m10(xy + wz); m.m11(1.0f - (xx + zz)); m.m12(yz - wx); m.m20(xz - wy); m.m21(yz + wx); m.m22(1.0f - (xx + yy)); }
private static void transform(Matrix3f m, Vector3f t3f, Vector3f result) { result.set(m.m00() * t3f.getX() + m.m01() * t3f.getY() + m.m02() * t3f.getZ(), m.m10() * t3f.getX() + m.m11() * t3f.getY() + m.m12() * t3f.getZ(), m.m20() * t3f.getX() + m.m21() * t3f.getY() + m.m22() * t3f.getZ() ); } |
It's a draft solution. Unfortunately, I can't test it now, so hopefully it will work with a little changes.
|
|
|
|
|
28
|
Game Development / Newbie & Debugging Questions / Re: Organizing ArrayLists for item lists?
|
on: 2012-03-07 08:30:06
|
Another way. If you can't have multiple stacks you can have a HashSet<Item, Integer> and use that to manage your item list, instead of an ArrayList.
A hashset sounds good. Thanks! If I need more help, I'll let you guys know! EDIT! So I messed with hashsets, but I have no idea how to get data from it. lol. Can someone explain? I add in the elements, then I can check if an element is there...but then what? it's meant HashMap<Item, Integer>. You can put into and get data from it. If order of insertion is important you may use LinkedHashMap.
|
|
|
|
|
29
|
Game Development / Newbie & Debugging Questions / Re: Need help with quanterion (cube rotate)
|
on: 2012-03-05 13:29:05
|
Here is some code. Hope it will work with minor changes. 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
| ...
private void update(){ roll(); for(int i = 0;i<array.length;i+=3) { change = new Vector3f(array[i], array[i+1], array[i+2]); MathUtils.transform(roll, change, change); array[i] = change.x; array[i+1] = change.y; array[i+2] = change.z; } vertexData.put(array); vertexData.flip(); }
...
public class MathUtils { public static Vector3f transform( Quaternion q, Vector3f vector, Vector3f result ) { Quaternion inv = new Quaternion(-q.getX(), -q.getY(), -q.getZ(), q.getW() ); inv.normalize(); Quaternion tmp = new Quaternion(); mul(q, vector, tmp ); tmp.mul( inv ); result.set( tmp.getX(), tmp.getY(), tmp.getZ() ); return ( result ); }
public static Quaternion mul(Quaternion q, Vector3f t, Quaternion out ) { out.set( ( q.getW() * t.getX() ) + ( q.getY() * t.getZ() ) - ( q.getZ() * t.getY() ), ( q.getW() * t.getY() ) + ( q.getZ() * t.getX() ) - ( q.getX() * t.getZ() ), ( q.getW() * t.getZ() ) + ( q.getX() * t.getY() ) - ( q.getY() * t.getX() ), -( q.getX() * t.getX() ) - ( q.getY() * t.getY() ) - ( q.getZ() * t.getZ() ) ); return ( out ); } } |
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|