Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
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 ... 5
1  Discussions / General Discussions / Re: Building a free flying 3D Quaternion camera on: 2014-08-29 16:50:44
i've removed my movement code so as to return to the "most working" state as i ask for suggestions.

thanks!
J.
2  Discussions / General Discussions / Re: Building a free flying 3D Quaternion camera on: 2014-08-29 16:49:27
well im still struggling on this..

so here is the full class..

What works
  • Rotate the camera pitch (w/s) yaw (a/s) roll (q/e)

what doesnt work:
  • Movement: attempting to following the examples provide resulted in a axis getting locked (stopped moving with the rotations) or the forward direction ignoring an axis rotation

Since quaternions are still relatively new to me i'm feeling like im just missing that "ahah! " moment..

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  
package com.windpoweredgames.wind.camera;

import org.lwjgl.input.Keyboard;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Quaternion;
import org.lwjgl.util.vector.Vector3f;
import org.lwjgl.util.vector.Vector4f;

import com.windpoweredgames.wind.GameEngine;
import com.windpoweredgames.wind.input.InputManager;
import com.windpoweredgames.wind.input.InputProcessor;
import com.windpoweredgames.wind.util.MatrixUtil;
import com.windpoweredgames.wind.util.VectorUtil;


public class DefaultCamera extends AbstractCamera implements InputProcessor{
   
   private float speed = 0f; // 1 unit per sec
  private float distRate = 1f/1000f;
   private float rotRate = 1f/1000f;
   
   private Quaternion camRotations = new Quaternion();
   
   private Vector3f pos =       new Vector3f(0,0,0);
   private Vector3f up =       new Vector3f(0,1,0);
   private Vector3f forward =   new Vector3f(0,0,-1);
   private Vector3f right =    new Vector3f(1,0,0);
   
   
   
   public void setActive(boolean active) {
      super.setActive(active);
      if(active){
         InputManager.getInstance().add(this);
      }else{
         InputManager.getInstance().remove(this);
      }
   }
   
   public void setSpeed(float speed) {
         this.speed = speed;
   }
   
   public float getSpeed() {
      return speed;
   }
   
   
   
   
   
   private float getTimeDependantDistance(){
      float deltaTime = (float)GameEngine.getInstance().getDeltaTime();
      float dist = speed * (distRate * deltaTime);
      return dist;
   }
   
   private float getTimeDependantRotation(){
      float deltaTime = (float)GameEngine.getInstance().getDeltaTime();
      float rot =  (rotRate * deltaTime);
      return rot;
   }
   
   
   
   
   public Matrix4f getCameraPositionMatrix() {
      Matrix4f result = new Matrix4f();
      Matrix4f rotMat = MatrixUtil.convertToMatrix(this.camRotations);
      result = result.mul(result, rotMat, result);
      result.translate(this.pos);
      return result;
   }
   
   private void updatePosition(float deltaPitch, float deltaYaw, float deltaRoll, float deltaFwd, float deltaRight){
     
      Quaternion qPitch = new Quaternion();
      qPitch.setFromAxisAngle(new Vector4f(this.right.x, this.right.y, this.right.z, deltaPitch));
      camRotations.mul(camRotations, qPitch, camRotations);
     
      Quaternion qYaw = new Quaternion();
      qYaw.setFromAxisAngle(new Vector4f(this.up.x, this.up.y, this.up.z, deltaYaw));
      camRotations.mul(camRotations, qYaw, camRotations);
               
      Quaternion qRoll = new Quaternion();
      qRoll.setFromAxisAngle(new Vector4f(this.forward.x, this.forward.y, this.forward.z, deltaRoll));
      camRotations.mul(camRotations, qRoll, camRotations);
     
     
   }
   
   
   
