Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Pages: 1 ... 3 4 [5] 6 7 ... 16

Author Topic: [0.97a] LazyLib v2.8b (released 2024-02-02)  (Read 979482 times)

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: LazyLib v1.7 (.6.1a, released 2013-12-18)
« Reply #60 on: December 19, 2013, 08:38:54 PM »

No, it's very simple, but a little different :)

Here is what I'm talking about:
Code: java
	public static Vector2f randomCircularVelocity(Vector2f position,float velocity)
{
Vector2f velPos = MathUtils.getRandomPointOnCircumference(position, velocity);
Vector2f newVel = Vector2f.sub(velPos,position,null);
return newVel;
}

Which is really really useful for building special-effects stuff, like particle-system bursts, where we want to create a particle with a true-circular random velocity (using two Math.randoms() gives us a square pattern, which looks horrible).  It's what I used to do all the neato explosion effects with in Vacuum- very simple code but very powerful.

Here is an example of it being used:

Spoiler
Code: java
package data.scripts.weapons;

import java.awt.Color;

import org.lwjgl.util.vector.Vector2f;
import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.CombatEntityAPI;
import com.fs.starfarer.api.combat.DamagingProjectileAPI;
import com.fs.starfarer.api.combat.OnHitEffectPlugin;
import org.lazywizard.lazylib.MathUtils;

public class ExplosiveOnHitEffect implements OnHitEffectPlugin {

public static Vector2f randomCircularVelocity(Vector2f position,float velocity)
{
Vector2f velPos = MathUtils.getRandomPointOnCircumference(position, velocity);
Vector2f newVel = Vector2f.sub(velPos,position,null);
return newVel;
}

        @Override
public void onHit(DamagingProjectileAPI projectile, CombatEntityAPI target,
  Vector2f point, boolean shieldHit, CombatEngineAPI engine) {

float emp = projectile.getEmpAmount();
float dam = projectile.getDamageAmount();
int repeat = Math.max(6,(int) ((dam / 100f) + 10f));
int repeatTwo = repeat / 3;
for(int i = 0; i < repeat; i++)
{
Vector2f randPoint = MathUtils.getRandomPointInCircle(point,dam/35f);
float randSize = MathUtils.getRandomNumberInRange(dam/25f,Math.max(dam / 20f,15f));
Vector2f randVec = randomCircularVelocity(randPoint,MathUtils.getRandomNumberInRange(30f,Math.max(dam / 50f,31f)));
float randDur = 0.1f + MathUtils.getRandomNumberInRange(0.0f,0.3f);
int yelVal = (int) (Math.random() * 200f + 32f);
int randTrans = (int) MathUtils.getRandomNumberInRange(64f,128f);

engine.addSmoothParticle(randPoint, randVec, randSize, 1f, randDur, new Color(255,yelVal,0,randTrans));
}
for(int i = 0; i < repeat; i++)
{

int yelVal = (int) (Math.random() * 128f + 64f);
Vector2f randPoint = MathUtils.getRandomPointInCircle(point,dam/100f);

//Random Vectors, in order of speed; generally, we need smoke and central poof to be slower than others
Vector2f randVecFast = randomCircularVelocity(randPoint,MathUtils.getRandomNumberInRange(30f,Math.max(dam / 2f,31f)));
Vector2f randVecFastTwo = randomCircularVelocity(randPoint,MathUtils.getRandomNumberInRange(30f,Math.max(dam / 2f,31f)));
Vector2f randVec = randomCircularVelocity(randPoint,MathUtils.getRandomNumberInRange(30f,Math.max(dam / 25f,31f)));
Vector2f randVecTwo = randomCircularVelocity(randPoint,MathUtils.getRandomNumberInRange(30f,Math.max(dam / 35f,31f)));
Vector2f randVecThree = randomCircularVelocity(randPoint,MathUtils.getRandomNumberInRange(15f,Math.max(dam / 40f,16f)));

float randSize = MathUtils.getRandomNumberInRange(10f,Math.max(dam / 50f,15f));
float randSizeTwo = MathUtils.getRandomNumberInRange(5f,10f);
float randDur = 1f + MathUtils.getRandomNumberInRange(-0.5f,3f);
float randDurTwo = MathUtils.getRandomNumberInRange(0.5f,1f);
int randTrans = (int) MathUtils.getRandomNumberInRange(32f,200f);
int randGray = (int) MathUtils.getRandomNumberInRange(32f,64f);

engine.addHitParticle(point, randVecFast, randSizeTwo, 1f, randDurTwo * 0.5f, new Color(255,yelVal + 64,0,randTrans + 55));
engine.addHitParticle(point, randVecFastTwo, randSizeTwo, 1f, randDurTwo * 0.65f, new Color(255,yelVal + 64,0,randTrans + 55));
engine.addHitParticle(point, randVec, randSize, 1f, randDurTwo, new Color(255,yelVal-64,0,randTrans));
engine.addHitParticle(point, randVecTwo, randSize, 1f, randDurTwo * 0.75f, new Color(255,yelVal-32,0,randTrans));
engine.addHitParticle(point, randVecThree, randSize, 1f, randDurTwo * 0.5f, new Color(255,yelVal,0,randTrans));

engine.addSmokeParticle(point, randVecThree, MathUtils.getRandomNumberInRange(dam / 100f,dam / 50f), MathUtils.getRandomNumberInRange(0.5f,1f), randDur, new Color(randGray,randGray,randGray,randTrans));
}
}
}

