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)

Author Topic: Attitude control system  (Read 2169 times)

xangle13

  • Lieutenant
  • **
  • Posts: 68
    • View Profile
Attitude control system
« on: April 25, 2014, 03:25:53 AM »

Long time haven't post any thing on forum.
Here's my new toy, hope you like it:

http://www.tudou.com/v/m5ctX2lam9A/&rpid=4866143&resourceId=4866143_04_05_99/v.swf
Logged

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: Attitude control system
« Reply #1 on: April 25, 2014, 04:53:06 AM »

Nice!
Logged

Cycerin

  • Admiral
  • *****
  • Posts: 1665
  • beyond the infinite void
    • View Profile
Re: Attitude control system
« Reply #2 on: April 25, 2014, 05:13:34 AM »

Wow, can you please post the scripts you used to accomplish that? It would be very useful.
Logged

billi999

  • Commander
  • ***
  • Posts: 149
    • View Profile
Re: Attitude control system
« Reply #3 on: April 25, 2014, 07:56:35 AM »

I always wanted to see something like this, reaction thrusters can really add to the visual appeal and are realistic at least with our current technology. Great work!
Logged

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: Attitude control system
« Reply #4 on: April 25, 2014, 08:03:51 AM »

Well actually I believe Xeno had some of the first reaction thrusters in his Vacuum mod, however IIRC they mainly just sent out projectiles, and were not thrusters/flame effects.
Logged

kazi

  • Admiral
  • *****
  • Posts: 714
    • View Profile
Re: Attitude control system
« Reply #5 on: April 25, 2014, 08:58:37 AM »

Oh man, I need these (share script please?  :D). Can't wait to see when your next mod release comes out.
Logged

Uomoz

  • Admiral
  • *****
  • Posts: 2663
  • 'womo'dz
    • View Profile
Re: Attitude control system
« Reply #6 on: April 25, 2014, 09:18:13 AM »

I'd love maneuvering jets like in real spacecrafts (whiteish brief jets). Watching the Soyuz in gravity made me squeal: http://youtu.be/ViFihKF8EiM?t=21s
Logged

xangle13

  • Lieutenant
  • **
  • Posts: 68
    • View Profile
Re: Attitude control system
« Reply #7 on: April 26, 2014, 01:48:30 AM »

I use five multiframe decoration weapons to make it, tophead, frontleft, frontright, backleft, backright.
Why I chose multiframe not particle, because of particle is a rare resource, too many particle is not good.
Here is the core part of my code, have fun ;):

Code
package data.scripts.effect.additive;

import java.util.List;
import java.util.ArrayList;
import java.awt.Color;
import org.lwjgl.util.vector.Vector2f;

import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.EveryFrameWeaponEffectPlugin;
import com.fs.starfarer.api.combat.WeaponAPI;
import com.fs.starfarer.api.combat.WeaponAPI.WeaponSize;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.AnimationAPI;
import com.fs.starfarer.api.Global;