    public void processInput() {
      float dist = getTimeDependantDistance();
      float rot = getTimeDependantRotation();
      float deltaPitch = 0f;
      float deltaRoll = 0f;
      float deltaYaw = 0f;
     
     
      //System.out.println(deltaTime);
     
      if(Keyboard.isKeyDown(Keyboard.KEY_Q)){
         deltaRoll -= rot;
      }
      if(Keyboard.isKeyDown(Keyboard.KEY_E)){
         deltaRoll +=rot;
      }
     
      if(Keyboard.isKeyDown(Keyboard.KEY_W) & Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)){
      }else if(Keyboard.isKeyDown(Keyboard.KEY_W)){
         deltaPitch -= rot;
      }
     
      if(Keyboard.isKeyDown(Keyboard.KEY_S) & Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)){
      }else if(Keyboard.isKeyDown(Keyboard.KEY_S)){
         deltaPitch += rot;
         
      }
     
     
      if(Keyboard.isKeyDown(Keyboard.KEY_A) & Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)){
      }else if(Keyboard.isKeyDown(Keyboard.KEY_A)){
         deltaYaw += rot;
      }
     
      if(Keyboard.isKeyDown(Keyboard.KEY_D) & Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)){
      }else if(Keyboard.isKeyDown(Keyboard.KEY_D)){
         deltaYaw -= rot;
      }
     
     
     
     
      if(Keyboard.isKeyDown(Keyboard.KEY_ADD) ||Keyboard.isKeyDown(Keyboard.KEY_EQUALS)  || Keyboard.isKeyDown(Keyboard.KEY_F)){
         setSpeed(getSpeed()+0.001f);
      }
      if(Keyboard.isKeyDown(Keyboard.KEY_MINUS) || Keyboard.isKeyDown(Keyboard.KEY_F)){
         setSpeed(getSpeed()-0.001f);
      }
      if(Keyboard.isKeyDown(Keyboard.KEY_BACK)){
         setSpeed(0);
      }
     
      updatePosition(deltaPitch, deltaYaw, deltaRoll, speed,0);
     
   }
   
   

   
}

3  Discussions / General Discussions / Re: Building a free flying 3D Quaternion camera on: 2014-08-29 15:59:00
Hi Basil

thanks for the code snippets.

Im going to ask one more dum question.  Smiley

so no i can determine the forward vector. I want to ensure my translate of the position is relative to the new angles.

(ie.. i want to fly forward in the forward vector direction)

Got any samples / tips for that?
4  Discussions / General Discussions / Re: Building a free flying 3D Quaternion camera on: 2014-08-29 14:05:26
you know what.. im probably making this harder in my head than it needs to be.

Here is a snippet of my code

1  
2  
3  
4  
5  
6  
7  
   private Quaternion camRotations = new Quaternion();
   private Matrix4f   camMatrix = new Matrix4f();
   
   private Vector3f up =       new Vector3f(0,1,0);
   private Vector3f forward =   new Vector3f(0,0,-1);
   private Vector3f right =    new Vector3f(1,0,0);
   



1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
   private void updatePosition(float deltaPitch, float deltaYaw, float deltaRoll, float deltaFwd, float deltaRight){
      Quaternion qPitch = new Quaternion();
      qPitch.setFromAxisAngle(new Vector4f(this.right.x, this.right.y, this.right.z, deltaPitch));
      camRotations.mul(camRotations, qPitch, camRotations);
     
      Quaternion qYaw = new Quaternion();
      qYaw.setFromAxisAngle(new Vector4f(this.up.x, this.up.y, this.up.z, deltaYaw));
      camRotations.mul(camRotations, qYaw, camRotations);
     
      Quaternion qRoll = new Quaternion();
      qRoll.setFromAxisAngle(new Vector4f(this.forward.x, this.forward.y, this.forward.z, deltaRoll));
      camRotations.mul(camRotations, qRoll, camRotations);
     
     
   }
   



whats throwing me off.. is if i roll then pitch then yaw.. then forward would be affected by all these rotations .. so When and from which quat would i be adding.. sigh.. need more coffee.

thanks!
J.


5  Discussions / General Discussions / Re: Shameless Plug on: 2014-08-29 13:54:01
Hi Cas,

First off kudos on building another game.
your projects were one of the first I found when deciding to work on a game using java and you've definately done some nicely polished work!

This latest game has me a bit confused as to how you play / what the game really is.

can you elaborate on the concept / mechanics?

