Skip to content

Commit

Permalink
Added graphics client for SIM rigid body. (#1779)
Browse files Browse the repository at this point in the history
* added SIM_singlerigidbody

* Added matrix operations file.

* Imported libraries and declared variables.

* New objects and more defined values.

* Declared more variables and added AzElRot. function.

* Sockets and file connections 1

* Adding to variable server.

* Variables for the variable server.

* Variable parsing added.

* Vertex model for crewModule; need to change to sphere later.

* Body and vantage positioning functions.

* Drawing functions to create the model.

* Finished drawing functions for world.

* Changed some of the object names and variable names for sync.

* Added Makefile.

* Added POM file.

* Graphics client starter added to input file.

* Changed paths in S_define to reflect current file structure.

* More accurate cd error message in input file.

* Color hardcoded for testing purposes and getting the sim running.

* S_overrides changed to include graphics cleaning for each sim execution.

* S_define formatted for better readability.

* Changed shape to a dodecahedron.

* Path changed for input file.

* Airport commit

* New edges for dodecahedron.

* Triangle normals for the dodecahedron changed.

* Sim variable parsing fixed for functionality.

* Edges of dodecahedron fixed.

* Changed paint color for the shape to change based on location.

* Deleted unnecessary JViewport library.

* Increased length of x, y, and z axis lines.

* Increased vantage distance.

* Fixed triangles and normals.

* Commented on the edges.

* Deleted the notes file.

* Removed trick.frame_long_on() from splashdown SIM's realtime.py in modified data directory.

* Deleted sims directory (including images sub directory).

* Removed unnecessary body.hh and body.cpp from subdirectory.

* Removed unnecessary files.

---------

Co-authored-by: Wallace <[email protected]>
Co-authored-by: AdityaGirish <[email protected]>
  • Loading branch information
3 people authored Nov 12, 2024
1 parent aecf6a0 commit 0292b52
Show file tree
Hide file tree
Showing 5 changed files with 919 additions and 0 deletions.
12 changes: 12 additions & 0 deletions trick_sims/SIM_singlerigidbody/S_overrides.mk
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
TRICK_CFLAGS += -Imodels
TRICK_CXXFLAGS += -Imodels

.PHONY: clean_graphics

all: models/singlerigidbodygraphics/build/SingleRigidBodyDisplay.jar

spotless: clean_graphics

models/singlerigidbodygraphics/build/SingleRigidBodyDisplay.jar:
${MAKE} -C ./models/singlerigidbodygraphics

clean_graphics:
${MAKE} -C ./models/singlerigidbodygraphics clean
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

all:
mvn package

clean:
rm -rf build
121 changes: 121 additions & 0 deletions trick_sims/SIM_singlerigidbody/models/singlerigidbodygraphics/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>trick-java</groupId>
<artifactId>trick-java</artifactId>
<version>23.0.0-beta</version>

<name>trick-java</name>

<url>https://github.com/nasa/trick</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>

<finalName>SingleRigidBodyDisplay</finalName>

<directory>build</directory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
<destDir>../../share/doc/trick/java</destDir>
</configuration>
</plugin>
</plugins>

<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->

<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>

<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<compilerArgs>
<arg>-g</arg>
<arg>-Xlint:unchecked</arg>
<arg>-Xlint:deprecation</arg>
</compilerArgs>
</configuration>
</plugin>

<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>trick.SRBDisplay</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>

<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>

<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>

<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>

<!--
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
-->

</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// This file contains helper functions for the matrix operations necessary for the graphics to be generated.

package trick.matrixOps;



public class MatrixOps { // Defines the matrix operation class.

public static void printMatrix(double M[][]) { // Prints out the matrix.
int M_rows = M.length;
int M_cols = M[0].length;
for (int i = 0; i < M_rows; i++) {
for (int j = 0; j < M_cols; j++)
System.out.print(" " + M[i][j]);
System.out.println();
}
}

public static void printDVector(double V[]) { // Prints out a vector passed as a double.
System.out.print("(");
for (int i = 0; i < V.length; i++) {
System.out.print(" " + V[i]);
}
System.out.println(")");
}

public static void printIVector(int V[]) { // Prints out a vector passed as an integer.
System.out.print("(");
for (int i = 0; i < V.length; i++) {
System.out.print(" " + V[i]);
}
System.out.println(")");
}

public static void MtimesM( double R[][], double A[][], double B[][]) { // Multiplies two matrices together.
int A_rows = A.length;
int A_cols = A[0].length;
int B_rows = B.length;
int B_cols = B[0].length;
int R_rows = R.length;
int R_cols = R[0].length;

if (A_cols != B_rows) { // Checks if the matrices can be multiplied.
System.out.println( "\nNot possible to multiply matrixes,");
System.out.println("where the first has " + A_cols + " columns,");
System.out.println("and the second has " + B_rows + "rows.");
return;
}
if ((R_rows != A_rows) || (R_cols != B_cols)) { // Checks if the defined result matrix is the wrong size.
System.out.println( "\n Result matrix is wrong size.");
return;
}

for (int i = 0; i < A_rows; i++) { // Multiplies the two matrices together.
for (int j = 0; j < B_cols; j++) {
R[i][j] = 0.0;
for (int k = 0; k < B_rows; k++)
R[i][j] += A[i][k] * B[k][j];
}
}
}

public static void MtimesV( double R[], double M[][], double V[]) { // Multiplies a matrix with a vector.
int M_rows = M.length;
int M_cols = M[0].length;
int V_rows = V.length;

if (M_cols != V_rows) { // Checks if the matrix and the vector can be multiplied together.
System.out.println( "\nNot possible to multiply matrix and vector,");
System.out.println( "where the matrix has " + M_cols + " columns,");
System.out.println("and the vector has " + V_rows + " elements.");
return;
}

if (R.length != M.length) { // Checks if the defined result vector is the wrong size.
System.out.println( "\n Result vector is wrong size.");
return;
}

for (int i =0; i < M_rows ; i++) { // Multiplies the vector with the matrix.
R[i] = 0.0;
for (int j =0; j < M_cols ; j++) {
R[i] += M[i][j] * V[j];
}
}
return;
}

public static void VplusV(double R[], double A[], double B[]) { // Adds two matrices together.
if ((A.length != B.length) || (A.length != R.length)) {
System.out.println( "\n MatrixOps::VplusV : Vectors are not the same size.");
}
for (int i=0; i<A.length ; i++) {
R[i] = A[i] + B[i];
}
}

public static void VminusV(double R[], double A[], double B[]) { // Subtracts two matrices together.
if ((A.length != B.length) || (A.length != R.length)) {
System.out.println( "\n MatrixOps::VminusV : Vectors are not the same size.");
return;
}
for (int i=0; i<A.length ; i++) {
R[i] = A[i] - B[i];
}
}

public static void VcrossV(double R[], double A[], double B[]) { // Finds the cross product of two matrices.
if ((R.length != 3) || (A.length != 3) || (B.length != 3)) {
System.out.println( "\n MatrixOps::VcrossV : All vector args must be length 3.");
return;
}
R[0] = A[1] * B[2] - A[2] * B[1];
R[1] = A[2] * B[0] - A[0] * B[2];
R[2] = A[0] * B[1] - A[1] * B[0];
}

public static double VdotV(double A[], double B[]) { // Finds the dot product of two matrices.
if (A.length != B.length) {
System.out.println( "\n MatrixOps::VdotV : Vectors are not the same size.");
return 0.0;
}
double R = 0.0;
for (int i=0; i<A.length ; i++) {
R += A[i] * B[i];
}
return R;
}

public static void Vscale(double R[], double A[], double S) { // Scales a vector (Multiplies by a given number).
if (A.length != R.length) {
System.out.println( "\n MatrixOps::Vscale : Input and output vectors are not the same size.");
return;
}
for (int i=0; i<A.length ; i++) {
R[i] = A[i] * S;
}
}

public static double Vmagnitude (double V[]) { // Returns the magnitude of a vector (Length of a vector).
double S = 0;
for (int i =0; i < V.length ; i++) {
S += V[i]*V[i];
}
return Math.sqrt(S);
}

}




Loading

0 comments on commit 0292b52

Please sign in to comment.