You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-20Lines changed: 20 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ This API utilizes a Utility library (found in `studios.vanish.utility`) that all
23
23
The `EventHandler` class holds multiple `Method`s, and allows one to invoke all of them at the same time through the `InvokeAll(Object... obj)` method. Throughout the Matrix Graphics Engine, `EventHandler`s are created so that the end user can specify what to do when a specific event occurs. An example of such is the `OnPaint` method. When it is time to draw objects to the screen, every method in `OnPaint` are invoked, allowing the user to render their own objects.
24
24
## GraphicsUnit
25
25
All of Java-ME's rendering capabilities are handled in the `GraphicsUnit` class. A `GraphicsUnit` object is automatically created when using the `Window` class, and is sent for use through the OnPaint event. However, you can always create a `GraphicsUnit` object, in case you want to use the 3D capabilities without initializing a `Window`.
-`RenderLights`: Specify whether to enable light based rendering, or simply render based on object color.
37
37
38
38
Many of these parameters impact the way the 3D components are drawn. `GraphicsUnit` has the capability to perform many 3D calculations that are useful to rendering, but are sometimes useful when updating a scene. Therefore, a useful `GetNullGraphics` method can be found in the `Window` class, which creates a `GraphicsUnit` object without the rendering capabilities.
Instead of manually creating a `JFrame` window, Java-ME handles it through the `Window` class. Thus, you can use Java-ME as the underlining framework for your application, as everything needed to render to the screen is already handled.
44
-
```
44
+
```java
45
45
Window window =newWindow("Java Matrix Engine", newSize(800, 600), true); //specify the name, size, and border style
46
46
```
47
47
The next lines initialize the graphical components that the window class uses by specifying the framerate, and shows the window. `Initialize3D` only needs to be called if you are going to render 3D components.
48
-
```
48
+
```java
49
49
window.Initialize(60); //specify the framerate
50
50
window.Initialize3D(newSize(800, 600), 1024, FillMode.Solid, false, false); //specify resolution, field of view, fill mode, calculate intersections (=false), automatically render all 3D objects
51
51
window.Show();
52
52
```
53
-
```
53
+
```java
54
54
window.Initialize3D();
55
55
```
56
56
To draw to the screen, you need to handle the OnPaint event.
57
-
```
57
+
```java
58
58
window.OnPaint.Add(this, "Render"); //specify the object, and the function's name
59
59
```
60
60
Don't forget to create the coinciding method. Remember that the method name must match the name you added to the `OnPaint` event handler. The method must also be public so that it can be accessed externally, and the parameters must correctly match the ones that the OnPaint method sends. In this case, `OnPaint` only sends one parameter.
61
-
```
61
+
```java
62
62
publicvoid Render(GraphicsUnitGraphics) //The Render method that will be called
63
63
```
64
64
## Sample Cube Application
65
65
Here is a sample rotating cube application.
66
-
```
66
+
```java
67
67
publicclassProgram
68
68
{
69
69
Object3D cube =newObject3D();
@@ -118,13 +118,13 @@ Unfortunately, I never planned on releasing this when I first embarked on making
118
118
Java-ME comes with a list of predefined colors. All of these colors were taken from [Rapid Tables](http://www.rapidtables.com/web/color/RGB_Color.htm).
119
119
## Color Object
120
120
You can create your own colors
121
-
```
121
+
```java
122
122
Color color =newColor(255, 255, 255); //R, G, B
123
123
Color color =newColor(255, 255, 255, 255); //R, G, B, A
124
124
```
125
125
## ColorLinearGradient
126
126
Instead of a basic solid color, this color type represents a linear gradient. You can send `ColorLinearGradient` colors to any render method, and it will be draw as a gradient. To create a `ColorLinearGradient`, you must specify a couple of things.
127
-
```
127
+
```java
128
128
ColorLinearGradient col =newColorLinearGradient(2); //How many times are you going to change the color?
129
129
col.Set(0, newPoint(0, 0), Color.Black); //Where is the first color, and what is that color?
130
130
col.Set(1, newPoint(800, 500), Color.Blue); //Where is the second color, and what is that color?
@@ -156,13 +156,13 @@ Java-ME comes with an abstract `Shape` class, that specifies an `Intersects` and
156
156
- Circle
157
157
158
158
You can render a rectangle by using the rectangle class.
You can do hit-detection by calling the `Intersects` method.
165
-
```
165
+
```java
166
166
if (shape1.Intersects(shape2))
167
167
{
168
168
//do something special, because the objects have collided
@@ -178,28 +178,28 @@ All of the 3D methods in `GraphicsUnit` have the `D3D_` identifier before them.
178
178
To render a 3D object effectively, use the `Object3D` class. This will ensure that any object rendered exactly as specified and that they will be rendered according to their Z axis, as this will automatically implement a Z Buffer. Transformations will also be self-contained, easy to manage, and fast. To create an `Object3D`, you need to specify the object's faces, and colors.
179
179
180
180
When creating an object, you need to specify every vertex that will be used. Identify these vertices within the vertices array object.
181
-
```
181
+
```java
182
182
object.Vertices=newVertex[]
183
183
{
184
184
//Include every single vertex here
185
185
};
186
186
```
187
187
Next, you define a face through the Indices array object. An `Index` object takes as many integer values as it takes to define a face. It takes at minimum 4 vertices to define a face. Each integer value in `Index` corresponds to the index value of the vertex.
188
-
```
188
+
```java
189
189
object.Indices=newIndex[]
190
190
{
191
191
//Include every face here
192
192
};
193
193
```
194
194
Finally, you need to define the color for each face. Note that the following condition must be met: `object.Colors.length = object.Indices.length`.
195
-
```
195
+
```java
196
196
object.Colors=newColor[]
197
197
{
198
198
//Include the colors of each face here
199
199
};
200
200
```
201
201
The following code will generate a 3D Cube.
202
-
```
202
+
```java
203
203
Object3D object =newObject3D();
204
204
object.Vertices=newVertex[]
205
205
{
@@ -220,23 +220,23 @@ obj1.Colors = new Color[]
220
220
};
221
221
```
222
222
Finally, render the object by using the render method.
223
-
```
223
+
```java
224
224
object.Render(Graphics); //where Graphics is a GraphicsUnit object
225
225
```
226
226
If in `Initialize3D`, you disable AutomaticRender, you need to manually render the 3D objects.
227
-
```
227
+
```java
228
228
Graphics.Render(); //where Graphics is a GraphicsUnit object
229
229
```
230
230
Each `Object3D` object comes with variables that specify transformations.
231
-
```
231
+
```java
232
232
object.Location=newVertex(0, 0, 10); //translates the object
233
233
object.Rotation=newVertex(10, 10, 10); //rotates the object
234
234
object.Scale=newVertex(1, 1, 1); //scales the object. Values between 0 and 1 make it smaller, while values greater than 1 make it larger
235
235
object.Revolution=newVertex(10, 10, 10); //revolves the object around its location. Note that this only works when RevolutionRadius is specified
236
236
object.RevolutionRadius=newVertex(0, 4, 0); //specifies how to revolve the object
237
237
```
238
238
Java-ME comes with a special `Object3D` class called `Sphere`, which automatically generates the vertices and indices for a sphere or cylinder.
239
-
```
239
+
```java
240
240
Object3D sphere =newSphere(10, 10, false, Color.White); //generate a sphere with 10 by 10 definition
241
241
Object3D cylinder =newSphere(10, 10, true, Color.White); //generate a cylinder with 10 by 10 definition
0 commit comments