6  Discussions / General Discussions / Building a free flying 3D Quaternion camera on: 2014-08-29 13:49:52
Hi Everyone,

Ok.. so i've been trying to build a free flying camera.
I've used quaternions to handle rotations with success.

Only one part of mechanics seems to be eluding me. movement.

how do i find out after the rotations have been applied what my new relative forward vector is, so that i can translate in the right direction...

Im sure there is likely a simple answer that im just missing.

thanks for any help

J.
7  Discussions / General Discussions / Re: Camera with Roll Pitch and Yaw on: 2014-08-28 06:28:30
thanks for the code snippet..
I'll review it but not sure it will work for what i need.

An FPS style camera usually moves on a plane and pitch but does not adjust for a roll.

The camera im looking to make need to be more "flight sim" in style. ie.. the camera can bank and pull up and the relative direction has changed.
8  Discussions / General Discussions / Camera with Roll Pitch and Yaw on: 2014-08-28 06:02:44
wow the net is full cameras that support yaw and pitch.. but not roll.

does anyone have a good example / tutorial or sample of a full yaw/pitch/roll camera?

thx
j.
9  Discussions / General Discussions / Re: Matrix4f rotation and movement interaction problem on: 2014-08-27 23:55:35
yes thats right..

if anyone has a really good tutorial link for this it would be much appreciated.
im sure im just missing one little detail.

j.
10  Discussions / General Discussions / Matrix4f rotation and movement interaction problem on: 2014-08-27 17:03:13
Hi Crew,

Ok.. im having what i thought should be simple but i must be missing something.

I have a object in my world. (camera)
I represent its location using a Matrix4f.

I want to be able to rotate the object and then move it forward where forward has been affected by the rotation.
ie.. rotate roll 45 degree then pitch 45 .. forward is now 45 / 45 and move forward 100.

in multiplying my matrices however the rotation works fine.. but the forward direction is unaffected.
(it will move forward ignoring the rotation)

so im clearly missing something that likely is very newbish on my part.

any help is appreciated.

j.
11  Game Development / Newbie & Debugging Questions / Re: Private fields, not really private? on: 2014-08-20 20:43:07
Are you afraid someone will use reflection to "hack" your application?
12  Game Development / Newbie & Debugging Questions / Re: LWJGL drag shape with mouse - How would I do it? on: 2014-08-20 19:13:03
ok.. so your a 2d application which makes things easier..

you have two choices on how to tell if your mouse in "inside" your shape.

option1 : treat all your shapes like rectangles.

This is a simplification...  if your mouse Y is less than highest modelY and more than lowest modelY then its within the height.
If your mouse X is less than the highest modelX and more than the lowest modelX then its inside X
if your inside Y and inside X your in the "rectangle" of the shape!

Option 2: very accurate approach but more work.

For your irregular shape (like your image)
your going calculate the area of the shape. To do this take 3 points that make up the shade and find the area of that triangle.
Next repeat this step taking another 3 points where at least 1 point has never been used in previous calculations
repeat until you covered all the points.

If you add up all the area calculations you will have the area of the shape.

Next we repeat the process but now we use the mouse x,y as if it was a point in the shape.
If the x,y of the mouse is inside the shape the area sum will == our first calculation. if its outside the shape it will result in an area larger than the original sum of the areas.

This approach will give you very accurate detection.




 
13  Game Development / Newbie & Debugging Questions / Re: LWJGL drag shape with mouse - How would I do it? on: 2014-08-20 17:59:06
Ok.. what you want to do should (as in most things in life) be broken down into smaller steps that when combined get the result your looking for.

Step 1: is my mouse over my model.
Now you didnt say if this was a 2d or 3d game.. the the concept is the same either way.
If your in a 2d game you needs a bounds checking (is my mouse x,y inside my shape)...
If your in a 3d game you need to do a raytrace or picker routine.

This is probably the hardest part.. once you have this working.
Next comes what to do now that we know your over the object with your mouse.

Step2: Keyboard  / mouse listener
LWJGL provides a very nice interface for building a keyboard and mouse listener.
Implement this and youll be able to write code that reacts to when a button on either peripheral is pressed.