[close]
Logged
Please check out my SS projects :)
Xeno's Mod Pack

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1363
    • View Profile
    • GitHub Profile
Re: LazyLib v1.7 (.6.1a, released 2013-12-18)
« Reply #61 on: December 19, 2013, 08:45:40 PM »

If you're getting a random point around position, then subtracting position from it, then wouldn't that be the same as MathUtils.getRandomPointOnCircumference(null, velocity), which uses a {0, 0} origin?
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: LazyLib v1.7 (.6.1a, released 2013-12-18)
« Reply #62 on: December 19, 2013, 08:55:35 PM »

Ah, I didn't think using null there was safe.  Sorry, I wrote that fairly early on, guess I can lose a few ops! 

Anyhow, yeah, that'd be a more efficient way to express it.  Point's still the same; it's a non-trivial use of the concept of vectors that extends getRandomPointOnCircumference that is something a lot of people need and would love a simple plug-and-play expression for :)
Logged
Please check out my SS projects :)
Xeno's Mod Pack

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1363
    • View Profile
    • GitHub Profile
Re: LazyLib v1.7 (.6.1a, released 2013-12-18)
« Reply #63 on: December 19, 2013, 09:10:28 PM »

Yeah, accepting a null isn't very intuitive, but it's useful to avoid instantiating an extra Vector2f. It's mentioned in the JavaDoc, but usually under the @params tag instead of the main method description. :)

For the record, the following methods in MathUtils will assume a {0, 0} origin if null is passed in for the center argument:
  • getPointOnCircumference(Vector2f center, float radius, float angle)
  • getPointsAlongCircumference(Vector2f center, float radius, int numPoints, float angleOffset)
  • getRandomPointOnCircumference(Vector2f center, float radius)
  • getRandomPointInCircle(Vector2f center, float radius)
  • getRandomPointInCone(Vector2f center, float radius, float minAngle, float maxAngle)
  • getEquidistantPointsInsideCircle(Vector2f center, float radius, float spaceBetweenPoints)
  • isPointWithinCircle(Vector2f point, Vector2f center, float radius)
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: LazyLib v1.7 (.6.1a, released 2013-12-18)
« Reply #64 on: December 19, 2013, 09:14:25 PM »

Aha.  Useful to know that, I usually don't presume null is acceptable input to a function in this language :)

BTW, thanks very, very much for the random point on line function, that's another relatively-simple thing but it's very useful for Beam SFX stuff. 

The Cone stuff looks super-useful as well, that makes it easy to do things like directional devices (rams, for example) and all sorts of SFX applications!
Logged
Please check out my SS projects :)
Xeno's Mod Pack

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: LazyLib v1.7 (.6.1a, released 2013-12-18)
« Reply #65 on: December 19, 2013, 09:18:58 PM »

Oh, and!

Where does that JSON go?
Logged
Please check out my SS projects :)
Xeno's Mod Pack

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1363
    • View Profile
    • GitHub Profile
Re: LazyLib v1.7 (.6.1a, released 2013-12-18)
« Reply #66 on: December 20, 2013, 01:09:28 PM »

