Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 ... 4 5 [6] 7 8 ... 10
 51 
 on: 2014-08-29 18:13:12 
Started by TehJavaDev - Last post by thedanisaur
Since everyone is using Thread.sleep(), which I think looks rather bad, I thought I'd just leave this here...

http://gafferongames.com/game-physics/fix-your-timestep/

 52 
 on: 2014-08-29 16:50:44 
Started by jmguillemette - Last post by jmguillemette
i've removed my movement code so as to return to the "most working" state as i ask for suggestions.

thanks!
J.

 53 
 on: 2014-08-29 16:49:27 
Started by jmguillemette - Last post by jmguillemette
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);
     
   }
   
   

   
}


 54 
 on: 2014-08-29 16:43:42 
Started by DrewLols - Last post by princec
You're looking in the wrong place... run -Xprof on the output and show it here. I think I know what your issue is and it's actually benign.

Cas Smiley

 55 
 on: 2014-08-29 16:41:32 
Started by jmguillemette - Last post by Roquen
The rotate about Y by angle.

 56 
 on: 2014-08-29 16:40:37 
Started by jmguillemette - Last post by basil_
[...] The rotation example above is wrong..miss the trig. [...]
which one ?

 57 
 on: 2014-08-29 16:34:17 
Started by jmguillemette - Last post by Roquen
Funny all these related questions popping.  Forward from matrix, inverting SE(2) and this.   Getting forward, up, right is equivalent to (part) of converting to a matrix, which in turn is just rotating an axial vector.  Dead easy since two values are zero and one is one (or minus one if you're into that kind of thing).  The rotation example above is wrong..miss the trig.  And if you've computed two, then the third is almost free...doing the cross product to produce it is more expensive.

 58 
 on: 2014-08-29 16:34:16 
Started by lcass - Last post by lcass
ALS is not that deadly of a disease , it only really effects people who are already at an age when its difficult to perform normal tasks anyway.

?

ALS can begin at any age as far as I am aware, and it most certainly IS deadly as your chance of a fatal hearth-failure is very high.
At least thats what my mother told me about ALS and what it does.
(And she should know what it does because some of her patients have it)

Or am I (and my mother) wrong?

- Longor1996
No you are nto wrong , my wording went a bit off there I meant its not as widespread or severe as other diseases , even looking at the values themselves almost a 100x more people die because of heart disease and yet the funding is only twice the amount of the funding for ALS .

Of course you should donate , dontating to any charity is good because it will always help someone , my point is that dont throw the money at one problem , it wont solve the rest. You should give money to ALS to Heart disease to cancer to unicef because it helps people but just giving all the money to one place leaves the others at difficulty, however going onto heart disease which is sometimes caused by people with things such as obesity and smoking whereas having ALS is currently not known to be caused by any human controllable factors.

 59 
 on: 2014-08-29 16:27:53 
Started by DrewLols - Last post by DrewLols
It seems that my 2D platformer game is becoming slower over time.  I decided to check out LibGDX since it was up to date with newer versions of opengl, runs smoothly, and acts as more of an optional abstraction around the pipeline.  I haven't run into any noticeable performance issues, but I have seen my cpu reach 19% over time.  To be specific, when I first launch the game, it runs quickly and efficiently.  Only about 2% of the cpu is being used at most.  After about 30 seconds, it's 4%.  Then, after a minute, it peaks to about 19%.  It never goes beyoind that number, and the fps never drops.  I can hear my fan going nuts, though, so it is still a problem.

I made a simple but effective performance logger that records the amount of time it takes to complete a task.  After about, say, 60 recordings, since my game's fps is 60, I log a message to a PrintStream regarding the average amount of time it took to complete the task.  I narrowed down where the performance degrades, and it's in LibGDX's SpriteBatch class.  Invocations of end() start to become slow after a while, but I am not sure why.  Here the the method utilizing SpriteBatch that sees performance issues.

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  
   public void render(Matrix4 m, float parentAlpha)
   {
      // Optimizes the grid so that only the tiles that are visible are displayed
     if(optimized)
         optimize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
     
      // Grabs SpriteBatch from globally accessible Renderer
     SpriteBatch batch = Renderer.getSpriteBatch();
     
      // Sets alpha to the one accumulated through the scene graph
     batch.setColor(1, 1, 1, parentAlpha);
     
      // Begins drawing
     batch.begin();
     
      // Renders all tiles within optimized range.  Mins and maxes were determine when optimize() was invoked
     for(int y=minY; y<maxY; y++)
      {
         for(int x=minX; x<maxX; x++)
         {
            TextureRegion reg = get(x, y);
            if(reg != null)
            {
               batch.draw(reg, x*regWidth, y*regHeight);
            }
         }
      }
     
      // Ends drawing
               logger.begin();        // Begins recording the amount of time it takes to complete batch.end()
     batch.end();
                logger.end();          // Ends recording, and outputs the average amount of time it took to complete after 60 invocations.
  }


Ok, not all variables are defined in this example, but I think what is happening here should be clear.  I have a matrix of tiles that I want to render, and the tiles are an array of TextureRegions.  When rendering, I iterate through the matrix from the top left to the bottom right horizontally before vertically.  When I am done rendering this batch, I invoke batch.end().  I have proven that the degredation occurs specifically at the invocation of batch.end(), because the amount of time it takes to do this after about a minute is 17-18 milliseconds, which composes the majority of the aforementioned slowdown.

Why would this method behave like an angel, and then suddenly slow down later?  I can't really focus my logger on a particular part of this method since it's part of LibGDX.  Is there some way that I could be misusing SpriteBatch here, or somewhere else?  I'm still fairly new to LibGDX, so I would not be surprised.

Edit:  I am aware that SpriteBatch's end() method uploads vertices and texture ids to opengl that were gathered earlier.  I feel like somehow, my batch is accumulating vertices/id's/SOMETHING, and perhaps I am forgetting to clear that something.

 60 
 on: 2014-08-29 16:08:15 
Started by yann68 - Last post by basil_
aah the good old transpose weirdness.

Pages: 1 ... 4 5 [6] 7 8 ... 10
 

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

The first screenshot will be displayed as a thumbnail.

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

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

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

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

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

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

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

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

BurntPizza (44 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01:56
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!