Step 3 and 4
Now that we know we were over a object and a key was pressed change the coords of the model as we move the mouse.
This really just changing the coords your using based on more keyboard / mouse listener imputs. Thing of moving the mouse as another way of pushing buttons.. you can get the motion from the same interface provided by lwjgl.

They then push a button and you stop updating the model's coords.

Ok.. so this is very very abstract.. but if you tell me more about your game i can try to be more specific.

j.
14  Game Development / Game Mechanics / Re: [LibGDX] Edges on 3D models on: 2014-08-18 18:44:51
in your shader.. you will need to "test" if your at the edge of your model and if so change the color to say black..
you can reapply this same logic to see if your "withing 5 pixels" of the edge to make the highlight bold if you want.

15  Games Center / Contests / Re: Ludum Dare 30 (Next Weekend) on: 2014-08-18 17:37:19
i may join. would be a great test for my homebrewed game engine thats finally maturing...
16  Discussions / Miscellaneous Topics / Re: Unofficial Minecraft Convention dissapears with $500,000 on: 2014-08-18 15:16:09
Im going to FanExpo in Toronto.

That one is 50 bucks to get in (for 1 day) and another 40 to participate in the Dr. Who session..

so 150 was not so extreme that it would raise eyebrows.

17  Discussions / Miscellaneous Topics / Re: How often do you code on: 2014-08-18 15:13:48
I code about 4 hours a night .. with the odd evening off to do "real world" things.

18  Discussions / General Discussions / Re: Open-Source Licenses on: 2014-08-07 18:50:49
nothing is stopping it.. in fact it happens all the time.

Ibm Http Server = is actually apache2 rebranded
Hudson is free but supported for $ by oracle = is actually Jenkins
The new IBM Websphere Liberty server =  is actually OSGi and tons of common open source libraries.

The promise these companies use to sell what is otherwise free is that they will provide support or extra features above and beyond what the open source one provides. When they fail to meet this promise their product usually only lasts a few years and then dies. If they do meet their customers expectations it can actually benefit both the OSS version and the paid knock offs in the form of larger community and more frequent bug fixes.
19  Discussions / General Discussions / Re: HIGH PROBABILITY OF SUCCESSFUL MIGRATION on: 2014-08-06 16:20:49
all smooth from this users end.. good job!
20  Discussions / General Discussions / Re: LWJGL - lUniformMatrix4fv on: 2014-07-31 21:16:44
i just figured it out.. your response it right!

use glUniformMatrix4f in your code.. put all the values in the buffer.

in your .vert shader define the variable as a mat4[] and use the gl_InstanceID .. Smiley
the magic happends under the covers for you.

21  Discussions / General Discussions / LWJGL - lUniformMatrix4fv on: 2014-07-31 20:37:33
Hi Everyone,

So im working on my game library an ran into a bit of a snag.
is lUniformMatrix4fv missing within LWJGL?

if so anyone find a good way to pass a list of per instanced matrix to a shader?

thanks
j.
22  Discussions / General Discussions / Re: Passing vectors from Vertex to Fragment on: 2014-05-26 13:32:07
here is a bit of an example...
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
#version 410


uniform mat4    in_projectionMatrix;
uniform mat4    in_cameraMatrix;
uniform mat4    in_modelMatrix;
layout(location = 0) in vec3 vp;
layout(location = 1) in vec3 np;

out vec3 pass_normal;
out mat4 pass_cameraMatrix;

void main () {
    vec4 vertex = vec4(vp, 1.0);
    gl_Position =    in_projectionMatrix * in_cameraMatrix * in_modelMatrix * vertex;
    pass_normal = np;
    pass_cameraMatrix = in_cameraMatrix;
   
   
}



1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
#version 410

in  vec3 pass_normal;
in  mat4 pass_cameraMatrix;
out vec4 frag_colour;







