• Content count

  • Joined

  • Last visited

Community Reputation

504 Good

About Clobslee

  • Rank
  1. LibGDX/Box2D orbital mechanics

      Hey thanks for the reply, made a few changes based on your recommendations and it now acts as expected regardless of initial position of the rocket. I appreciate it!   Edit: That's all I needed! I can now orbit small masses around the larger mass. Thanks again.
  2. So I'm messing around with Box2D and libgdx again and seem to have run into an issue. I'm calculating the gravitational force of a planet object and trying to apply the appropriate force vector to my "rocket" every step to accelerate it towards the planet but am getting a few unexpected results. I have a planet body at 0,0 in the box2d world. My rocket seems to be pulled toward the planet correctly IF its x value is greater than 0 and I don't try too apply any initial force to the rocket, but the second I move to the other side it has unexpected results. All of the physics I know are self taught so I'm sure I'm making a mistake in the math but am unsure exactly where. Hopefully my explanation of the following will provide enough information for you guys to give me some help!    Every step I apply a force to the center of my rocket object as seen in these two functions: private void gameUpdate() { //If more than 1/45 of a second has passed update the game if(shouldUpdate(TimeUtils.millis())) { //Step Box2D world - Update physics 1/45th of a second. world.step(1/45f, 6, 2); applyGravitationalForce(); // System.out.println("Updating"); //Just updated so set the gameTime to now gameTime = TimeUtils.millis(); } //System.out.println("Passed on Updating"); } private void applyGravitationalForce() { rocket.getWorldBody().applyForceToCenter(rocket.getVectorForce(planet), false); } The Rocket class and my force calculation function : public class Rocket { private Vector2 pos; private Texture rocketTexture; private BodyDef body; private CircleShape circle; private FixtureDef fixtureDef; private Fixture fixture; private Body worldBody; private double mass; public Rocket(World world) { setPos(new Vector2(100,-100)); createWorldBody(world); setMass(5); } private void createWorldBody(World world) { body = new BodyDef(); body.type = BodyType.DynamicBody; body.position.set(this.pos); setWorldBody(world.createBody(body)); circle = new CircleShape(); circle.setRadius(6f); fixtureDef = new FixtureDef(); fixtureDef.shape = circle; fixtureDef.density = .5f; fixtureDef.friction = .4f; fixtureDef.restitution = .6f; fixture = getWorldBody().createFixture(fixtureDef); } public Vector2 getVectorForce(Planet planet2) { //rocket -> planet force vector //rocket pos Vector2 posOfRocket = new Vector2(getPos()); System.out.println("Rocket: " + this.getWorldBody().getPosition().toString()); System.out.println("Planet: " + planet2.getLocation().toString()); //rockets pos - planets pos Vector2 sub = new Vector2(posOfRocket.sub(planet2.getWorldBody().getPosition())); System.out.println("sub: " + sub.toString()); //System.out.println("Local pos: " + posLocal.toString()); //Find angel of in radians double angleR = Math.atan(sub.y/sub.x); //<--------------------------- This is my best guess as to where the problem is. System.out.println("Radians: " + angleR); //convert to degrees double angleD = Math.toDegrees(angleR); System.out.println("Degrees: " + angleR); Vector2 force = new Vector2(0,0); //Calculate force vector using planets gravitational force *no idea why I have to multiply by -1 here* force.x = (float) ((planet2.calcgravity(this) * Math.cos(angleD)) * -1); force.y = (float) ((planet2.calcgravity(this ) * Math.sin(angleD)) * -1); System.out.println("Force Vector: " + force.toString()); return force; } My planet class with its function to calculate gravitational force based on mass and rockets mass package; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.BodyDef; import com.badlogic.gdx.physics.box2d.CircleShape; import com.badlogic.gdx.physics.box2d.Fixture; import com.badlogic.gdx.physics.box2d.FixtureDef; import com.badlogic.gdx.physics.box2d.World; import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; public class Planet { private double mass; private double radius; private double gravity; private String name; private Vector2 location; //calculate gravitational constant private final double gravityConstant = 1;//6.673 * (java.lang.Math.pow(10, -11)); //box2d imports private Body worldBody; private BodyDef body; private CircleShape circle; private FixtureDef fixtureDef; private Fixture fixture; // name, mass of new planet, radius, mass of object, loc in 2D space public Planet(String name, double d, double e, double f, Vector2 loc, World world) { this.setName(name); this.setRadius(e); this.setMass(d); //this.setgravity(calcgravity(f)); this.setLocation(loc); createWorldBody(world); debugObj(f); } private void createWorldBody(World world) { body = new BodyDef(); body.type = BodyType.DynamicBody; body.position.set(this.location); worldBody = world.createBody(body); circle = new CircleShape(); circle.setRadius((float)radius/100000); fixtureDef = new FixtureDef(); fixtureDef.shape = circle; fixtureDef.density = .5f; fixtureDef.friction = .4f; fixtureDef.restitution = .6f; fixture = worldBody.createFixture(fixtureDef); } private void debugObj(double f) { System.out.println("Planet - " + name); //System.out.println("radius: " + radius); System.out.println("mass: " + mass); System.out.println("gravitational acceleration: " + gravity + " (ship mass: " + f + ")"); //System.out.println("Box2D radius: " + circle.getRadius()); } //Calculate the gravitational pull of the planet on the rocket object public double calcgravity(Rocket rocket) { double gravityForce = 0; //Calculate the gravitational force in Newtons System.out.println("GC: " + gravityConstant + ", Planet mass: " + this.mass + ", RocketMass: " + rocket.getMass()); //force in N gravityForce = (gravityConstant * this.mass * rocket.getMass()) / (Math.pow(rocket.getPos().x, 2) + Math.pow(rocket.getPos().y, 2)); System.out.println("G Force: " + gravityForce); this.gravity = gravityForce; return gravityForce; // TODO Auto-generated method stub } I think I already mentioned it but applying any initial force seems to bring it completely out of whack... Any help or suggestions are appreciated! Thanks in advance.  

    Congratulations! Washington State is beautiful! I'm going to college here and it's amazing... I love seeing this kind of thing. Makes me want to keep grinding! Thanks for sharing!
  4. WPF - Presenting 2D sprites (2D map editor)

    It's possible, but there are tools that do most of this for free! Is there a reason you don't want to use one of these?   Check out tiled or tide! There are many more but these are the only ones I've used.
  5.   Well said! I have always excelled with computers, code daily, but couldn't draw worth a damn! The past semester I took an art class expecting to see immediate improvement, I had the best attendance in the class, turned everything in and got a C. My mother is a children's book illustrator, you have it, or you don't. FML.   That stuffs hard!
  6. Am I Officially Getting Old, When...

    Whats wrong with a little spiced cucumber every now and again, or every meal?     Sometimes I think of pickles as really dead cucumbers.
  7. Beginner Blog

    Sweet!   Not to pry, but what is the name of the program or school you're at? I've been at a state university studying computer science, but am starting to feel like a program for just games might be my next step.
  8. Do you or anyone that would be helping have programming experience? Which platforms would you want it to run on? You mentioned mobile, but is that all? Knowing these things will probably help someone answer your question. Assuming programming experience and that you're not set on a language or engine, I'd say look at any starting libgdx tutorials, and general networking.     If no one working on the project has programming experience I'd say the first step is learning how to program.
  9. Should I use OpenGL or Directx

      I'd agree with eric and would encourage you to try some 2D games first. This will help you better understand the "game loop" and how to manage assets effectively. I haven't messed with anything 3D yet and have been working on a few 2D games for 5-6 months. I'm sure this is going to make 3D a quicker and more efficient learning experience. I use openGl because its used on many platforms, but id assume this decision depends on which platforms you're targeting.
  10. So this is still happening after re installing tools... Also I can delete the entire android manifest and I get the exact same error. It's not even looking at the manifest....
  11.   Will try some of these when I get some time today but I'm not using eclipse and have already tried copying the project to a new folder, although I haven't tried re-installing my tools. I've been devloping with gedit and gradle through the terminal.   It's very odd. It has to be a bug!
  12.   Thanks for the explination. My java files do have the correct package name at the top! package; import android.os.Bundle; import; import; import; public class AndroidLauncher extends AndroidApplication { @Override protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); initialize(new MyGdxGame(), config); } }
  13. So this is weird but I guess that was not the problem... I'm very confused. When trying to run everything again this morning I started recieving the same error again. I haven't changed any of files. The project builds for android succesfully but when I execute gradles "android:run" command I get the above error. My packages are correct as I have not altered them at all after using using the libgdx app to build the project. My emulator is running and recognized.   Here is the terminal Configuration on demand is an incubating feature. :android:run WARNING: linker: has text relocations. This is wasting memory and prevents security hardening. Please fix. Starting: Intent { } Error type 3 Error: Activity class {} does not exist. BUILD SUCCESSFUL Total time: 2.155 secs And the AndroidManifest <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="" package="" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="22" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/GdxTheme" > <activity android:name="" android:label="@string/app_name" android:screenOrientation="landscape" android:configChanges="keyboard|keyboardHidden|orientation|screenSize"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> And my file (I haven't changed anything) buildscript { repositories { mavenCentral() maven { url "" } } dependencies { classpath '' } } allprojects { apply plugin: "eclipse" apply plugin: "idea" version = '1.0' ext { appName = 'my-gdx-game' gdxVersion = '1.6.0' roboVMVersion = '1.2.0' box2DLightsVersion = '1.3' ashleyVersion = '1.4.0' aiVersion = '1.5.0' } repositories { mavenCentral() maven { url "" } maven { url "" } } } project(":desktop") { apply plugin: "java" dependencies { compile project(":core") compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion" compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop" compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop" } } project(":android") { apply plugin: "android" configurations { natives } dependencies { compile project(":core") compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion" natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi" natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a" natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86" compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion" natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi" natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a" natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86" } } project(":core") { apply plugin: "java" dependencies { compile "com.badlogicgames.gdx:gdx:$gdxVersion" compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion" } } tasks.eclipse.doLast { delete ".project" } [attachment=28773:helpME.png]   What is going on...?[attachment=28774:wtf.png]
  14.   Thanks for the replies, gave up on the android build for now and just focusing on the back end for a day, completely forgot about this post. I haven't tried it but this does indeed sound like the issue. Seems my tools are having trouble. Thanks!      EDIT: This ended up not being the issue!
  15. Did I not add enough information? I'm still stuck. Effffffff.