Skip to content

Commit 0292b52

Browse files
adityagirishworkWallaceAdityaGirish
authored
Added graphics client for SIM rigid body. (#1779)
* 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]>
1 parent aecf6a0 commit 0292b52

File tree

5 files changed

+919
-0
lines changed

5 files changed

+919
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
TRICK_CFLAGS += -Imodels
22
TRICK_CXXFLAGS += -Imodels
3+
4+
.PHONY: clean_graphics
5+
6+
all: models/singlerigidbodygraphics/build/SingleRigidBodyDisplay.jar
7+
8+
spotless: clean_graphics
9+
10+
models/singlerigidbodygraphics/build/SingleRigidBodyDisplay.jar:
11+
${MAKE} -C ./models/singlerigidbodygraphics
12+
13+
clean_graphics:
14+
${MAKE} -C ./models/singlerigidbodygraphics clean
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
all:
3+
mvn package
4+
5+
clean:
6+
rm -rf build
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>trick-java</groupId>
8+
<artifactId>trick-java</artifactId>
9+
<version>23.0.0-beta</version>
10+
11+
<name>trick-java</name>
12+
13+
<url>https://github.com/nasa/trick</url>
14+
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<maven.compiler.source>1.8</maven.compiler.source>
18+
<maven.compiler.target>1.8</maven.compiler.target>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>junit</groupId>
24+
<artifactId>junit</artifactId>
25+
<version>4.13.1</version>
26+
<scope>test</scope>
27+
</dependency>
28+
</dependencies>
29+
30+
<build>
31+
32+
<finalName>SingleRigidBodyDisplay</finalName>
33+
34+
<directory>build</directory>
35+
<plugins>
36+
<plugin>
37+
<groupId>org.apache.maven.plugins</groupId>
38+
<artifactId>maven-javadoc-plugin</artifactId>
39+
<version>3.1.1</version>
40+
<configuration>
41+
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
42+
<destDir>../../share/doc/trick/java</destDir>
43+
</configuration>
44+
</plugin>
45+
</plugins>
46+
47+
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
48+
49+
<plugins>
50+
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
51+
<plugin>
52+
<artifactId>maven-clean-plugin</artifactId>
53+
<version>3.1.0</version>
54+
</plugin>
55+
56+
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
57+
<plugin>
58+
<artifactId>maven-resources-plugin</artifactId>
59+
<version>3.0.2</version>
60+
</plugin>
61+
62+
<plugin>
63+
<artifactId>maven-compiler-plugin</artifactId>
64+
<version>3.8.0</version>
65+
<configuration>
66+
<compilerArgs>
67+
<arg>-g</arg>
68+
<arg>-Xlint:unchecked</arg>
69+
<arg>-Xlint:deprecation</arg>
70+
</compilerArgs>
71+
</configuration>
72+
</plugin>
73+
74+
<plugin>
75+
<!-- Build an executable JAR -->
76+
<groupId>org.apache.maven.plugins</groupId>
77+
<artifactId>maven-jar-plugin</artifactId>
78+
<version>3.1.0</version>
79+
<configuration>
80+
<archive>
81+
<manifest>
82+
<addClasspath>true</addClasspath>
83+
<classpathPrefix>lib/</classpathPrefix>
84+
<mainClass>trick.SRBDisplay</mainClass>
85+
</manifest>
86+
</archive>
87+
</configuration>
88+
</plugin>
89+
90+
<plugin>
91+
<artifactId>maven-surefire-plugin</artifactId>
92+
<version>2.22.1</version>
93+
</plugin>
94+
95+
<plugin>
96+
<artifactId>maven-install-plugin</artifactId>
97+
<version>2.5.2</version>
98+
</plugin>
99+
100+
<plugin>
101+
<artifactId>maven-deploy-plugin</artifactId>
102+
<version>2.8.2</version>
103+
</plugin>
104+
105+
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
106+
<plugin>
107+
<artifactId>maven-site-plugin</artifactId>
108+
<version>3.7.1</version>
109+
</plugin>
110+
111+
<!--
112+
<plugin>
113+
<artifactId>maven-project-info-reports-plugin</artifactId>
114+
<version>3.0.0</version>
115+
</plugin>
116+
-->
117+
118+
</plugins>
119+
</pluginManagement>
120+
</build>
121+
</project>
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
// This file contains helper functions for the matrix operations necessary for the graphics to be generated.
2+
3+
package trick.matrixOps;
4+
5+
6+
7+
public class MatrixOps { // Defines the matrix operation class.
8+
9+
public static void printMatrix(double M[][]) { // Prints out the matrix.
10+
int M_rows = M.length;
11+
int M_cols = M[0].length;
12+
for (int i = 0; i < M_rows; i++) {
13+
for (int j = 0; j < M_cols; j++)
14+
System.out.print(" " + M[i][j]);
15+
System.out.println();
16+
}
17+
}
18+
19+
public static void printDVector(double V[]) { // Prints out a vector passed as a double.
20+
System.out.print("(");
21+
for (int i = 0; i < V.length; i++) {
22+
System.out.print(" " + V[i]);
23+
}
24+
System.out.println(")");
25+
}
26+
27+
public static void printIVector(int V[]) { // Prints out a vector passed as an integer.
28+
System.out.print("(");
29+
for (int i = 0; i < V.length; i++) {
30+
System.out.print(" " + V[i]);
31+
}
32+
System.out.println(")");
33+
}
34+
35+
public static void MtimesM( double R[][], double A[][], double B[][]) { // Multiplies two matrices together.
36+
int A_rows = A.length;
37+
int A_cols = A[0].length;
38+
int B_rows = B.length;
39+
int B_cols = B[0].length;
40+
int R_rows = R.length;
41+
int R_cols = R[0].length;
42+
43+
if (A_cols != B_rows) { // Checks if the matrices can be multiplied.
44+
System.out.println( "\nNot possible to multiply matrixes,");
45+
System.out.println("where the first has " + A_cols + " columns,");
46+
System.out.println("and the second has " + B_rows + "rows.");
47+
return;
48+
}
49+
if ((R_rows != A_rows) || (R_cols != B_cols)) { // Checks if the defined result matrix is the wrong size.
50+
System.out.println( "\n Result matrix is wrong size.");
51+
return;
52+
}
53+
54+
for (int i = 0; i < A_rows; i++) { // Multiplies the two matrices together.
55+
for (int j = 0; j < B_cols; j++) {
56+
R[i][j] = 0.0;
57+
for (int k = 0; k < B_rows; k++)
58+
R[i][j] += A[i][k] * B[k][j];
59+
}
60+
}
61+
}
62+
63+
public static void MtimesV( double R[], double M[][], double V[]) { // Multiplies a matrix with a vector.
64+
int M_rows = M.length;
65+
int M_cols = M[0].length;
66+
int V_rows = V.length;
67+
68+
if (M_cols != V_rows) { // Checks if the matrix and the vector can be multiplied together.
69+
System.out.println( "\nNot possible to multiply matrix and vector,");
70+
System.out.println( "where the matrix has " + M_cols + " columns,");
71+
System.out.println("and the vector has " + V_rows + " elements.");
72+
return;
73+
}
74+
75+
if (R.length != M.length) { // Checks if the defined result vector is the wrong size.
76+
System.out.println( "\n Result vector is wrong size.");
77+
return;
78+
}
79+
80+
for (int i =0; i < M_rows ; i++) { // Multiplies the vector with the matrix.
81+
R[i] = 0.0;
82+
for (int j =0; j < M_cols ; j++) {
83+
R[i] += M[i][j] * V[j];
84+
}
85+
}
86+
return;
87+
}
88+
89+
public static void VplusV(double R[], double A[], double B[]) { // Adds two matrices together.
90+
if ((A.length != B.length) || (A.length != R.length)) {
91+
System.out.println( "\n MatrixOps::VplusV : Vectors are not the same size.");
92+
}
93+
for (int i=0; i<A.length ; i++) {
94+
R[i] = A[i] + B[i];
95+
}
96+
}
97+
98+
public static void VminusV(double R[], double A[], double B[]) { // Subtracts two matrices together.
99+
if ((A.length != B.length) || (A.length != R.length)) {
100+
System.out.println( "\n MatrixOps::VminusV : Vectors are not the same size.");
101+
return;
102+
}
103+
for (int i=0; i<A.length ; i++) {
104+
R[i] = A[i] - B[i];
105+
}
106+
}
107+
108+
public static void VcrossV(double R[], double A[], double B[]) { // Finds the cross product of two matrices.
109+
if ((R.length != 3) || (A.length != 3) || (B.length != 3)) {
110+
System.out.println( "\n MatrixOps::VcrossV : All vector args must be length 3.");
111+
return;
112+
}
113+
R[0] = A[1] * B[2] - A[2] * B[1];
114+
R[1] = A[2] * B[0] - A[0] * B[2];
115+
R[2] = A[0] * B[1] - A[1] * B[0];
116+
}
117+
118+
public static double VdotV(double A[], double B[]) { // Finds the dot product of two matrices.
119+
if (A.length != B.length) {
120+
System.out.println( "\n MatrixOps::VdotV : Vectors are not the same size.");
121+
return 0.0;
122+
}
123+
double R = 0.0;
124+
for (int i=0; i<A.length ; i++) {
125+
R += A[i] * B[i];
126+
}
127+
return R;
128+
}
129+
130+
public static void Vscale(double R[], double A[], double S) { // Scales a vector (Multiplies by a given number).
131+
if (A.length != R.length) {
132+
System.out.println( "\n MatrixOps::Vscale : Input and output vectors are not the same size.");
133+
return;
134+
}
135+
for (int i=0; i<A.length ; i++) {
136+
R[i] = A[i] * S;
137+
}
138+
}
139+
140+
public static double Vmagnitude (double V[]) { // Returns the magnitude of a vector (Length of a vector).
141+
double S = 0;
142+
for (int i =0; i < V.length ; i++) {
143+
S += V[i]*V[i];
144+
}
145+
return Math.sqrt(S);
146+
}
147+
148+
}
149+
150+
151+
152+

0 commit comments

Comments
 (0)