void main(){
   //frag_colour = vec4(0.5, 0.0, 0.5, 1.0);
  vec4 colour = vec4(pass_normal, 1) * pass_cameraMatrix;
   //frag_colour = vec4(0.1,0.1,0.1,1) * colour;
  frag_colour = colour;
   
}
23  Java Game APIs & Engines / OpenGL Development / Re: Render on specific GPU in OpenGL on: 2014-03-07 15:50:48
To the original poster...

I'm guessing your on a Macbook Pro. Cause this two video card approach is exactly how they are setup.

So to answer your question and give you a hint to what your going to encounter next ..

1) you dont have to do anything .. as soon as you init your display using OpenGL it will switch to the dedicated card. There is a GLX util you can download that monitors the cards and will show you it autoswitches.

2) now the next challenge.. which version of opengl do you want to use? By default the dedicated card will be a opengl 2.2 profile. If you want the opengl 4.1 profile you will have to specifically init the opengl profile asking for ... 3.2 CORE ... (yes 3.2 CORE = 4.1 implementation.. if you ask for 4.1 you will get an error.. welcome to the nuances that is Mac gaming Smiley

24  Discussions / General Discussions / Re: Windows 8 Purchase on Linux on: 2014-03-05 15:15:31
Here is how you do it.

Install the software.. when it asks for you to enter your key.. dont.
it will allow the install to continue... but it will not be a "registered" install.
then once installed.. you install it again using the same disk.
This time you can use your key and all will turn out fine.

I've often used upgrade disks.. this is the work around.
25  Game Development / Newbie & Debugging Questions / Re: Why should I use a Game-Engine like lwjgl or libgdx instead of Swing? on: 2014-03-05 14:56:12
For 2D games there are lots of options.. the only real answer is use what works for you.

When talking about lwjgl and libgdx the real trade off is they are wrappers exposing opengl to your java code. If your game will not benefit from opengl then there may not be a compelling reason to use these. On the other had these are both libraries suited to game development and opengl will provide high performance graphics, but they will be harder to work with then pure swing for very basic tasks like making buttons.
26  Game Development / Newbie & Debugging Questions / Re: New to java, where do i start? on: 2014-03-04 19:35:44
If you are new to java I recommend you download the the book "Thinking in Java" by Bruce Eckle. You can download it for free. Its a great book and introduces the concepts used in java programming in one of the most logical ways I've ever seen.

j.
27  Discussions / General Discussions / Modern Opengl (4.x) unproject on: 2014-02-16 18:10:00
Ok.. so my old code used GLU unproject to transform mouse coords into world coords.

Now that i have converted to OpenGL 4.x i have run into an issue.

The param used to call unproject include the viewport matrix. I used to get this by asking opengl to return it to me.
Now it seems i will have to create the matrix my self before calling the function.

anyone ever found any documentation on how to convert your width / height into a view port matrix?

thanks
j.
28  Game Development / Game Play & Game Design / Re: How does one make such perfect 8x8 font? on: 2014-02-13 16:37:07
not sure im following your question..

what he did was make an image map. each region becomes a letter.
the regions in the image are evenly spaced so its easy to iterate through them.

the actual act of making the letters is just a matter of drawing them in your favourite paint program.

29  Discussions / General Discussions / Re: Indie Crowdfunding on: 2014-02-13 16:11:41
crowdsourcing is basically like pre-buying a game a your local best buy.
you pay up front with no product only a promise that eventually youll get it.

Which likely explains why most donators are actually paying the minimum price to get the product and not token 1$ amounts.

This method is great for indie start ups that want to try something the community believes in but a large publisher would not risk money on.

I just worry that the percentage of games that never get delivered may tarnish this medium.

j.
 
30  Discussions / General Discussions / Re: Data bases and game programming on: 2014-02-13 16:07:13
JavaDB / Derby is good option if you want a DB for game development. Mostly cause it has a in memory only runtime mode. So the latency of hiting and reading from the DB is basically removed in this model.

j.
Pages: [1] 2 3 ... 5
 

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

The first screenshot will be displayed as a thumbnail.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (29 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (38 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (25 views)
2014-08-16 06:20:21

Tekkerue (34 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (48 views)
2014-08-09 21:09:32
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!