Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8490939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:16:18+00:00 2026-06-10T22:16:18+00:00

typedef struct { float lifetime; // total lifetime of the particle float decay; //

  • 0
typedef struct
{
  float lifetime;                       // total lifetime of the particle
  float decay;                          // decay speed of the particle
  float r,g,b;                          // color values of the particle
  float xpos,ypos,zpos;                 // position of the particle
  float xspeed,yspeed,zspeed;           // speed of the particle
  boolean active;                       // is particle active or not?
} PARTICLE;

    void CreateParticle(int i)
    {
         particle[i].lifetime= (float)random(500000)/500000.0;
         particle[i].decay=0.001;
         particle[i].r = 0.7;
         particle[i].g = 0.7;
         particle[i].b = 1.0;
         particle[i].xpos= 0.0;
         particle[i].ypos= 0.0;
         particle[i].zpos= 0.0;
         particle[i].xspeed = 0.0005-(float)random(100)/100000.0;
         particle[i].yspeed = 0.01-(float)random(100)/100000.0;
         particle[i].zspeed = 0.0005-(float)random(100)/100000.0;
         particle[i].active = true;
    }

How would I go about doing something like this in Java? I think this looks like a good way of doing so I was hoping there is a similar solution in Java.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:16:20+00:00Added an answer on June 10, 2026 at 10:16 pm

    You could create a Particle class:

    import java.util.Random;
    
    public class Particle {
        // Data fields:
        private double lifetime;
        private double decay;
        private double r, g, b;
        private double xpos, ypos, zpos;
        private double xspeed, yspeed, zspeed;
        private boolean active;
    
        // Constructor
        public Particle() {
            r = 0.7; g = 0.7; b = 1.0;
            decay = 0.001;
            Random rand = new Random();
            lifetime = rand.nextInt(500000)/500000.0;
            xspeed = 0.0005 - rand.nextInt(100)/100000.0;
            yspeed = 0.01 - rand.nextInt(100)/100000.0;
            zspeed = 0.0005 - rand.nextInt(100)/100000.0;
            active = true; 
            // all others are 0 by default
        }
    }
    

    You can also easily make methods to return the values of your data fields, for example:

    public double lifetime() {
        return lifetime;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok so I have struct like this typedef struct { float x; float y;
I have a struct that looks like this: typedef struct _my_struct { float first_vector[SOME_NUM][OTHER_NUM];
I have defined the following struct in C: typedef struct point{ float x; float
i have this problem... i have a my struct: typedef struct Mystruct{ float a;
template struct A{ typedef float atype; typedef typename tB::btype typeB; }; template struct B{
I'm making a vector/matrix library. (GCC, ARM NEON, iPhone) typedef struct{ float v[4]; }
This is my code. struct Vector { float x, y, z, w; }; typedef
I have a nested structure as follows: typedef struct { float mz_value; float int_value;
I have two vector classes: typedef struct D3DXVECTOR3 { FLOAT x; FLOAT y; FLOAT
typedef struct { int data1; float data2; } packetType1; typedef struct { bool data1;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.