public class AttitudeControl_Effect {

private static float amountSpeed = 20f;
private static int growAmount = 7;
private static List WeaponList = new ArrayList();
static{
WeaponList.add("AttitudeControl_HT");
WeaponList.add(0);
WeaponList.add("AttitudeControl_TL");
WeaponList.add(1);
WeaponList.add("AttitudeControl_TR");
WeaponList.add(2);
WeaponList.add("AttitudeControl_BL");
WeaponList.add(3);
WeaponList.add("AttitudeControl_BR");
WeaponList.add(4);
}

private int recordAmount = 0;
private int growUpAmount = 0;
private float currentAmount = 0f;

private float currentAngularVelocity = 0f;
private Vector2f currentVelocity = new Vector2f(0f, 0f);
private boolean checkRun = false;

private int frame = 0;

public AttitudeControl_Effect(float amount, CombatEngineAPI engine, WeaponAPI weapon){
for(int i = 0;i < WeaponList.size() && !this.checkRun;i+=2){
String weaponGet = (String)WeaponList.get(i);
if(weaponGet.equals(weapon.getId())){
this.checkRun = true;
}
}
}

public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon) {
if (engine.isPaused()) return;
if(weapon.getShip().isHulk()) return;
if(!this.checkRun) return;

this.currentAmount = this.currentAmount + amount * this.amountSpeed;
if((int)this.currentAmount > this.recordAmount){
this.recordAmount = (int)this.currentAmount;
if(this.currentAmount > 100){
this.currentAmount = 0f;
this.recordAmount = 0;
}
}else{
return;
}

ShipAPI ship = weapon.getShip();
AnimationAPI animation  = weapon.getAnimation();
int value[] = new int[5];
value[0] = 0;
value[1] = 0;
value[2] = 0;
value[3] = 0;
value[4] = 0;

float angularVelocityChange = ship.getAngularVelocity() - this.currentAngularVelocity;
this.currentAngularVelocity = ship.getAngularVelocity();
if(angularVelocityChange == 0f && ship.getAngularVelocity() != 0f){
angularVelocityChange = ship.getAngularVelocity();
}

float velocityX = ship.getVelocity().getX() - this.currentVelocity.getX();
float velocityY = ship.getVelocity().getY() - this.currentVelocity.getY();
this.currentVelocity.setX(ship.getVelocity().getX());
this.currentVelocity.setY(ship.getVelocity().getY());

float wholeSize = (float)Math.sqrt(ship.getVelocity().getX() * ship.getVelocity().getX() + ship.getVelocity().getY() * ship.getVelocity().getY());
wholeSize = (wholeSize > 50f)?50f:wholeSize;

if(velocityX < wholeSize * 0.001f && velocityX > wholeSize * -0.001f){
velocityX = 0f;
}
if(velocityY < wholeSize * 0.001f && velocityY > wholeSize * -0.001f){
velocityY = 0f;
}

float velocityAngle = -1f;
if(velocityX != 0f || velocityY != 0f){

if(velocityX != 0f){
velocityAngle = (float)Math.atan((double)(velocityY / velocityX)) * (float)(180f / Math.PI);
if(velocityX < 0f){
velocityAngle = velocityAngle + 180f;
}
}else{
if(velocityY > 0f){
velocityAngle = 90f;
}else{
velocityAngle = 270f;
}
}

velocityAngle = velocityAngle - ship.getFacing();
if(velocityAngle < 0f){
velocityAngle += 360f;
}

velocityX = (float)Math.sin(velocityAngle / (180f / Math.PI));
velocityY = (float)Math.cos(velocityAngle / (180f / Math.PI));

if(velocityX < 0.01f && velocityX > -0.01f){
velocityX = 0f;
}
if(velocityY <= 0.1f && velocityY >= -0.1f){
velocityY = 0f;
}

if(velocityX > 0f){
value[2]++;
value[4]++;
}else if(velocityX < 0f){
value[1]++;
value[3]++;
}
if(velocityY < 0f){
value[0]++;
}
}

if(ship.getAngularVelocity() != this.currentAngularVelocity || ship.getAngularVelocity() != 0f){
if(angularVelocityChange > 0){
value[2]++;
value[3]++;
}else{
value[1]++;
value[4]++;
}
}

if(value[1] > 0 && value[2] > 0){
value[1] = 0;
value[2] = 0;
}
if(value[3] > 0 && value[4] > 0){
value[3] = 0;
value[4] = 0;
}

if(value[0] > 0 || value[1] > 0 || value[2] > 0 || value[3] > 0 || value[4] > 0){
for(int i = 0;i < WeaponList.size();i+=2){
String weaponGet = (String)WeaponList.get(i);
if(weaponGet.equals(weapon.getId())){
int group = (Integer)WeaponList.get(i+1);
for(;group >= 5;group-=5){}
if(value[group] > 0){
if(this.growUpAmount <= this.growAmount){
this.growUpAmount++;
this.frame = this.growUpAmount;
}else{
//this.frame++;
this.frame = this.growAmount + (int)((float)Math.random() * (float)(animation.getNumFrames() - this.growAmount - 1)) + 1;
if(this.frame >= animation.getNumFrames()){
this.frame = this.growUpAmount + 1;
}
}
animation.setFrame(this.frame);
}else{
if(this.growUpAmount > 0){
this.growUpAmount--;
this.frame = this.growUpAmount;
}else{
this.growUpAmount = 0;
this.frame = this.growUpAmount;
}
animation.setFrame(this.frame);
}
}
}
}else{
if(this.growUpAmount > 0){
this.growUpAmount--;
this.frame = this.growUpAmount;
}else{
this.growUpAmount = 0;
this.frame = this.growUpAmount;
}
animation.setFrame(this.frame);
}
}

}

Logged