Aha.  Useful to know that, I usually don't presume null is acceptable input to a function in this language :)

I'm sure this kind of thing probably drives purists insane. :D

Oh, and!

Where does that JSON go?

lazylib_settings.json? It's in the base mod folder. If you still include LazyLib in your Vacuum mod, you'll also want to delete data/scripts/plugins/LazyLibCombatPlugin.java as it's no longer used.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: LazyLib v1.7 (.6.1a, released 2013-12-18)
« Reply #67 on: January 08, 2014, 11:15:12 PM »

Code: java
//Rotates a line segment of length offset around the Vector2f origin using the angle (in degrees).  
//Very useful for anything where we need A-to-B line segments, but we only have one point to work with and a length.
//Many thanks to Louis Wasserman for his example of simple line segment rotation on Stack Overflow, from which this example was derived.

public Vector2f RotateLineSegment(Vector2f origin, float offset, float angle){            
  double[] pt = {(double) offset, (double) 0f};
   // rotates the line segment from 0,0 to offset, 0 to angle
  AffineTransform.getRotateInstance(Math.toRadians(angle), 0, 0).transform(pt, 0, pt, 0, 1);
  //Cast result back to float to get back to Vector2f here, now that we don't need the precision
  float newX = (float) pt[0];
  float newY = (float) pt[1];
  return new Vector2f(origin.getX() + newX, origin.getY() + newY);
}
« Last Edit: January 08, 2014, 11:40:44 PM by xenoargh »
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Himntor

  • Ensign
  • *
  • Posts: 48
    • View Profile
Re: LazyLib v1.7 (.6.1a, released 2013-12-18)
« Reply #68 on: January 09, 2014, 08:46:45 PM »

Hey, I'm using the LazyLib mod for the UomozSector mods, and every time I start up the game with both it gives me this error:



No idea how to fix it.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: LazyLib v1.7 (.6.1a, released 2013-12-18)
« Reply #69 on: January 09, 2014, 09:45:25 PM »

Sounds like Uomoz needs to update his mod.  LazyLibCombatPlugin is deprecated.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1363
    • View Profile
    • GitHub Profile
Re: LazyLib v1.7 (.6.1a, released 2013-12-18)
« Reply #70 on: January 10, 2014, 02:05:41 AM »

You can fix it by opening the US mod folder, going to data/scripts/plugins and deleting LazyLibCombatPlugin.java.
Logged

Uomoz

  • Admiral
  • *****
  • Posts: 2663
  • 'womo'dz
    • View Profile
Re: LazyLib v1.7 (.6.1a, released 2013-12-18)
« Reply #71 on: January 10, 2014, 02:16:11 AM »

Sounds like Uomoz needs to update his mod.  LazyLibCombatPlugin is deprecated.

It's not present in the current release, as far as i know.
Logged

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1363
    • View Profile
    • GitHub Profile
Re: LazyLib v1.7 (.6.1a, released 2013-12-18)
« Reply #72 on: January 10, 2014, 02:32:13 AM »

It's not present in the current release, as far as i know.

I was wondering about that. I know the vast majority of crashes go unreported, but to only get a report about my mod causing a guaranteed crash in one of the most popular mods on the forum a month later? :P

Also, is it weird to say I found the history of this particular crash fascinating? That plugin is a relic from the pre-1.0
version of LazyLib, and was probably only there because your compilation was one of the mods to use the old bundled version of LazyLib and keeping the plugin around wouldn't have caused any problems until 1.7 was released. :)
Logged

Himntor

  • Ensign
  • *
  • Posts: 48
    • View Profile
Re: LazyLib v1.7 (.6.1a, released 2013-12-18)
« Reply #73 on: January 10, 2014, 12:34:35 PM »

Fixed it, but there wasn't a LazyLib combat plugin file where you said. Had to delete the one that was in the LL mod file, not the US. Thanks though! Still helped.
Logged

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1363
    • View Profile
    • GitHub Profile
Re: LazyLib v1.7 (.6.1a, released 2013-12-18)
« Reply #74 on: January 10, 2014, 12:58:50 PM »

Ah, glad to hear you got it fixed.

You should always delete a mod's old folder before installing a new version (this goes for any mod). If you don't, files that were removed in the new version will be left floating around and can cause errors. :)
Logged
Pages: 1 ... 3 4 [5] 6 7 ... 16