[FEAT] continue maven integration
This commit is contained in:
parent
b2c0eb7da6
commit
0baab98804
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
|
||||
<fileset name="all" enabled="true" check-config-name="Ewol" local="false">
|
||||
<fileset name="all" enabled="true" check-config-name="Google Checks" local="false">
|
||||
<file-match-pattern match-pattern="." include-pattern="true"/>
|
||||
</fileset>
|
||||
</fileset-config>
|
||||
|
27
.classpath
27
.classpath
@ -1,27 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry including="**/*.java" kind="src" output="out/maven/classes" path="src">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="out/maven/test-classes" path="test/src">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="out/maven/classes"/>
|
||||
</classpath>
|
23
.project
23
.project
@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ege</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
18
pom.xml
18
pom.xml
@ -44,15 +44,21 @@
|
||||
<version>0.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.9.3</version>
|
||||
<scope>test</scope>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.11.0-M2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.11.0-M2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>2.0.7</version>
|
||||
<version>2.1.0-alpha1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@ -60,7 +66,6 @@
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<testSourceDirectory>test/src</testSourceDirectory>
|
||||
<directory>${project.basedir}/out/maven/</directory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@ -76,6 +81,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.3.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
|
@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/atriasoft-ege">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/atriasoft-etk">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
1
samples/.gitignore
vendored
1
samples/.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
|
||||
/__pycache__/
|
||||
/bin/
|
||||
/target/
|
||||
|
@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>atriasoft-ege-samples</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1646149232189</id>
|
||||
<name></name>
|
||||
<type>30</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
@ -1,141 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
|
||||
org.eclipse.jdt.ui.text.custom_code_templates=
|
||||
sp_cleanup.add_all=false
|
||||
sp_cleanup.add_default_serial_version_id=true
|
||||
sp_cleanup.add_generated_serial_version_id=false
|
||||
sp_cleanup.add_missing_annotations=true
|
||||
sp_cleanup.add_missing_deprecated_annotations=true
|
||||
sp_cleanup.add_missing_methods=false
|
||||
sp_cleanup.add_missing_nls_tags=false
|
||||
sp_cleanup.add_missing_override_annotations=true
|
||||
sp_cleanup.add_missing_override_annotations_interface_methods=true
|
||||
sp_cleanup.add_serial_version_id=false
|
||||
sp_cleanup.always_use_blocks=true
|
||||
sp_cleanup.always_use_parentheses_in_expressions=false
|
||||
sp_cleanup.always_use_this_for_non_static_field_access=true
|
||||
sp_cleanup.always_use_this_for_non_static_method_access=false
|
||||
sp_cleanup.array_with_curly=true
|
||||
sp_cleanup.arrays_fill=true
|
||||
sp_cleanup.bitwise_conditional_expression=false
|
||||
sp_cleanup.boolean_literal=false
|
||||
sp_cleanup.boolean_value_rather_than_comparison=false
|
||||
sp_cleanup.break_loop=false
|
||||
sp_cleanup.collection_cloning=true
|
||||
sp_cleanup.comparing_on_criteria=true
|
||||
sp_cleanup.comparison_statement=false
|
||||
sp_cleanup.controlflow_merge=false
|
||||
sp_cleanup.convert_functional_interfaces=true
|
||||
sp_cleanup.convert_to_enhanced_for_loop=false
|
||||
sp_cleanup.convert_to_enhanced_for_loop_if_loop_var_used=false
|
||||
sp_cleanup.convert_to_switch_expressions=true
|
||||
sp_cleanup.correct_indentation=true
|
||||
sp_cleanup.do_while_rather_than_while=false
|
||||
sp_cleanup.double_negation=false
|
||||
sp_cleanup.else_if=false
|
||||
sp_cleanup.embedded_if=false
|
||||
sp_cleanup.evaluate_nullable=false
|
||||
sp_cleanup.extract_increment=false
|
||||
sp_cleanup.format_source_code=true
|
||||
sp_cleanup.format_source_code_changes_only=false
|
||||
sp_cleanup.hash=false
|
||||
sp_cleanup.if_condition=true
|
||||
sp_cleanup.insert_inferred_type_arguments=false
|
||||
sp_cleanup.instanceof=true
|
||||
sp_cleanup.instanceof_keyword=false
|
||||
sp_cleanup.invert_equals=false
|
||||
sp_cleanup.join=true
|
||||
sp_cleanup.lazy_logical_operator=false
|
||||
sp_cleanup.make_local_variable_final=true
|
||||
sp_cleanup.make_parameters_final=false
|
||||
sp_cleanup.make_private_fields_final=true
|
||||
sp_cleanup.make_type_abstract_if_missing_method=false
|
||||
sp_cleanup.make_variable_declarations_final=false
|
||||
sp_cleanup.map_cloning=true
|
||||
sp_cleanup.merge_conditional_blocks=false
|
||||
sp_cleanup.multi_catch=true
|
||||
sp_cleanup.never_use_blocks=false
|
||||
sp_cleanup.never_use_parentheses_in_expressions=true
|
||||
sp_cleanup.no_string_creation=false
|
||||
sp_cleanup.no_super=true
|
||||
sp_cleanup.number_suffix=false
|
||||
sp_cleanup.objects_equals=true
|
||||
sp_cleanup.on_save_use_additional_actions=true
|
||||
sp_cleanup.one_if_rather_than_duplicate_blocks_that_fall_through=false
|
||||
sp_cleanup.operand_factorization=false
|
||||
sp_cleanup.organize_imports=true
|
||||
sp_cleanup.overridden_assignment=false
|
||||
sp_cleanup.plain_replacement=false
|
||||
sp_cleanup.precompile_regex=false
|
||||
sp_cleanup.primitive_comparison=false
|
||||
sp_cleanup.primitive_parsing=false
|
||||
sp_cleanup.primitive_rather_than_wrapper=false
|
||||
sp_cleanup.primitive_serialization=false
|
||||
sp_cleanup.pull_out_if_from_if_else=true
|
||||
sp_cleanup.pull_up_assignment=false
|
||||
sp_cleanup.push_down_negation=false
|
||||
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
|
||||
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=false
|
||||
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=false
|
||||
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
|
||||
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
|
||||
sp_cleanup.reduce_indentation=false
|
||||
sp_cleanup.redundant_comparator=false
|
||||
sp_cleanup.redundant_falling_through_block_end=false
|
||||
sp_cleanup.remove_private_constructors=true
|
||||
sp_cleanup.remove_redundant_modifiers=true
|
||||
sp_cleanup.remove_redundant_semicolons=true
|
||||
sp_cleanup.remove_redundant_type_arguments=true
|
||||
sp_cleanup.remove_trailing_whitespaces=true
|
||||
sp_cleanup.remove_trailing_whitespaces_all=false
|
||||
sp_cleanup.remove_trailing_whitespaces_ignore_empty=true
|
||||
sp_cleanup.remove_unnecessary_array_creation=true
|
||||
sp_cleanup.remove_unnecessary_casts=true
|
||||
sp_cleanup.remove_unnecessary_nls_tags=false
|
||||
sp_cleanup.remove_unused_imports=true
|
||||
sp_cleanup.remove_unused_local_variables=false
|
||||
sp_cleanup.remove_unused_private_fields=true
|
||||
sp_cleanup.remove_unused_private_members=false
|
||||
sp_cleanup.remove_unused_private_methods=true
|
||||
sp_cleanup.remove_unused_private_types=true
|
||||
sp_cleanup.return_expression=false
|
||||
sp_cleanup.simplify_lambda_expression_and_method_ref=false
|
||||
sp_cleanup.single_used_field=false
|
||||
sp_cleanup.sort_members=true
|
||||
sp_cleanup.sort_members_all=false
|
||||
sp_cleanup.standard_comparison=false
|
||||
sp_cleanup.static_inner_class=false
|
||||
sp_cleanup.strictly_equal_or_different=false
|
||||
sp_cleanup.stringbuffer_to_stringbuilder=false
|
||||
sp_cleanup.stringbuilder=true
|
||||
sp_cleanup.stringbuilder_for_local_vars=true
|
||||
sp_cleanup.stringconcat_to_textblock=true
|
||||
sp_cleanup.substring=false
|
||||
sp_cleanup.switch=false
|
||||
sp_cleanup.system_property=false
|
||||
sp_cleanup.system_property_boolean=false
|
||||
sp_cleanup.system_property_file_encoding=false
|
||||
sp_cleanup.system_property_file_separator=false
|
||||
sp_cleanup.system_property_line_separator=false
|
||||
sp_cleanup.system_property_path_separator=false
|
||||
sp_cleanup.ternary_operator=false
|
||||
sp_cleanup.try_with_resource=false
|
||||
sp_cleanup.unlooped_while=false
|
||||
sp_cleanup.unreachable_block=false
|
||||
sp_cleanup.use_anonymous_class_creation=false
|
||||
sp_cleanup.use_autoboxing=false
|
||||
sp_cleanup.use_blocks=false
|
||||
sp_cleanup.use_blocks_only_for_return_and_throw=false
|
||||
sp_cleanup.use_directly_map_method=true
|
||||
sp_cleanup.use_lambda=true
|
||||
sp_cleanup.use_parentheses_in_expressions=false
|
||||
sp_cleanup.use_string_is_blank=false
|
||||
sp_cleanup.use_this_for_non_static_field_access=true
|
||||
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=false
|
||||
sp_cleanup.use_this_for_non_static_method_access=false
|
||||
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
|
||||
sp_cleanup.use_unboxing=false
|
||||
sp_cleanup.use_var=false
|
||||
sp_cleanup.useless_continue=true
|
||||
sp_cleanup.useless_return=true
|
||||
sp_cleanup.valueof_rather_than_instantiation=false
|
@ -1,2 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
|
@ -44,8 +44,11 @@ import org.atriasoft.gale.key.KeyStatus;
|
||||
import org.atriasoft.gale.key.KeyType;
|
||||
import org.atriasoft.gale.resource.ResourceColored3DObject;
|
||||
import org.atriasoft.phyligram.PhysicBox;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CollisionTestApplication extends GaleApplication {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(CollisionTestApplication.class);
|
||||
public static Vector3f box1HalfSize;
|
||||
public static Vector3f box2HalfSize;
|
||||
// public static ComponentPosition relativeTestPos;
|
||||
@ -88,7 +91,8 @@ public class CollisionTestApplication extends GaleApplication {
|
||||
// simple sun to have a global light ...
|
||||
final Entity sun = new Entity(this.env);
|
||||
sun.addComponent(new ComponentPosition(new Transform3D(new Vector3f(1000, 1000, 1000))));
|
||||
sun.addComponent(new ComponentLightSun(new Light(new Color(0.4f, 0.4f, 0.4f), Vector3f.ZERO, new Vector3f(0.8f, 0, 0))));
|
||||
sun.addComponent(
|
||||
new ComponentLightSun(new Light(new Color(0.4f, 0.4f, 0.4f), Vector3f.ZERO, new Vector3f(0.8f, 0, 0))));
|
||||
this.env.addEntity(sun);
|
||||
|
||||
// add a cube to show where in the light ...
|
||||
@ -109,7 +113,8 @@ public class CollisionTestApplication extends GaleApplication {
|
||||
orientation = orientation.normalize();
|
||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/dirt.png", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"),
|
||||
new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentPosition(new Transform3D(Vector3f.ZERO, orientation)));
|
||||
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
||||
physics2.setBodyType(PhysicBodyType.BODY_STATIC);
|
||||
@ -148,7 +153,8 @@ public class CollisionTestApplication extends GaleApplication {
|
||||
final Entity gird = new Entity(this.env);
|
||||
gird.addComponent(new ComponentPosition(new Transform3D(Vector3f.ZERO)));
|
||||
gird.addComponent(new ComponentStaticMesh(MeshGenerator.createGrid(5)));
|
||||
gird.addComponent(new ComponentRenderColoredStaticMesh(new Uri("DATA", "wireColor.vert", "ege"), new Uri("DATA", "wireColor.frag", "ege")));
|
||||
gird.addComponent(new ComponentRenderColoredStaticMesh(new Uri("DATA", "wireColor.vert", "ege"),
|
||||
new Uri("DATA", "wireColor.frag", "ege")));
|
||||
this.env.addEntity(gird);
|
||||
|
||||
final Entity player = new Entity(this.env);
|
||||
@ -221,29 +227,43 @@ public class CollisionTestApplication extends GaleApplication {
|
||||
final Vector3f elem = CollisionTestApplication.testPoints.get(iii);
|
||||
final boolean collide = CollisionTestApplication.testPointsCollide.get(iii);
|
||||
if (collide) {
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f),
|
||||
Matrix4f.IDENTITY.multiply(
|
||||
Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
new Color(1, 0, 0, 1));
|
||||
} else if (iii == 0) {
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f),
|
||||
Matrix4f.IDENTITY.multiply(
|
||||
Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
new Color(0, 1, 0, 1));
|
||||
} else if (iii == 7) {
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f),
|
||||
Matrix4f.IDENTITY.multiply(
|
||||
Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
new Color(1, 1, 0, 1));
|
||||
} else {
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f),
|
||||
Matrix4f.IDENTITY.multiply(
|
||||
Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
new Color(1, 1, 1, 1));
|
||||
}
|
||||
}
|
||||
for (int iii = 0; iii < CollisionTestApplication.testPointsBox.size(); iii++) {
|
||||
final Vector3f elem = CollisionTestApplication.testPointsBox.get(iii);
|
||||
if (iii == 0) {
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f),
|
||||
Matrix4f.IDENTITY.multiply(
|
||||
Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
new Color(0, 1, 0, 1));
|
||||
} else if (iii == 7) {
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f),
|
||||
Matrix4f.IDENTITY.multiply(
|
||||
Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
new Color(1, 1, 0, 1));
|
||||
} else {
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f),
|
||||
Matrix4f.IDENTITY.multiply(
|
||||
Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
new Color(0, 0, 1, 1));
|
||||
}
|
||||
}
|
||||
@ -254,13 +274,17 @@ public class CollisionTestApplication extends GaleApplication {
|
||||
//Matrix4f transformation = testQTransfert.getMatrix4().multiply(Matrix4f.createMatrixTranslate(new Vector3f(testRpos.x,testRpos.y,testRpos.z))).multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,14)));
|
||||
//Matrix4f transformation = testQTransfert.getMatrix4().multiply(Matrix4f.createMatrixTranslate(new Vector3f(testRpos.x,testRpos.y,testRpos.z))).multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,14)));
|
||||
final Matrix4f transformation = Matrix4f
|
||||
.createMatrixTranslate(new Vector3f(CollisionTestApplication.testRpos.x(), CollisionTestApplication.testRpos.y(), CollisionTestApplication.testRpos.z()))
|
||||
.multiply(Matrix4f.createMatrixTranslate(new Vector3f(0, 0, 14))).multiply(CollisionTestApplication.testQTransfert.getMatrix4());
|
||||
.createMatrixTranslate(new Vector3f(CollisionTestApplication.testRpos.x(),
|
||||
CollisionTestApplication.testRpos.y(), CollisionTestApplication.testRpos.z()))
|
||||
.multiply(Matrix4f.createMatrixTranslate(new Vector3f(0, 0, 14)))
|
||||
.multiply(CollisionTestApplication.testQTransfert.getMatrix4());
|
||||
// OK sans la box1 orientation ...
|
||||
//Matrix4f transformation = Matrix4f.createMatrixTranslate(new Vector3f(testRpos.x,testRpos.y,testRpos.z)).multiply(testQTransfert.getMatrix4()).multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,14)));
|
||||
//Matrix4f transformation = Matrix4f.createMatrixTranslate(new Vector3f(testRpos.x,testRpos.y,testRpos.z)).multiply(testQTransfert.getMatrix4()).multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,14)));
|
||||
this.debugDrawProperty.drawSquare(CollisionTestApplication.box2HalfSize, transformation, new Color(0, 1, 0, 0.5f));
|
||||
this.debugDrawProperty.drawSquare(CollisionTestApplication.box1HalfSize, Matrix4f.createMatrixTranslate(new Vector3f(0, 0, 14)), new Color(0, 0, 1, 0.5f));
|
||||
this.debugDrawProperty.drawSquare(CollisionTestApplication.box2HalfSize, transformation,
|
||||
new Color(0, 1, 0, 0.5f));
|
||||
this.debugDrawProperty.drawSquare(CollisionTestApplication.box1HalfSize,
|
||||
Matrix4f.createMatrixTranslate(new Vector3f(0, 0, 14)), new Color(0, 0, 1, 0.5f));
|
||||
}
|
||||
|
||||
// Restore context of matrix
|
||||
@ -268,7 +292,11 @@ public class CollisionTestApplication extends GaleApplication {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyboard(final KeySpecial special, final KeyKeyboard type, final Character value, final KeyStatus state) {
|
||||
public void onKeyboard(
|
||||
final KeySpecial special,
|
||||
final KeyKeyboard type,
|
||||
final Character value,
|
||||
final KeyStatus state) {
|
||||
if (type == KeyKeyboard.F1) {
|
||||
Gale.getContext().grabPointerEvents(false, new Vector2f(0, 0));
|
||||
}
|
||||
@ -282,7 +310,12 @@ public class CollisionTestApplication extends GaleApplication {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPointer(final KeySpecial special, final KeyType type, final int pointerID, final Vector2f pos, final KeyStatus state) {
|
||||
public void onPointer(
|
||||
final KeySpecial special,
|
||||
final KeyType type,
|
||||
final int pointerID,
|
||||
final Vector2f pos,
|
||||
final KeyStatus state) {
|
||||
this.env.onPointer(special, type, pointerID, new Vector3f(pos.x(), pos.y(), 0), state);
|
||||
}
|
||||
|
||||
@ -290,7 +323,8 @@ public class CollisionTestApplication extends GaleApplication {
|
||||
public void onRegenerateDisplay(final GaleContext context) {
|
||||
//LOGGER.trace("Regenerate Gale Application");
|
||||
this.angleLight += 0.01;
|
||||
final Vector3f posss = this.lightPosition.getTransform().getPosition().add(new Vector3f(5 + (float) Math.cos(this.angleLight) * 7.0f, 5 + (float) Math.sin(this.angleLight) * 7.0f, 0));
|
||||
final Vector3f posss = this.lightPosition.getTransform().getPosition().add(new Vector3f(
|
||||
5 + (float) Math.cos(this.angleLight) * 7.0f, 5 + (float) Math.sin(this.angleLight) * 7.0f, 0));
|
||||
this.lightPosition.setTransform(this.lightPosition.getTransform().withPosition(posss));
|
||||
this.env.periodicCall();
|
||||
markDrawingIsNeeded();
|
||||
|
@ -1,39 +0,0 @@
|
||||
package sample.atriasoft.ege.collisiontest;
|
||||
|
||||
public class Log {
|
||||
private static final String LIBNAME = "LoxelEngine";
|
||||
|
||||
public static void critical(String data) {
|
||||
System.out.println("[C] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void debug(String data) {
|
||||
System.out.println("[D] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void error(String data) {
|
||||
System.out.println("[E] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void info(String data) {
|
||||
System.out.println("[I] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void print(String data) {
|
||||
System.out.println(data);
|
||||
}
|
||||
|
||||
public static void todo(String data) {
|
||||
System.out.println("[TODO] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void verbose(String data) {
|
||||
System.out.println("[V] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void warning(String data) {
|
||||
System.out.println("[W] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
private Log() {}
|
||||
}
|
@ -33,8 +33,11 @@ import org.atriasoft.gale.key.KeyKeyboard;
|
||||
import org.atriasoft.gale.key.KeySpecial;
|
||||
import org.atriasoft.gale.key.KeyStatus;
|
||||
import org.atriasoft.gale.key.KeyType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class LightTestApplication extends GaleApplication {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(LightTestApplication.class);
|
||||
private float angleLight = 0;
|
||||
private Quaternion basicRotation = Quaternion.IDENTITY;
|
||||
private Quaternion basicRotation2 = Quaternion.IDENTITY;
|
||||
@ -61,7 +64,8 @@ public class LightTestApplication extends GaleApplication {
|
||||
// simple sun to have a global light ...
|
||||
final Entity sun = new Entity(this.env);
|
||||
sun.addComponent(new ComponentPosition(new Transform3D(new Vector3f(1000, 1000, 1000))));
|
||||
sun.addComponent(new ComponentLightSun(new Light(new Color(0.4f, 0.4f, 0.4f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0, 0))));
|
||||
sun.addComponent(new ComponentLightSun(
|
||||
new Light(new Color(0.4f, 0.4f, 0.4f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0, 0))));
|
||||
this.env.addEntity(sun);
|
||||
|
||||
// add a cube to show where in the light ...
|
||||
@ -70,14 +74,17 @@ public class LightTestApplication extends GaleApplication {
|
||||
localLight.addComponent(this.lightPosition);
|
||||
localLight.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||
localLight.addComponent(new ComponentTexture(new Uri("RES", "grass.png")));
|
||||
localLight.addComponent(new ComponentLight(new Light(new Color(0.0f, 2.0f, 0.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.01f, 0.002f))));
|
||||
localLight.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localLight.addComponent(new ComponentLight(
|
||||
new Light(new Color(0.0f, 2.0f, 0.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.01f, 0.002f))));
|
||||
localLight.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"),
|
||||
new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
this.env.addEntity(localLight);
|
||||
|
||||
final Entity gird = new Entity(this.env);
|
||||
gird.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0, 0, 0))));
|
||||
gird.addComponent(new ComponentStaticMesh(MeshGenerator.createGrid(5)));
|
||||
gird.addComponent(new ComponentRenderColoredStaticMesh(new Uri("DATA", "wireColor.vert", "ege"), new Uri("DATA", "wireColor.frag", "ege")));
|
||||
gird.addComponent(new ComponentRenderColoredStaticMesh(new Uri("DATA", "wireColor.vert", "ege"),
|
||||
new Uri("DATA", "wireColor.frag", "ege")));
|
||||
this.env.addEntity(gird);
|
||||
|
||||
final Entity basicTree = new Entity(this.env);
|
||||
@ -88,8 +95,10 @@ public class LightTestApplication extends GaleApplication {
|
||||
basicTree.addComponent(new ComponentStaticMesh(new Uri("RES", "cube.obj")));
|
||||
basicTree.addComponent(new ComponentTexture(new Uri("RES", "mud.png")));
|
||||
//basicTree.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
basicTree.addComponent(new ComponentRenderTexturedMaterialsStaticMesh(new Uri("DATA", "basicMaterial.vert", "loxelEngine"), new Uri("DATA", "basicMaterial.frag", "loxelEngine"),
|
||||
(EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME)));
|
||||
basicTree.addComponent(
|
||||
new ComponentRenderTexturedMaterialsStaticMesh(new Uri("DATA", "basicMaterial.vert", "loxelEngine"),
|
||||
new Uri("DATA", "basicMaterial.frag", "loxelEngine"),
|
||||
(EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME)));
|
||||
this.env.addEntity(basicTree);
|
||||
|
||||
for (int xxx = -10; xxx < 10; xxx++) {
|
||||
@ -99,7 +108,9 @@ public class LightTestApplication extends GaleApplication {
|
||||
superGrass.addComponent(new ComponentMaterial(new Material()));
|
||||
superGrass.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||
superGrass.addComponent(new ComponentTexture(new Uri("RES", "dirt.png")));
|
||||
superGrass.addComponent(new ComponentRenderTexturedMaterialsStaticMesh(new Uri("DATA", "basicMaterial.vert", "loxelEngine"), new Uri("DATA", "basicMaterial.frag", "loxelEngine"),
|
||||
superGrass.addComponent(new ComponentRenderTexturedMaterialsStaticMesh(
|
||||
new Uri("DATA", "basicMaterial.vert", "loxelEngine"),
|
||||
new Uri("DATA", "basicMaterial.frag", "loxelEngine"),
|
||||
(EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME)));
|
||||
this.env.addEntity(superGrass);
|
||||
}
|
||||
@ -150,12 +161,21 @@ public class LightTestApplication extends GaleApplication {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyboard(final KeySpecial special, final KeyKeyboard type, final Character value, final KeyStatus state) {
|
||||
public void onKeyboard(
|
||||
final KeySpecial special,
|
||||
final KeyKeyboard type,
|
||||
final Character value,
|
||||
final KeyStatus state) {
|
||||
this.env.onKeyboard(special, type, value, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPointer(final KeySpecial special, final KeyType type, final int pointerID, final Vector2f pos, final KeyStatus state) {
|
||||
public void onPointer(
|
||||
final KeySpecial special,
|
||||
final KeyType type,
|
||||
final int pointerID,
|
||||
final Vector2f pos,
|
||||
final KeyStatus state) {
|
||||
this.env.onPointer(special, type, pointerID, new Vector3f(pos.x(), pos.y(), 0), state);
|
||||
}
|
||||
|
||||
@ -167,8 +187,9 @@ public class LightTestApplication extends GaleApplication {
|
||||
//objectPosition.getTransform().applyRotation(basicRotation);
|
||||
//objectPosition.getTransform().applyRotation(basicRotation2);
|
||||
this.angleLight += 0.01;
|
||||
this.lightPosition.setTransform(this.lightPosition.getTransform()
|
||||
.withPosition(new Vector3f((float) Math.cos(this.angleLight) * 7.0f, (float) Math.sin(this.angleLight) * 7.0f, this.lightPosition.getTransform().getPosition().z())));
|
||||
this.lightPosition.setTransform(this.lightPosition.getTransform().withPosition(
|
||||
new Vector3f((float) Math.cos(this.angleLight) * 7.0f, (float) Math.sin(this.angleLight) * 7.0f,
|
||||
this.lightPosition.getTransform().getPosition().z())));
|
||||
this.env.periodicCall();
|
||||
markDrawingIsNeeded();
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
package sample.atriasoft.ege.lightTest;
|
||||
|
||||
public class Log {
|
||||
private static final String LIBNAME = "LowPolySample";
|
||||
|
||||
public static void critical(String data) {
|
||||
System.out.println("[C] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void debug(String data) {
|
||||
System.out.println("[D] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void error(String data) {
|
||||
System.out.println("[E] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void info(String data) {
|
||||
System.out.println("[I] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void print(String data) {
|
||||
System.out.println(data);
|
||||
}
|
||||
|
||||
public static void todo(String data) {
|
||||
System.out.println("[TODO] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void verbose(String data) {
|
||||
System.out.println("[V] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void warning(String data) {
|
||||
System.out.println("[W] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
private Log() {}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package sample.atriasoft.ege.lowPoly;
|
||||
|
||||
public class Log {
|
||||
private static final String LIBNAME = "LowPolySample";
|
||||
|
||||
public static void critical(String data) {
|
||||
System.out.println("[C] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void debug(String data) {
|
||||
System.out.println("[D] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void error(String data) {
|
||||
System.out.println("[E] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void info(String data) {
|
||||
System.out.println("[I] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void print(String data) {
|
||||
System.out.println(data);
|
||||
}
|
||||
|
||||
public static void todo(String data) {
|
||||
System.out.println("[TODO] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void verbose(String data) {
|
||||
System.out.println("[V] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void warning(String data) {
|
||||
System.out.println("[W] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
private Log() {}
|
||||
}
|
@ -34,8 +34,11 @@ import org.atriasoft.gale.key.KeyKeyboard;
|
||||
import org.atriasoft.gale.key.KeySpecial;
|
||||
import org.atriasoft.gale.key.KeyStatus;
|
||||
import org.atriasoft.gale.key.KeyType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class LowPolyApplication extends GaleApplication {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(LowPolyApplication.class);
|
||||
private float angleLight = 0;
|
||||
private Quaternion basicRotation = Quaternion.IDENTITY;
|
||||
private Quaternion basicRotation2 = Quaternion.IDENTITY;
|
||||
@ -62,7 +65,8 @@ public class LowPolyApplication extends GaleApplication {
|
||||
// simple sun to have a global light ...
|
||||
final Entity sun = new Entity(this.env);
|
||||
sun.addComponent(new ComponentPosition(new Transform3D(new Vector3f(1000, 1000, 1000))));
|
||||
sun.addComponent(new ComponentLightSun(new Light(new Color(1.0f, 1.0f, 1.0f), new Vector3f(0, 0, 0), new Vector3f(1.0f, 0, 0))));
|
||||
sun.addComponent(new ComponentLightSun(
|
||||
new Light(new Color(1.0f, 1.0f, 1.0f), new Vector3f(0, 0, 0), new Vector3f(1.0f, 0, 0))));
|
||||
this.env.addEntity(sun);
|
||||
|
||||
// add a cube to show where in the light ...
|
||||
@ -71,15 +75,18 @@ public class LowPolyApplication extends GaleApplication {
|
||||
localLight.addComponent(this.lightPosition);
|
||||
localLight.addComponent(new ComponentStaticMesh(new Uri("DATA", "cube-one.obj")));
|
||||
localLight.addComponent(new ComponentTexture(new Uri("DATA", "grass.png")));
|
||||
localLight.addComponent(new ComponentLight(new Light(new Color(0.0f, 0.0f, 2.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.01f, 0.002f))));
|
||||
localLight.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localLight.addComponent(new ComponentLight(
|
||||
new Light(new Color(0.0f, 0.0f, 2.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.01f, 0.002f))));
|
||||
localLight.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"),
|
||||
new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
this.env.addEntity(localLight);
|
||||
|
||||
// Simple Gird
|
||||
final Entity gird = new Entity(this.env);
|
||||
gird.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0, 0, 0))));
|
||||
gird.addComponent(new ComponentStaticMesh(MeshGenerator.createGrid(5)));
|
||||
gird.addComponent(new ComponentRenderColoredStaticMesh(new Uri("DATA", "wireColor.vert", "ege"), new Uri("DATA", "wireColor.frag", "ege")));
|
||||
gird.addComponent(new ComponentRenderColoredStaticMesh(new Uri("DATA", "wireColor.vert", "ege"),
|
||||
new Uri("DATA", "wireColor.frag", "ege")));
|
||||
this.env.addEntity(gird);
|
||||
|
||||
// test entity
|
||||
@ -91,7 +98,8 @@ public class LowPolyApplication extends GaleApplication {
|
||||
basicTree.addComponent(new ComponentMesh(new Uri("DATA", "tree1.emf")));
|
||||
basicTree.addComponent(new ComponentTexturePalette(new Uri("DATA", "palette_1.json")));
|
||||
//basicTree.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
basicTree.addComponent(new ComponentRenderMeshPalette(new Uri("DATA", "basicPalette.vert"), new Uri("DATA", "basicPalette.frag"), (EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME)));
|
||||
basicTree.addComponent(new ComponentRenderMeshPalette(new Uri("DATA", "basicPalette.vert"),
|
||||
new Uri("DATA", "basicPalette.frag"), (EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME)));
|
||||
this.env.addEntity(basicTree);
|
||||
|
||||
basicTree = new Entity(this.env);
|
||||
@ -102,7 +110,8 @@ public class LowPolyApplication extends GaleApplication {
|
||||
basicTree.addComponent(new ComponentMesh(new Uri("DATA", "tree2.emf")));
|
||||
basicTree.addComponent(new ComponentTexturePalette(new Uri("DATA", "palette_1.json")));
|
||||
//basicTree.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
basicTree.addComponent(new ComponentRenderMeshPalette(new Uri("DATA", "basicPalette.vert"), new Uri("DATA", "basicPalette.frag"), (EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME)));
|
||||
basicTree.addComponent(new ComponentRenderMeshPalette(new Uri("DATA", "basicPalette.vert"),
|
||||
new Uri("DATA", "basicPalette.frag"), (EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME)));
|
||||
this.env.addEntity(basicTree);
|
||||
|
||||
// for (int xxx = -10; xxx < 10; xxx++) {
|
||||
@ -163,12 +172,21 @@ public class LowPolyApplication extends GaleApplication {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyboard(final KeySpecial special, final KeyKeyboard type, final Character value, final KeyStatus state) {
|
||||
public void onKeyboard(
|
||||
final KeySpecial special,
|
||||
final KeyKeyboard type,
|
||||
final Character value,
|
||||
final KeyStatus state) {
|
||||
this.env.onKeyboard(special, type, value, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPointer(final KeySpecial special, final KeyType type, final int pointerID, final Vector2f pos, final KeyStatus state) {
|
||||
public void onPointer(
|
||||
final KeySpecial special,
|
||||
final KeyType type,
|
||||
final int pointerID,
|
||||
final Vector2f pos,
|
||||
final KeyStatus state) {
|
||||
this.env.onPointer(special, type, pointerID, new Vector3f(pos.x(), pos.y(), 0), state);
|
||||
}
|
||||
|
||||
@ -180,8 +198,9 @@ public class LowPolyApplication extends GaleApplication {
|
||||
//objectPosition.getTransform().applyRotation(basicRotation);
|
||||
//objectPosition.getTransform().applyRotation(basicRotation2);
|
||||
this.angleLight += 0.01;
|
||||
this.lightPosition.setTransform(this.lightPosition.getTransform()
|
||||
.withPosition(new Vector3f((float) Math.cos(this.angleLight) * 7.0f, (float) Math.sin(this.angleLight) * 7.0f, this.lightPosition.getTransform().getPosition().z())));
|
||||
this.lightPosition.setTransform(this.lightPosition.getTransform().withPosition(
|
||||
new Vector3f((float) Math.cos(this.angleLight) * 7.0f, (float) Math.sin(this.angleLight) * 7.0f,
|
||||
this.lightPosition.getTransform().getPosition().z())));
|
||||
this.env.periodicCall();
|
||||
markDrawingIsNeeded();
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
package sample.atriasoft.ege.loxelEngine;
|
||||
|
||||
public class Log {
|
||||
private static final String LIBNAME = "LoxelEnginePerso";
|
||||
|
||||
public static void critical(String data) {
|
||||
System.out.println("[C] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void debug(String data) {
|
||||
System.out.println("[D] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void error(String data) {
|
||||
System.out.println("[E] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void info(String data) {
|
||||
System.out.println("[I] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void print(String data) {
|
||||
System.out.println(data);
|
||||
}
|
||||
|
||||
public static void todo(String data) {
|
||||
System.out.println("[TODO] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void verbose(String data) {
|
||||
System.out.println("[V] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void warning(String data) {
|
||||
System.out.println("[W] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
private Log() {}
|
||||
}
|
@ -47,8 +47,11 @@ import org.atriasoft.gale.resource.ResourceColored3DObject;
|
||||
import org.atriasoft.phyligram.PhysicBox;
|
||||
import org.atriasoft.phyligram.PhysicSphere;
|
||||
import org.atriasoft.phyligram.PhysicTriangle;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class LoxelApplicationPerso extends GaleApplication {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(LoxelApplicationPerso.class);
|
||||
public static Vector3f box1HalfSize;
|
||||
public static Vector3f box2HalfSize;
|
||||
// public static ComponentPosition relativeTestPos;
|
||||
@ -94,7 +97,8 @@ public class LoxelApplicationPerso extends GaleApplication {
|
||||
// simple sun to have a global light ...
|
||||
final Entity sun = new Entity(this.env);
|
||||
sun.addComponent(new ComponentPosition(new Transform3D(new Vector3f(1000, 1000, 1000))));
|
||||
sun.addComponent(new ComponentLightSun(new Light(new Color(0.4f, 0.4f, 0.4f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0, 0))));
|
||||
sun.addComponent(new ComponentLightSun(
|
||||
new Light(new Color(0.4f, 0.4f, 0.4f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0, 0))));
|
||||
this.env.addEntity(sun);
|
||||
|
||||
// add a cube to show where in the light ...
|
||||
@ -113,8 +117,10 @@ public class LoxelApplicationPerso extends GaleApplication {
|
||||
final Entity localBox = new Entity(this.env);
|
||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentLight(new Light(new Color(0.0f, 1.0f, 0.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.03f, 0.002f))));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentLight(
|
||||
new Light(new Color(0.0f, 1.0f, 0.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.03f, 0.002f))));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"),
|
||||
new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0, 0, 5))));
|
||||
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
||||
final PhysicBox box2 = new PhysicBox();
|
||||
@ -130,8 +136,10 @@ public class LoxelApplicationPerso extends GaleApplication {
|
||||
final Entity localBox = new Entity(this.env);
|
||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentLight(new Light(new Color(0.0f, 1.0f, 0.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.03f, 0.002f))));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentLight(
|
||||
new Light(new Color(0.0f, 1.0f, 0.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.03f, 0.002f))));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"),
|
||||
new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0, 4, 2.5f))));
|
||||
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
||||
final PhysicBox box2 = new PhysicBox();
|
||||
@ -147,7 +155,8 @@ public class LoxelApplicationPerso extends GaleApplication {
|
||||
final Entity localBox = new Entity(this.env);
|
||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"),
|
||||
new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(-2, 2, 1.5f))));
|
||||
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
||||
final PhysicBox box2 = new PhysicBox();
|
||||
@ -164,7 +173,8 @@ public class LoxelApplicationPerso extends GaleApplication {
|
||||
final Entity localBox = new Entity(this.env);
|
||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"),
|
||||
new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(-5, -5, 0))));
|
||||
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
||||
final PhysicBox box2 = new PhysicBox();
|
||||
@ -182,7 +192,8 @@ public class LoxelApplicationPerso extends GaleApplication {
|
||||
orientation = orientation.normalize();
|
||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"),
|
||||
new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(15, 15, 0), orientation)));
|
||||
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
||||
final PhysicBox box2 = new PhysicBox();
|
||||
@ -200,7 +211,8 @@ public class LoxelApplicationPerso extends GaleApplication {
|
||||
//orientation.normalize();
|
||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"),
|
||||
new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(2, -2, 0.2f), orientation)));
|
||||
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
||||
// TODO: physics2.setAngularReactionEnable(false);
|
||||
@ -219,7 +231,8 @@ public class LoxelApplicationPerso extends GaleApplication {
|
||||
orientation = orientation.normalize();
|
||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/dirt.png", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"),
|
||||
new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0, 0, 0.0f), orientation)));
|
||||
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
||||
physics2.setBodyType(PhysicBodyType.BODY_STATIC);
|
||||
@ -267,8 +280,10 @@ public class LoxelApplicationPerso extends GaleApplication {
|
||||
final Entity localBox = new Entity(this.env);
|
||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentLight(new Light(new Color(0.0f, 1.0f, 0.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.03f, 0.002f))));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentLight(
|
||||
new Light(new Color(0.0f, 1.0f, 0.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.03f, 0.002f))));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"),
|
||||
new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0, 3, 0))));
|
||||
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
||||
physics2.setBodyType(PhysicBodyType.BODY_STATIC);
|
||||
@ -299,9 +314,12 @@ public class LoxelApplicationPerso extends GaleApplication {
|
||||
final Entity localBox = new Entity(this.env);
|
||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentLight(new Light(new Color(0.0f, 1.0f, 0.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.03f, 0.002f))));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(1.1f, 5.1f, 1.0f), Quaternion.fromEulerAngles(new Vector3f(0.15f, 0.95f, 0.3f)))));
|
||||
localBox.addComponent(new ComponentLight(
|
||||
new Light(new Color(0.0f, 1.0f, 0.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.03f, 0.002f))));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"),
|
||||
new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(1.1f, 5.1f, 1.0f),
|
||||
Quaternion.fromEulerAngles(new Vector3f(0.15f, 0.95f, 0.3f)))));
|
||||
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
||||
final PhysicSphere box2 = new PhysicSphere();
|
||||
physics2.setBodyType(PhysicBodyType.BODY_STATIC);
|
||||
@ -318,9 +336,12 @@ public class LoxelApplicationPerso extends GaleApplication {
|
||||
final Entity localBox = new Entity(this.env);
|
||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentLight(new Light(new Color(0.0f, 1.0f, 0.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.03f, 0.002f))));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(1.8f, 5.8f, 4), Quaternion.fromEulerAngles(new Vector3f(0.15f, 0.95f, 0.3f)))));
|
||||
localBox.addComponent(new ComponentLight(
|
||||
new Light(new Color(0.0f, 1.0f, 0.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.03f, 0.002f))));
|
||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"),
|
||||
new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(1.8f, 5.8f, 4),
|
||||
Quaternion.fromEulerAngles(new Vector3f(0.15f, 0.95f, 0.3f)))));
|
||||
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
||||
physics2.setBodyType(PhysicBodyType.BODY_DYNAMIC);
|
||||
final PhysicSphere box2 = new PhysicSphere();
|
||||
@ -335,7 +356,8 @@ public class LoxelApplicationPerso extends GaleApplication {
|
||||
final Entity gird = new Entity(this.env);
|
||||
gird.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0, 0, 0))));
|
||||
gird.addComponent(new ComponentStaticMesh(MeshGenerator.createGrid(5)));
|
||||
gird.addComponent(new ComponentRenderColoredStaticMesh(new Uri("DATA", "wireColor.vert", "ege"), new Uri("DATA", "wireColor.frag", "ege")));
|
||||
gird.addComponent(new ComponentRenderColoredStaticMesh(new Uri("DATA", "wireColor.vert", "ege"),
|
||||
new Uri("DATA", "wireColor.frag", "ege")));
|
||||
this.env.addEntity(gird);
|
||||
|
||||
final Entity player = new Entity(this.env);
|
||||
@ -349,8 +371,10 @@ public class LoxelApplicationPerso extends GaleApplication {
|
||||
//player.addComponent(new ComponentStaticMesh(new Uri("RES", "person.obj")));
|
||||
player.addComponent(new ComponentStaticMesh(new Uri("RES", "person_-yfw_zup.obj")));
|
||||
player.addComponent(new ComponentTexture(new Uri("RES", "playerTexture.png")));
|
||||
player.addComponent(new ComponentRenderTexturedMaterialsStaticMesh(new Uri("DATA", "basicMaterial.vert", "loxelEngine"), new Uri("DATA", "basicMaterial.frag", "loxelEngine"),
|
||||
(EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME)));
|
||||
player.addComponent(
|
||||
new ComponentRenderTexturedMaterialsStaticMesh(new Uri("DATA", "basicMaterial.vert", "loxelEngine"),
|
||||
new Uri("DATA", "basicMaterial.frag", "loxelEngine"),
|
||||
(EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME)));
|
||||
player.addComponent(new ComponentPosition(playerTransform));
|
||||
final ComponentPhysics physics = new ComponentPhysics(this.env);
|
||||
physics.setBodyType(PhysicBodyType.BODY_DYNAMIC);
|
||||
@ -373,8 +397,10 @@ public class LoxelApplicationPerso extends GaleApplication {
|
||||
//player.addComponent(new ComponentStaticMesh(new Uri("RES", "person.obj")));
|
||||
player.addComponent(new ComponentStaticMesh(new Uri("RES", "person_-yfw_zup.obj")));
|
||||
player.addComponent(new ComponentTexture(new Uri("RES", "playerTexture.png")));
|
||||
player.addComponent(new ComponentRenderTexturedMaterialsStaticMesh(new Uri("DATA", "basicMaterial.vert", "loxelEngine"), new Uri("DATA", "basicMaterial.frag", "loxelEngine"),
|
||||
(EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME)));
|
||||
player.addComponent(
|
||||
new ComponentRenderTexturedMaterialsStaticMesh(new Uri("DATA", "basicMaterial.vert", "loxelEngine"),
|
||||
new Uri("DATA", "basicMaterial.frag", "loxelEngine"),
|
||||
(EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME)));
|
||||
final ComponentPhysics physics = new ComponentPhysics(this.env);
|
||||
physics.setBodyType(PhysicBodyType.BODY_DYNAMIC);
|
||||
final PhysicBox box = new PhysicBox();
|
||||
@ -434,29 +460,43 @@ public class LoxelApplicationPerso extends GaleApplication {
|
||||
final Vector3f elem = LoxelApplicationPerso.testPoints.get(iii);
|
||||
final boolean collide = LoxelApplicationPerso.testPointsCollide.get(iii);
|
||||
if (collide) {
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f),
|
||||
Matrix4f.IDENTITY.multiply(
|
||||
Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
new Color(1, 0, 0, 1));
|
||||
} else if (iii == 0) {
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f),
|
||||
Matrix4f.IDENTITY.multiply(
|
||||
Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
new Color(0, 1, 0, 1));
|
||||
} else if (iii == 7) {
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f),
|
||||
Matrix4f.IDENTITY.multiply(
|
||||
Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
new Color(1, 1, 0, 1));
|
||||
} else {
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f),
|
||||
Matrix4f.IDENTITY.multiply(
|
||||
Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
new Color(1, 1, 1, 1));
|
||||
}
|
||||
}
|
||||
for (int iii = 0; iii < LoxelApplicationPerso.testPointsBox.size(); iii++) {
|
||||
final Vector3f elem = LoxelApplicationPerso.testPointsBox.get(iii);
|
||||
if (iii == 0) {
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f),
|
||||
Matrix4f.IDENTITY.multiply(
|
||||
Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
new Color(0, 1, 0, 1));
|
||||
} else if (iii == 7) {
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f),
|
||||
Matrix4f.IDENTITY.multiply(
|
||||
Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
new Color(1, 1, 0, 1));
|
||||
} else {
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
this.debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f),
|
||||
Matrix4f.IDENTITY.multiply(
|
||||
Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
||||
new Color(0, 0, 1, 1));
|
||||
}
|
||||
}
|
||||
@ -466,13 +506,18 @@ public class LoxelApplicationPerso extends GaleApplication {
|
||||
//Matrix4f transformation = Matrix4f.createMatrixTranslate(new Vector3f(testRpos.x,testRpos.y,testRpos.z)).multiply(testQTransfert.getMatrix4()).multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,14)));
|
||||
//Matrix4f transformation = testQTransfert.getMatrix4().multiply(Matrix4f.createMatrixTranslate(new Vector3f(testRpos.x,testRpos.y,testRpos.z))).multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,14)));
|
||||
//Matrix4f transformation = testQTransfert.getMatrix4().multiply(Matrix4f.createMatrixTranslate(new Vector3f(testRpos.x,testRpos.y,testRpos.z))).multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,14)));
|
||||
final Matrix4f transformation = Matrix4f.createMatrixTranslate(new Vector3f(LoxelApplicationPerso.testRpos.x(), LoxelApplicationPerso.testRpos.y(), LoxelApplicationPerso.testRpos.z()))
|
||||
.multiply(Matrix4f.createMatrixTranslate(new Vector3f(0, 0, 14))).multiply(LoxelApplicationPerso.testQTransfert.getMatrix4());
|
||||
final Matrix4f transformation = Matrix4f
|
||||
.createMatrixTranslate(new Vector3f(LoxelApplicationPerso.testRpos.x(),
|
||||
LoxelApplicationPerso.testRpos.y(), LoxelApplicationPerso.testRpos.z()))
|
||||
.multiply(Matrix4f.createMatrixTranslate(new Vector3f(0, 0, 14)))
|
||||
.multiply(LoxelApplicationPerso.testQTransfert.getMatrix4());
|
||||
// OK sans la box1 orientation ...
|
||||
//Matrix4f transformation = Matrix4f.createMatrixTranslate(new Vector3f(testRpos.x,testRpos.y,testRpos.z)).multiply(testQTransfert.getMatrix4()).multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,14)));
|
||||
//Matrix4f transformation = Matrix4f.createMatrixTranslate(new Vector3f(testRpos.x,testRpos.y,testRpos.z)).multiply(testQTransfert.getMatrix4()).multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,14)));
|
||||
this.debugDrawProperty.drawSquare(LoxelApplicationPerso.box2HalfSize, transformation, new Color(0, 1, 0, 0.5f));
|
||||
this.debugDrawProperty.drawSquare(LoxelApplicationPerso.box1HalfSize, Matrix4f.createMatrixTranslate(new Vector3f(0, 0, 14)), new Color(0, 0, 1, 0.5f));
|
||||
this.debugDrawProperty.drawSquare(LoxelApplicationPerso.box2HalfSize, transformation,
|
||||
new Color(0, 1, 0, 0.5f));
|
||||
this.debugDrawProperty.drawSquare(LoxelApplicationPerso.box1HalfSize,
|
||||
Matrix4f.createMatrixTranslate(new Vector3f(0, 0, 14)), new Color(0, 0, 1, 0.5f));
|
||||
}
|
||||
|
||||
// Restore context of matrix
|
||||
@ -480,7 +525,11 @@ public class LoxelApplicationPerso extends GaleApplication {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyboard(final KeySpecial special, final KeyKeyboard type, final Character value, final KeyStatus state) {
|
||||
public void onKeyboard(
|
||||
final KeySpecial special,
|
||||
final KeyKeyboard type,
|
||||
final Character value,
|
||||
final KeyStatus state) {
|
||||
if (type == KeyKeyboard.F1) {
|
||||
Gale.getContext().grabPointerEvents(false, new Vector2f(0, 0));
|
||||
}
|
||||
@ -494,7 +543,12 @@ public class LoxelApplicationPerso extends GaleApplication {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPointer(final KeySpecial special, final KeyType type, final int pointerID, final Vector2f pos, final KeyStatus state) {
|
||||
public void onPointer(
|
||||
final KeySpecial special,
|
||||
final KeyType type,
|
||||
final int pointerID,
|
||||
final Vector2f pos,
|
||||
final KeyStatus state) {
|
||||
this.env.onPointer(special, type, pointerID, new Vector3f(pos.x(), pos.y(), 0), state);
|
||||
}
|
||||
|
||||
@ -503,7 +557,9 @@ public class LoxelApplicationPerso extends GaleApplication {
|
||||
//LOGGER.trace("Regenerate Gale Application");
|
||||
this.angleLight += 0.01;
|
||||
this.lightPosition.setTransform(this.lightPosition.getTransform()
|
||||
.withPosition(new Vector3f(5 + (float) Math.cos(this.angleLight) * 7.0f, 5 + (float) Math.sin(this.angleLight) * 7.0f, this.lightPosition.getTransform().getPosition().z())));
|
||||
.withPosition(new Vector3f(5 + (float) Math.cos(this.angleLight) * 7.0f,
|
||||
5 + (float) Math.sin(this.angleLight) * 7.0f,
|
||||
this.lightPosition.getTransform().getPosition().z())));
|
||||
this.env.periodicCall();
|
||||
markDrawingIsNeeded();
|
||||
}
|
||||
|
@ -4,15 +4,18 @@ import org.atriasoft.etk.Configs;
|
||||
import org.atriasoft.etk.math.Vector2f;
|
||||
import org.atriasoft.ewol.context.EwolApplication;
|
||||
import org.atriasoft.ewol.context.EwolContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Appl implements EwolApplication {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(Appl.class);
|
||||
|
||||
private void localCreate(final EwolContext context) {
|
||||
// parse all the argument of the application
|
||||
for (int iii = 0; iii < context.getCmd().size(); iii++) {
|
||||
String tmpppp = context.getCmd().get(iii);
|
||||
if (tmpppp == "-h" || tmpppp == "--help") {
|
||||
LOGGER.print(" -h/--help display this help");
|
||||
LOGGER.info(" -h/--help display this help");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
@ -13,11 +13,14 @@ import org.atriasoft.etk.math.Transform3D;
|
||||
import org.atriasoft.etk.math.Vector3f;
|
||||
import org.atriasoft.ewol.event.EventEntry;
|
||||
import org.atriasoft.ewol.event.EventInput;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sample.atriasoft.ege.mapFactory.model.Map;
|
||||
import sample.atriasoft.ege.mapFactory.tools.MapToolInterface;
|
||||
|
||||
public class ApplScene extends EgeScene {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(ApplScene.class);
|
||||
//Ground ground = new Ground();
|
||||
Map map = new Map();
|
||||
private ControlInterface simpleControl;
|
||||
@ -38,8 +41,8 @@ public class ApplScene extends EgeScene {
|
||||
groundEntity.addComponent(new ComponentMesh(this.map.ground.createMesh()));
|
||||
groundEntity.addComponent(new ComponentTexturePalette(new Uri("DATA", "palette_1.json")));
|
||||
//basicTree.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
|
||||
groundEntity
|
||||
.addComponent(new ComponentRenderMeshPalette(new Uri("DATA", "basicPalette.vert"), new Uri("DATA", "basicPalette.frag"), (EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME)));
|
||||
groundEntity.addComponent(new ComponentRenderMeshPalette(new Uri("DATA", "basicPalette.vert"),
|
||||
new Uri("DATA", "basicPalette.frag"), (EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME)));
|
||||
this.env.addEntity(groundEntity);
|
||||
|
||||
this.map.updateMesh();
|
||||
|
@ -20,8 +20,12 @@ import org.atriasoft.ewol.event.EventTime;
|
||||
import org.atriasoft.ewol.widget.Widget;
|
||||
import org.atriasoft.gale.backend3d.OpenGL;
|
||||
import org.atriasoft.gale.backend3d.OpenGL.Flag;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class EgeScene extends Widget {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(EgeScene.class);
|
||||
|
||||
/**
|
||||
* Periodic call to update grapgic display
|
||||
* @param _event Time generic event
|
||||
@ -72,7 +76,8 @@ public class EgeScene extends Widget {
|
||||
final Entity gird = new Entity(this.env);
|
||||
gird.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0, 0, 0))));
|
||||
gird.addComponent(new ComponentStaticMesh(MeshGenerator.createGrid(5)));
|
||||
gird.addComponent(new ComponentRenderColoredStaticMesh(new Uri("DATA", "wireColor.vert", "ege"), new Uri("DATA", "wireColor.frag", "ege")));
|
||||
gird.addComponent(new ComponentRenderColoredStaticMesh(new Uri("DATA", "wireColor.vert", "ege"),
|
||||
new Uri("DATA", "wireColor.frag", "ege")));
|
||||
this.env.addEntity(gird);
|
||||
}
|
||||
|
||||
|
@ -1,76 +0,0 @@
|
||||
package sample.atriasoft.ege.mapFactory;
|
||||
|
||||
import org.atriasoft.reggol.LogLevel;
|
||||
import org.atriasoft.reggol.Logger;
|
||||
|
||||
public class Log {
|
||||
private static final boolean FORCE_ALL = false;
|
||||
private static final String LIB_NAME = "mapFactory";
|
||||
private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME);
|
||||
private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(LIB_NAME, LogLevel.CRITICAL);
|
||||
private static final boolean PRINT_ERROR = Logger.getNeedPrint(LIB_NAME, LogLevel.ERROR);
|
||||
private static final boolean PRINT_WARNING = Logger.getNeedPrint(LIB_NAME, LogLevel.WARNING);
|
||||
private static final boolean PRINT_INFO = Logger.getNeedPrint(LIB_NAME, LogLevel.INFO);
|
||||
private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG);
|
||||
private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(LIB_NAME, LogLevel.VERBOSE);
|
||||
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
|
||||
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
|
||||
|
||||
public static void critical(final Exception e, final String data) {
|
||||
e.printStackTrace();
|
||||
if (PRINT_CRITICAL || FORCE_ALL) {
|
||||
Logger.critical(LIB_NAME_DRAW, data + " : " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void critical(final String data, final Object... objects) {
|
||||
if (PRINT_CRITICAL || FORCE_ALL) {
|
||||
Logger.critical(LIB_NAME_DRAW, data, objects);
|
||||
}
|
||||
}
|
||||
|
||||
public static void debug(final String data, final Object... objects) {
|
||||
if (PRINT_DEBUG || FORCE_ALL) {
|
||||
Logger.debug(LIB_NAME_DRAW, data, objects);
|
||||
}
|
||||
}
|
||||
|
||||
public static void error(final String data, final Object... objects) {
|
||||
if (PRINT_ERROR || FORCE_ALL) {
|
||||
Logger.error(LIB_NAME_DRAW, data, objects);
|
||||
}
|
||||
}
|
||||
|
||||
public static void info(final String data, final Object... objects) {
|
||||
if (PRINT_INFO || FORCE_ALL) {
|
||||
Logger.info(LIB_NAME_DRAW, data, objects);
|
||||
}
|
||||
}
|
||||
|
||||
public static void print(final String data, final Object... objects) {
|
||||
if (PRINT_PRINT || FORCE_ALL) {
|
||||
Logger.print(LIB_NAME_DRAW, data, objects);
|
||||
}
|
||||
}
|
||||
|
||||
public static void todo(final String data, final Object... objects) {
|
||||
if (PRINT_TODO || FORCE_ALL) {
|
||||
Logger.todo(LIB_NAME_DRAW, data, objects);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verbose(final String data, final Object... objects) {
|
||||
if (PRINT_VERBOSE || FORCE_ALL) {
|
||||
Logger.verbose(LIB_NAME_DRAW, data, objects);
|
||||
}
|
||||
}
|
||||
|
||||
public static void warning(final String data, final Object... objects) {
|
||||
if (PRINT_WARNING || FORCE_ALL) {
|
||||
Logger.warning(LIB_NAME_DRAW, data, objects);
|
||||
}
|
||||
}
|
||||
|
||||
private Log() {}
|
||||
|
||||
}
|
@ -6,11 +6,14 @@ import org.atriasoft.ewol.widget.Sizer;
|
||||
import org.atriasoft.ewol.widget.Sizer.DisplayMode;
|
||||
import org.atriasoft.ewol.widget.Widget;
|
||||
import org.atriasoft.ewol.widget.Windows;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sample.atriasoft.ege.mapFactory.tools.MapToolInterface;
|
||||
import sample.atriasoft.ege.mapFactory.tools.ToolMapHeight;
|
||||
|
||||
public class MainWindows extends Windows {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(MainWindows.class);
|
||||
|
||||
public static void eventButtonTool(final MainWindows self, Boolean value) {
|
||||
//Vector2b state = self.testWidget.getPropertyFill();
|
||||
|
@ -12,13 +12,16 @@ import org.atriasoft.ewol.widget.Slider;
|
||||
import org.atriasoft.ewol.widget.Widget;
|
||||
import org.atriasoft.gale.key.KeyStatus;
|
||||
import org.atriasoft.gale.resource.ResourceColored3DObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sample.atriasoft.ege.mapFactory.EgeScene;
|
||||
import sample.atriasoft.ege.mapFactory.Log;
|
||||
import sample.atriasoft.ege.mapFactory.model.Map;
|
||||
import toolbox.Maths;
|
||||
|
||||
public class ToolMapHeight implements MapToolInterface {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(ToolMapHeight.class);
|
||||
|
||||
protected static void onCallbackMaxChange(final ToolMapHeight self, final float value) {
|
||||
LOGGER.warn("get new value {}", value);
|
||||
self.onCallbackMax(value);
|
||||
@ -50,13 +53,16 @@ public class ToolMapHeight implements MapToolInterface {
|
||||
public Widget getWidget() {
|
||||
final Widget data = Composer.composerGenerateFile(new Uri("DATA", "ToolMapHeight.xml"), this.uniqueID);
|
||||
|
||||
if (data.getSubObjectNamed("[" + Long.toString(this.uniqueID) + "]HeighMap:slider-width") instanceof final Slider tmp) {
|
||||
if (data.getSubObjectNamed(
|
||||
"[" + Long.toString(this.uniqueID) + "]HeighMap:slider-width") instanceof final Slider tmp) {
|
||||
tmp.signalValue.connectAuto(this, ToolMapHeight::onCallbackWidthChange);
|
||||
}
|
||||
if (data.getSubObjectNamed("[" + Long.toString(this.uniqueID) + "]HeighMap:slider-top") instanceof final Slider tmp) {
|
||||
if (data.getSubObjectNamed(
|
||||
"[" + Long.toString(this.uniqueID) + "]HeighMap:slider-top") instanceof final Slider tmp) {
|
||||
tmp.signalValue.connectAuto(this, ToolMapHeight::onCallbackMaxChange);
|
||||
}
|
||||
if (data.getSubObjectNamed("[" + Long.toString(this.uniqueID) + "]HeighMap:slider-bottom") instanceof final Slider tmp) {
|
||||
if (data.getSubObjectNamed(
|
||||
"[" + Long.toString(this.uniqueID) + "]HeighMap:slider-bottom") instanceof final Slider tmp) {
|
||||
tmp.signalValue.connectAuto(this, ToolMapHeight::onCallbackMinChange);
|
||||
}
|
||||
|
||||
@ -81,8 +87,10 @@ public class ToolMapHeight implements MapToolInterface {
|
||||
if (this.positionRay != null) {
|
||||
map.ground.drawDynamicElement(this.dynamicElement, this.positionRay, this.widthBrush);
|
||||
float size = this.maxBrush - this.minBrush;
|
||||
Transform3D tmpTransform = new Transform3D(this.positionRay.add(new Vector3f(0.0f, 0.0f, this.minBrush + size * 0.5f)));
|
||||
this.dynamicElement.drawCylinder(this.widthBrush, size, 10, 22, tmpTransform.getOpenGLMatrix(), Color.AZURE.withA(0.5f), false, true);
|
||||
Transform3D tmpTransform = new Transform3D(
|
||||
this.positionRay.add(new Vector3f(0.0f, 0.0f, this.minBrush + size * 0.5f)));
|
||||
this.dynamicElement.drawCylinder(this.widthBrush, size, 10, 22, tmpTransform.getOpenGLMatrix(),
|
||||
Color.AZURE.withA(0.5f), false, true);
|
||||
}
|
||||
|
||||
}
|
||||
@ -134,33 +142,39 @@ public class ToolMapHeight implements MapToolInterface {
|
||||
return true;
|
||||
}
|
||||
// max brush
|
||||
if (event.inputId() == 4 && event.status() == KeyStatus.down && (event.specialKey() != null && event.specialKey().getAltLeft() && event.specialKey().getCtrlLeft())) {
|
||||
if (event.inputId() == 4 && event.status() == KeyStatus.down && (event.specialKey() != null
|
||||
&& event.specialKey().getAltLeft() && event.specialKey().getCtrlLeft())) {
|
||||
this.maxBrush = Maths.avg(this.minBrush + 0.1f, this.maxBrush + 0.1f, 128.0f);
|
||||
LOGGER.warn(" values: {} / {}", this.minBrush, this.maxBrush);
|
||||
return true;
|
||||
}
|
||||
if (event.inputId() == 5 && event.status() == KeyStatus.down && (event.specialKey() != null && event.specialKey().getAltLeft() && event.specialKey().getCtrlLeft())) {
|
||||
if (event.inputId() == 5 && event.status() == KeyStatus.down && (event.specialKey() != null
|
||||
&& event.specialKey().getAltLeft() && event.specialKey().getCtrlLeft())) {
|
||||
this.maxBrush = Maths.avg(this.minBrush + 0.1f, this.maxBrush - 0.1f, 128.0f);
|
||||
LOGGER.warn(" values: {} / {}", this.minBrush, this.maxBrush);
|
||||
return true;
|
||||
}
|
||||
// min brush
|
||||
if (event.inputId() == 4 && event.status() == KeyStatus.down && (event.specialKey() != null && event.specialKey().getAltLeft())) {
|
||||
if (event.inputId() == 4 && event.status() == KeyStatus.down
|
||||
&& (event.specialKey() != null && event.specialKey().getAltLeft())) {
|
||||
this.minBrush = Maths.avg(-128.0f, this.minBrush + 0.1f, this.maxBrush - 0.1f);
|
||||
LOGGER.warn(" values: {} / {}", this.minBrush, this.maxBrush);
|
||||
return true;
|
||||
}
|
||||
if (event.inputId() == 5 && event.status() == KeyStatus.down && (event.specialKey() != null && event.specialKey().getAltLeft())) {
|
||||
if (event.inputId() == 5 && event.status() == KeyStatus.down
|
||||
&& (event.specialKey() != null && event.specialKey().getAltLeft())) {
|
||||
this.minBrush = Maths.avg(-128.0f, this.minBrush - 0.1f, this.maxBrush - 0.1f);
|
||||
LOGGER.warn(" values: {} / {}", this.minBrush, this.maxBrush);
|
||||
return true;
|
||||
}
|
||||
// width brush
|
||||
if (event.inputId() == 4 && event.status() == KeyStatus.down && (event.specialKey() != null && event.specialKey().getCtrlLeft())) {
|
||||
if (event.inputId() == 4 && event.status() == KeyStatus.down
|
||||
&& (event.specialKey() != null && event.specialKey().getCtrlLeft())) {
|
||||
this.widthBrush = Maths.avg(0.1f, this.widthBrush + 0.1f, 30.0f);
|
||||
return true;
|
||||
}
|
||||
if (event.inputId() == 5 && event.status() == KeyStatus.down && (event.specialKey() != null && event.specialKey().getCtrlLeft())) {
|
||||
if (event.inputId() == 5 && event.status() == KeyStatus.down
|
||||
&& (event.specialKey() != null && event.specialKey().getCtrlLeft())) {
|
||||
this.widthBrush = Maths.avg(0.1f, this.widthBrush - 0.1f, 30.0f);
|
||||
return true;
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
package sample.atriasoft.ege.s1_texturedCube;
|
||||
|
||||
public class Log {
|
||||
private static final String LIBNAME = "Sample1";
|
||||
|
||||
public static void critical(String data) {
|
||||
System.out.println("[C] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void debug(String data) {
|
||||
System.out.println("[D] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void error(String data) {
|
||||
System.out.println("[E] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void info(String data) {
|
||||
System.out.println("[I] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void print(String data) {
|
||||
System.out.println(data);
|
||||
}
|
||||
|
||||
public static void todo(String data) {
|
||||
System.out.println("[TODO] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void verbose(String data) {
|
||||
System.out.println("[V] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void warning(String data) {
|
||||
System.out.println("[W] " + LOGGER.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
private Log() {}
|
||||
}
|
@ -26,8 +26,12 @@ import org.atriasoft.gale.key.KeyKeyboard;
|
||||
import org.atriasoft.gale.key.KeySpecial;
|
||||
import org.atriasoft.gale.key.KeyStatus;
|
||||
import org.atriasoft.gale.key.KeyType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class S1Application extends GaleApplication {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(S1Application.class);
|
||||
|
||||
private Quaternion basicRotation = Quaternion.IDENTITY;
|
||||
private Quaternion basicRotation2 = Quaternion.IDENTITY;
|
||||
private Environement env;
|
||||
@ -48,7 +52,8 @@ public class S1Application extends GaleApplication {
|
||||
final Entity gird = new Entity(this.env);
|
||||
gird.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0, 0, 0))));
|
||||
gird.addComponent(new ComponentStaticMesh(MeshGenerator.createGrid(5)));
|
||||
gird.addComponent(new ComponentRenderColoredStaticMesh(new Uri("DATA", "wireColor.vert", "ege"), new Uri("DATA", "wireColor.frag", "ege")));
|
||||
gird.addComponent(new ComponentRenderColoredStaticMesh(new Uri("DATA", "wireColor.vert", "ege"),
|
||||
new Uri("DATA", "wireColor.frag", "ege")));
|
||||
this.env.addEntity(gird);
|
||||
|
||||
final Entity basicTree = new Entity(this.env);
|
||||
@ -56,7 +61,8 @@ public class S1Application extends GaleApplication {
|
||||
basicTree.addComponent(this.objectPosition);
|
||||
basicTree.addComponent(new ComponentStaticMesh(new Uri("RES", "cube.obj")));
|
||||
basicTree.addComponent(new ComponentTexture(new Uri("DATA", "blocks/dirt.png", "loxelEngine")));
|
||||
basicTree.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "sample"), new Uri("DATA", "basic.frag", "sample")));
|
||||
basicTree.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "sample"),
|
||||
new Uri("DATA", "basic.frag", "sample")));
|
||||
this.env.addEntity(basicTree);
|
||||
|
||||
this.mainView = new Camera();
|
||||
@ -107,12 +113,21 @@ public class S1Application extends GaleApplication {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyboard(final KeySpecial special, final KeyKeyboard type, final Character value, final KeyStatus state) {
|
||||
public void onKeyboard(
|
||||
final KeySpecial special,
|
||||
final KeyKeyboard type,
|
||||
final Character value,
|
||||
final KeyStatus state) {
|
||||
this.env.onKeyboard(special, type, value, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPointer(final KeySpecial special, final KeyType type, final int pointerID, final Vector2f pos, final KeyStatus state) {
|
||||
public void onPointer(
|
||||
final KeySpecial special,
|
||||
final KeyType type,
|
||||
final int pointerID,
|
||||
final Vector2f pos,
|
||||
final KeyStatus state) {
|
||||
this.env.onPointer(special, type, pointerID, new Vector3f(pos.x(), pos.y(), 0), state);
|
||||
}
|
||||
|
||||
@ -128,12 +143,14 @@ public class S1Application extends GaleApplication {
|
||||
|
||||
//this.objectPosition.setTransform(this.objectPosition.getTransform().withPosition(new Vector3f(2, -1, -5)));
|
||||
if (this.signe == true) {
|
||||
this.objectPosition.setTransform(this.objectPosition.getTransform().withPosition(this.objectPosition.getTransform().getPosition().add(new Vector3f(0, 0, -0.1f))));
|
||||
this.objectPosition.setTransform(this.objectPosition.getTransform()
|
||||
.withPosition(this.objectPosition.getTransform().getPosition().add(new Vector3f(0, 0, -0.1f))));
|
||||
if (this.objectPosition.getTransform().getPosition().z() < -5) {
|
||||
this.signe = false;
|
||||
}
|
||||
} else {
|
||||
this.objectPosition.setTransform(this.objectPosition.getTransform().withPosition(this.objectPosition.getTransform().getPosition().add(new Vector3f(0, 0, 0.1f))));
|
||||
this.objectPosition.setTransform(this.objectPosition.getTransform()
|
||||
.withPosition(this.objectPosition.getTransform().getPosition().add(new Vector3f(0, 0, 0.1f))));
|
||||
if (this.objectPosition.getTransform().getPosition().z() > 5) {
|
||||
this.signe = true;
|
||||
}
|
||||
|
@ -1,53 +0,0 @@
|
||||
package org.atriasoft.arkon;
|
||||
/*
|
||||
* From http://www.redblobgames.com/x/1742-webgl-mapgen2/
|
||||
* Copyright 2017 Red Blob Games <redblobgames@gmail.com>
|
||||
* License: Apache v2.0 <http://www.apache.org/licenses/LICENSE-2.0.html>
|
||||
*/
|
||||
|
||||
/* Generate the biome colormap indexed by elevation -1:+1 and rainfall 0:1 */
|
||||
class ColorMap {
|
||||
public static int width = 64;
|
||||
public static int height = 64;
|
||||
|
||||
public int[] colormap() {
|
||||
int[] pixels = new int[width * height * 4];
|
||||
|
||||
for (int y = 0, p = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int e = 2 * x / width - 1, m = y / height;
|
||||
int r, g, b;
|
||||
if (x == width / 2 - 1) {
|
||||
r = 48;
|
||||
g = 120;
|
||||
b = 160;
|
||||
} else if (x == width / 2 - 2) {
|
||||
r = 48;
|
||||
g = 100;
|
||||
b = 150;
|
||||
} else if (x == width / 2 - 3) {
|
||||
r = 48;
|
||||
g = 80;
|
||||
b = 140;
|
||||
} else if (e < 0.0) {
|
||||
r = 48 + 48 * e;
|
||||
g = 64 + 64 * e;
|
||||
b = 127 + 127 * e;
|
||||
} else { // adapted from terrain-from-noise article
|
||||
m = m * (1 - e); // higher elevation holds less moisture; TODO: should be based on slope, not elevation
|
||||
r = 210 - 100 * m;
|
||||
g = 185 - 45 * m;
|
||||
b = 139 - 45 * m;
|
||||
r = 255 * e + r * (1 - e);
|
||||
g = 255 * e + g * (1 - e);
|
||||
b = 255 * e + b * (1 - e);
|
||||
}
|
||||
pixels[p++] = r;
|
||||
pixels[p++] = g;
|
||||
pixels[p++] = b;
|
||||
pixels[p++] = 255;
|
||||
}
|
||||
}
|
||||
return pixels;
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
package org.atriasoft.arkon;
|
||||
/*
|
||||
* From https://www.redblobgames.com/maps/mapgen4/
|
||||
* Copyright 2018 Red Blob Games <redblobgames@gmail.com>
|
||||
* License: Apache v2.0 <http://www.apache.org/licenses/LICENSE-2.0.html>
|
||||
*
|
||||
* Configuration parameters shared by the point precomputation and the
|
||||
* map generator. Some of these objects are empty because they will be
|
||||
* filled in by the map generator.
|
||||
*/
|
||||
|
||||
class Config {
|
||||
public class ConfinElement {
|
||||
public float initialValue;
|
||||
public float min;
|
||||
public float max;
|
||||
|
||||
public ConfinElement(float initialValue, float min, float max) {
|
||||
this.initialValue = initialValue;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int spacing = 5;
|
||||
public int mountainSpacing = 35;
|
||||
public int mountainDensity = 1500;
|
||||
|
||||
public ConfinElement mesh_seed = new ConfinElement(187, 1, 1 << 30);
|
||||
public ConfinElement mesh_island = new ConfinElement(0.5f, 0, 1);
|
||||
public ConfinElement mesh_noisy_coastlines = new ConfinElement(0.01f, 0, 0.1f);
|
||||
public ConfinElement mesh_hill_height = new ConfinElement(0.02f, 0, 0.1f);
|
||||
public ConfinElement mesh_mountain_jagged = new ConfinElement(0, 0, 1);
|
||||
public ConfinElement mesh_mountain_sharpness = new ConfinElement(10, 9.5f, 12.5f);
|
||||
public ConfinElement mesh_ocean_depth = new ConfinElement(1.5f, 1, 3);
|
||||
public ConfinElement biomes_wind_angle_deg = new ConfinElement(0, 0, 360);
|
||||
public ConfinElement biomes_raininess = new ConfinElement(0.9f, 0, 2);
|
||||
public ConfinElement biomes_rain_shadow = new ConfinElement(0.5f, 0.1f, 2);
|
||||
public ConfinElement biomes_evaporation = new ConfinElement(0.5f, 0, 1);
|
||||
public ConfinElement rivers_lg_min_flow = new ConfinElement(2.7f, -5, 5);
|
||||
public ConfinElement rivers_lg_river_width = new ConfinElement(-2.7f, -5, 5);
|
||||
public ConfinElement rivers_flow = new ConfinElement(0.2f, 0, 1);
|
||||
public ConfinElement render_zoom = new ConfinElement(100 / 480, 100 / 1000, 100 / 50);
|
||||
public ConfinElement render_x = new ConfinElement(500, 0, 1000);
|
||||
public ConfinElement render_y = new ConfinElement(500, 0, 1000);
|
||||
public ConfinElement render_light_angle_deg = new ConfinElement(80, 0, 360);
|
||||
public ConfinElement render_slope = new ConfinElement(2, 0, 5);
|
||||
public ConfinElement render_flat = new ConfinElement(2.5f, 0, 5);
|
||||
public ConfinElement render_ambient = new ConfinElement(0.25f, 0, 1);
|
||||
public ConfinElement render_overhead = new ConfinElement(30, 0, 60);
|
||||
public ConfinElement render_tilt_deg = new ConfinElement(0, 0, 90);
|
||||
public ConfinElement render_rotate_deg = new ConfinElement(0, -180, 180);
|
||||
public ConfinElement render_mountain_height = new ConfinElement(50, 0, 250);
|
||||
public ConfinElement render_outline_depth = new ConfinElement(1, 0, 2);
|
||||
public ConfinElement render_outline_strength = new ConfinElement(15, 0, 30);
|
||||
public ConfinElement render_outline_threshold = new ConfinElement(0, 0, 100);
|
||||
public ConfinElement render_outline_coast = new ConfinElement(0, 0, 1);
|
||||
public ConfinElement render_outline_water = new ConfinElement(10.0f, 0, 20); // things start going wrong when this is high
|
||||
public ConfinElement render_biome_colors = new ConfinElement(1, 0, 1);
|
||||
|
||||
}
|
@ -1,229 +0,0 @@
|
||||
package org.atriasoft.arkon;
|
||||
|
||||
public class Create {
|
||||
let Delaunator = require('delaunator'); // ISC licensed
|
||||
let TriangleMesh = require('./');
|
||||
|
||||
function s_next_s(s) { return (s % 3 == 2) ? s-2 : s+1; }
|
||||
|
||||
|
||||
function checkPointInequality({_r_vertex, _triangles, _halfedges}) {
|
||||
// TODO: check for collinear vertices. Around each red point P if
|
||||
// there's a point Q and R both connected to it, and the angle P→Q and
|
||||
// the angle P→R are 180° apart, then there's collinearity. This would
|
||||
// indicate an issue with point selection.
|
||||
}
|
||||
|
||||
|
||||
function checkTriangleInequality({_r_vertex, _triangles, _halfedges}) {
|
||||
// check for skinny triangles
|
||||
const badAngleLimit = 30;
|
||||
let summary = new Array(badAngleLimit).fill(0);
|
||||
let count = 0;
|
||||
for (let s = 0; s < _triangles.length; s++) {
|
||||
let r0 = _triangles[s],
|
||||
r1 = _triangles[s_next_s(s)],
|
||||
r2 = _triangles[s_next_s(s_next_s(s))];
|
||||
let p0 = _r_vertex[r0],
|
||||
p1 = _r_vertex[r1],
|
||||
p2 = _r_vertex[r2];
|
||||
let d0 = [p0[0]-p1[0], p0[1]-p1[1]];
|
||||
let d2 = [p2[0]-p1[0], p2[1]-p1[1]];
|
||||
let dotProduct = d0[0] * d2[0] + d0[1] + d2[1];
|
||||
let angleDegrees = 180 / Math.PI * Math.acos(dotProduct);
|
||||
if (angleDegrees < badAngleLimit) {
|
||||
summary[angleDegrees|0]++;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
// NOTE: a much faster test would be the ratio of the inradius to
|
||||
// the circumradius, but as I'm generating these offline, I'm not
|
||||
// worried about speed right now
|
||||
|
||||
// TODO: consider adding circumcenters of skinny triangles to the point set
|
||||
if (count > 0) {
|
||||
console.log(' bad angles:', summary.join(" "));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function checkMeshConnectivity({_r_vertex, _triangles, _halfedges}) {
|
||||
// 1. make sure each side's opposite is back to itself
|
||||
// 2. make sure region-circulating starting from each side works
|
||||
let ghost_r = _r_vertex.length - 1, out_s = [];
|
||||
for (let s0 = 0; s0 < _triangles.length; s0++) {
|
||||
if (_halfedges[_halfedges[s0]] !== s0) {
|
||||
console.log(`FAIL _halfedges[_halfedges[${s0}]] !== ${s0}`);
|
||||
}
|
||||
let s = s0, count = 0;
|
||||
out_s.length = 0;
|
||||
do {
|
||||
count++; out_s.push(s);
|
||||
s = s_next_s(_halfedges[s]);
|
||||
if (count > 100 && _triangles[s0] !== ghost_r) {
|
||||
console.log(`FAIL to circulate around region with start side=${s0} from region ${_triangles[s0]} to ${_triangles[s_next_s(s0)]}, out_s=${out_s}`);
|
||||
break;
|
||||
}
|
||||
} while (s !== s0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Add vertices evenly along the boundary of the mesh;
|
||||
* use a slight curve so that the Delaunay triangulation
|
||||
* doesn't make long thing triangles along the boundary.
|
||||
* These points also prevent the Poisson disc generator
|
||||
* from making uneven points near the boundary.
|
||||
*/
|
||||
function addBoundaryPoints(spacing, size) {
|
||||
let N = Math.ceil(size/spacing);
|
||||
let points = [];
|
||||
for (let i = 0; i <= N; i++) {
|
||||
let t = (i + 0.5) / (N + 1);
|
||||
let w = size * t;
|
||||
let offset = Math.pow(t - 0.5, 2);
|
||||
points.push([offset, w], [size-offset, w]);
|
||||
points.push([w, offset], [w, size-offset]);
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
|
||||
function addGhostStructure({_r_vertex, _triangles, _halfedges}) {
|
||||
const numSolidSides = _triangles.length;
|
||||
const ghost_r = _r_vertex.length;
|
||||
|
||||
let numUnpairedSides = 0, firstUnpairedEdge = -1;
|
||||
let r_unpaired_s = []; // seed to side
|
||||
for (let s = 0; s < numSolidSides; s++) {
|
||||
if (_halfedges[s] === -1) {
|
||||
numUnpairedSides++;
|
||||
r_unpaired_s[_triangles[s]] = s;
|
||||
firstUnpairedEdge = s;
|
||||
}
|
||||
}
|
||||
|
||||
let r_newvertex = _r_vertex.concat([[500, 500]]);
|
||||
let s_newstart_r = new Int32Array(numSolidSides + 3 * numUnpairedSides);
|
||||
s_newstart_r.set(_triangles);
|
||||
let s_newopposite_s = new Int32Array(numSolidSides + 3 * numUnpairedSides);
|
||||
s_newopposite_s.set(_halfedges);
|
||||
|
||||
for (let i = 0, s = firstUnpairedEdge;
|
||||
i < numUnpairedSides;
|
||||
i++, s = r_unpaired_s[s_newstart_r[s_next_s(s)]]) {
|
||||
|
||||
// Construct a ghost side for s
|
||||
let ghost_s = numSolidSides + 3 * i;
|
||||
s_newopposite_s[s] = ghost_s;
|
||||
s_newopposite_s[ghost_s] = s;
|
||||
s_newstart_r[ghost_s] = s_newstart_r[s_next_s(s)];
|
||||
|
||||
// Construct the rest of the ghost triangle
|
||||
s_newstart_r[ghost_s + 1] = s_newstart_r[s];
|
||||
s_newstart_r[ghost_s + 2] = ghost_r;
|
||||
let k = numSolidSides + (3 * i + 4) % (3 * numUnpairedSides);
|
||||
s_newopposite_s[ghost_s + 2] = k;
|
||||
s_newopposite_s[k] = ghost_s + 2;
|
||||
}
|
||||
|
||||
return {
|
||||
numSolidSides,
|
||||
_r_vertex: r_newvertex,
|
||||
_triangles: s_newstart_r,
|
||||
_halfedges: s_newopposite_s
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Build a dual mesh from points, with ghost triangles around the exterior.
|
||||
*
|
||||
* The builder assumes 0 ≤ x < 1000, 0 ≤ y < 1000
|
||||
*
|
||||
* Options:
|
||||
* - To have equally spaced points added around the 1000x1000 boundary,
|
||||
* pass in boundarySpacing > 0 with the spacing value. If using Poisson
|
||||
* disc points, I recommend 1.5 times the spacing used for Poisson disc.
|
||||
*
|
||||
* Phases:
|
||||
* - Your own set of points
|
||||
* - Poisson disc points
|
||||
*
|
||||
* The mesh generator runs some sanity checks but does not correct the
|
||||
* generated points.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* Build a mesh with poisson disc points and a boundary:
|
||||
*
|
||||
* new MeshBuilder({boundarySpacing: 150})
|
||||
* .addPoisson(Poisson, 100)
|
||||
* .create()
|
||||
*/
|
||||
class MeshBuilder {
|
||||
/** If boundarySpacing > 0 there will be a boundary added around the 1000x1000 area */
|
||||
public MeshBuilder (float boundarySpacing) {
|
||||
let boundaryPoints = boundarySpacing > 0 ? addBoundaryPoints(boundarySpacing, 1000) : [];
|
||||
this.points = boundaryPoints;
|
||||
this.numBoundaryRegions = boundaryPoints.length;
|
||||
}
|
||||
|
||||
/** Points should be [x, y] */
|
||||
addPoints(newPoints) {
|
||||
for (let p of newPoints) {
|
||||
this.points.push(p);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Points will be [x, y] */
|
||||
getNonBoundaryPoints() {
|
||||
return this.points.slice(this.numBoundaryRegions);
|
||||
}
|
||||
|
||||
/** (used for more advanced mixing of different mesh types) */
|
||||
clearNonBoundaryPoints() {
|
||||
this.points.splice(this.numBoundaryRegions, this.points.length);
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Pass in the constructor from the poisson-disk-sampling module */
|
||||
addPoisson(Poisson, spacing, random=Math.random) {
|
||||
let generator = new Poisson({
|
||||
shape: [1000, 1000],
|
||||
minDistance: spacing,
|
||||
}, random);
|
||||
this.points.forEach(p => generator.addPoint(p));
|
||||
this.points = generator.fill();
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Build and return a TriangleMesh */
|
||||
create(runChecks=false) {
|
||||
// TODO: use Float32Array instead of this, so that we can
|
||||
// construct directly from points read in from a file
|
||||
let delaunator = Delaunator.from(this.points);
|
||||
let graph = {
|
||||
_r_vertex: this.points,
|
||||
_triangles: delaunator.triangles,
|
||||
_halfedges: delaunator.halfedges
|
||||
};
|
||||
|
||||
if (runChecks) {
|
||||
checkPointInequality(graph);
|
||||
checkTriangleInequality(graph);
|
||||
}
|
||||
|
||||
graph = addGhostStructure(graph);
|
||||
graph.numBoundaryRegions = this.numBoundaryRegions;
|
||||
if (runChecks) {
|
||||
checkMeshConnectivity(graph);
|
||||
}
|
||||
|
||||
return new TriangleMesh(graph);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,369 +0,0 @@
|
||||
package org.atriasoft.arkon;
|
||||
|
||||
// @ts-check
|
||||
/*
|
||||
* From https://www.redblobgames.com/maps/mapgen4/
|
||||
* Copyright 2018 Red Blob Games <redblobgames@gmail.com>
|
||||
* License: Apache v2.0 <http://www.apache.org/licenses/LICENSE-2.0.html>
|
||||
*
|
||||
* This module has the procedural map generation algorithms (elevations, rivers)
|
||||
*/
|
||||
import SimplexNoise from'simplex-noise';
|
||||
import FlatQueue from'flatqueue';import{makeRandFloat}from'@redblobgames/prng';
|
||||
|
||||
const mountain={slope:20,density:1500,};
|
||||
|
||||
/**
|
||||
* @typedef { import("./types").Mesh } Mesh
|
||||
*/
|
||||
|
||||
|
||||
class Map {
|
||||
Mesh mesh;
|
||||
float[] peaks_t;
|
||||
long seed = -1;
|
||||
int spacing;
|
||||
float mountainJaggedness = Float.NEGATIVE_INFINITY;
|
||||
float windAngleDeg = Float.POSITIVE_INFINITY;
|
||||
float[] t_elevation;
|
||||
float[] r_elevation;
|
||||
float[] r_humidity;
|
||||
float[] t_moisture;
|
||||
float[] r_rainfall;
|
||||
int[] t_downslope_s;
|
||||
int[] order_t;
|
||||
float[] t_flow;
|
||||
float[] s_flow;
|
||||
int[] wind_order_r;
|
||||
float[] r_wind_sort;
|
||||
float[] t_mountain_distance;
|
||||
|
||||
/**
|
||||
* @param {Mesh} mesh
|
||||
* @param {number[]} peaks_t - array of triangle indices for mountain peaks
|
||||
* @param {any} param - global parameters
|
||||
*/
|
||||
public Map(Mesh mesh, float[] peaks_t, Config param) {
|
||||
this.mesh = mesh;
|
||||
this.peaks_t = peaks_t;
|
||||
this.seed = -1;
|
||||
this.spacing = param.spacing;
|
||||
this.t_elevation = new float[mesh.numTriangles];
|
||||
this.r_elevation = new float[mesh.numRegions];
|
||||
this.r_humidity = new float[mesh.numRegions];
|
||||
this.t_moisture = new float[mesh.numTriangles];
|
||||
this.r_rainfall = new float[mesh.numRegions];
|
||||
this.t_downslope_s = new int[mesh.numTriangles];
|
||||
this.order_t = new int[mesh.numTriangles];
|
||||
this.t_flow = new float[mesh.numTriangles];
|
||||
this.s_flow = new float[mesh.numSides];
|
||||
this.wind_order_r = new int[mesh.numRegions];
|
||||
this.r_wind_sort = new float[mesh.numRegions];
|
||||
this.t_mountain_distance = new float[mesh.numTriangles];
|
||||
}
|
||||
/**
|
||||
* Mountains are peaks surrounded by steep dropoffs. In the point
|
||||
* selection process (mesh.js) we pick the mountain peak locations.
|
||||
* Here we calculate a distance field from peaks to all other points.
|
||||
*
|
||||
* We'll use breadth first search for this because it's simple and
|
||||
* fast. Dijkstra's Algorithm would produce a more accurate distance
|
||||
* field, but we only need an approximation. For increased
|
||||
* interestingness, we add some randomness to the distance field.
|
||||
*
|
||||
* @param {Mesh} mesh
|
||||
* @param {number[]} seeds_t - a list of triangles with mountain peaks
|
||||
* @param {number} spacing - the global param.spacing value
|
||||
* @param {number} jaggedness - how much randomness to mix into the distances
|
||||
* @param {function(): number} randFloat - random number generator
|
||||
* @param {Float32Array} t_distance - the distance field indexed by t, OUTPUT
|
||||
*/
|
||||
public static void calculateMountainDistance(mesh,seeds_t,spacing,jaggedness,randFloat,t_distance){t_distance.fill(-1);let queue_t=seeds_t.concat([]);for(let i=0;i<queue_t.length;i++){let current_t=queue_t[i];for(let j=0;j<3;j++){let s=3*current_t+j;let neighbor_t=mesh.s_outer_t(s);if(t_distance[neighbor_t]==-1){let increment=spacing*(1+jaggedness*(randFloat()-randFloat()));t_distance[neighbor_t]=t_distance[current_t]+increment;queue_t.push(neighbor_t);}}}}
|
||||
|
||||
/**
|
||||
* Save noise values in arrays.
|
||||
*
|
||||
* @param {function(): number} randFloat - random number generator
|
||||
* @param {Mesh} mesh
|
||||
*/
|
||||
public static void precalculateNoise(randFloat,mesh){const noise=new SimplexNoise(randFloat);let{numTriangles}=mesh;let t_noise0=new float[numTriangles),t_noise1=new float[numTriangles),t_noise2=new float[numTriangles),t_noise3=new float[numTriangles),t_noise4=new float[numTriangles),t_noise5=new float[numTriangles),t_noise6=new float[numTriangles);for(let t=0;t<numTriangles;t++){let nx=(mesh.t_x(t)-500)/500,ny=(mesh.t_y(t)-500)/500;t_noise0[t]=noise.noise2D(nx,ny);t_noise1[t]=noise.noise2D(2*nx+5,2*ny+5);t_noise2[t]=noise.noise2D(4*nx+7,4*ny+7);t_noise3[t]=noise.noise2D(8*nx+9,8*ny+9);t_noise4[t]=noise.noise2D(16*nx+15,16*ny+15);t_noise5[t]=noise.noise2D(32*nx+31,32*ny+31);t_noise6[t]=noise.noise2D(64*nx+67,64*ny+67);}return{t_noise0,t_noise1,t_noise2,t_noise3,t_noise4,t_noise5,t_noise6};}
|
||||
|
||||
|
||||
void assignTriangleElevation(elevationParam, constraints) {
|
||||
let {mesh, t_elevation, t_mountain_distance, precomputed} = this;
|
||||
let {numTriangles, numSolidTriangles} = mesh;
|
||||
}
|
||||
|
||||
// Assign elevations to triangles TODO: separate message,
|
||||
// store the interpolated values in an array, or maybe for
|
||||
// each painted cell store which triangle elevations have to
|
||||
// be updated, so that we don't have to recalculate the entire
|
||||
// map's interpolated values each time (involves copying 50k
|
||||
// floats instead of 16k floats), or maybe send a message with
|
||||
// the bounding box of the painted area
|
||||
float constraintAt(float x, float y) {
|
||||
// https://en.wikipedia.org/wiki/Bilinear_interpolation
|
||||
const C = constraints.constraints, size = constraints.size;
|
||||
x *= size; y *= size;
|
||||
let xInt = Math.floor(x),
|
||||
yInt = Math.floor(y),
|
||||
xFrac = x - xInt,
|
||||
yFrac = y - yInt;
|
||||
if (0 <= xInt && xInt+1 < size && 0 <= yInt && yInt+1 < size) {
|
||||
let p = size * yInt + xInt;
|
||||
let e00 = C[p],
|
||||
e01 = C[p + 1],
|
||||
e10 = C[p + size],
|
||||
e11 = C[p + size + 1];
|
||||
return ((e00 * (1 - xFrac) + e01 * xFrac) * (1 - yFrac)
|
||||
+ (e10 * (1 - xFrac) + e11 * xFrac) * yFrac);
|
||||
} else {
|
||||
return -1.0;
|
||||
}
|
||||
}
|
||||
for (let t = 0; t < numSolidTriangles; t++) {
|
||||
let e = constraintAt(mesh.t_x(t)/1000, mesh.t_y(t)/1000);
|
||||
// TODO: e*e*e*e seems too steep for this, as I want this
|
||||
// to apply mostly at the original coastlines and not
|
||||
// elsewhere
|
||||
t_elevation[t] = e + elevationParam.noisy_coastlines * (1 - e*e*e*e) * (precomputed.t_noise4[t] + precomputed.t_noise5[t]/2 + precomputed.t_noise6[t]/4);
|
||||
}
|
||||
|
||||
// For land triangles, mix hill and mountain terrain together
|
||||
const mountain_slope = mountain.slope,
|
||||
mountain_sharpness = Math.pow(2, elevationParam.mountain_sharpness),
|
||||
{t_noise0, t_noise1, t_noise2, t_noise4} = precomputed;
|
||||
for (let t = 0; t < numTriangles; t++) {
|
||||
let e = t_elevation[t];
|
||||
if (e > 0) {
|
||||
/* Mix two sources of elevation:
|
||||
*
|
||||
* 1. eh: Hills are formed using simplex noise. These
|
||||
* are very low amplitude, and the main purpose is
|
||||
* to make the rivers meander. The amplitude
|
||||
* doesn't make much difference in the river
|
||||
* meandering. These hills shouldn't be
|
||||
* particularly visible so I've kept the amplitude
|
||||
* low.
|
||||
*
|
||||
* 2. em: Mountains are formed using something similar to
|
||||
* worley noise. These form distinct peaks, with
|
||||
* varying distance between them.
|
||||
*/
|
||||
// TODO: precompute eh, em per triangle
|
||||
let noisiness = 1.0 - 0.5 * (1 + t_noise0[t]);
|
||||
let eh = (1 + noisiness * t_noise4[t] + (1 - noisiness) * t_noise2[t]) * elevationParam.hill_height;
|
||||
if (eh < 0.01) { eh = 0.01; }
|
||||
let em = 1 - mountain_slope/mountain_sharpness * t_mountain_distance[t];
|
||||
if (em < 0.01) { em = 0.01; }
|
||||
let weight = e * e;
|
||||
e = (1-weight) * eh + weight * em;
|
||||
} else {
|
||||
/* Add noise to make it more interesting. */
|
||||
e *= elevationParam.ocean_depth + t_noise1[t];
|
||||
}
|
||||
if (e < -1.0) { e = -1.0; }
|
||||
if (e > +1.0) { e = +1.0; }
|
||||
t_elevation[t] = e;
|
||||
}
|
||||
}
|
||||
|
||||
void assignRegionElevation(elevationParam, constraints) {
|
||||
let {mesh, t_elevation, r_elevation} = this;
|
||||
let {numRegions, _r_in_s, _halfedges} = mesh;
|
||||
for (let r = 0; r < numRegions; r++) {
|
||||
let count = 0, e = 0, water = false;
|
||||
const s0 = _r_in_s[r];
|
||||
let incoming = s0;
|
||||
do {
|
||||
let t = (incoming/3) | 0;
|
||||
e += t_elevation[t];
|
||||
water = water || t_elevation[t] < 0.0;
|
||||
let outgoing = mesh.s_next_s(incoming);
|
||||
incoming = _halfedges[outgoing];
|
||||
count++;
|
||||
} while (incoming !== s0);
|
||||
e /= count;
|
||||
if (water && e >= 0) { e = -0.001; }
|
||||
r_elevation[r] = e;
|
||||
}
|
||||
}
|
||||
|
||||
void assignElevation(elevationParam, constraints) {
|
||||
if (this.seed !== elevationParam.seed || this.mountainJaggedness !== elevationParam.mountain_jagged) {
|
||||
this.mountainJaggedness = elevationParam.mountain_jagged;
|
||||
calculateMountainDistance(
|
||||
this.mesh, this.peaks_t, this.spacing,
|
||||
this.mountainJaggedness, makeRandFloat(elevationParam.seed),
|
||||
this.t_mountain_distance
|
||||
);
|
||||
}
|
||||
|
||||
if (this.seed !== elevationParam.seed) {
|
||||
// TODO: function should reuse existing arrays
|
||||
this.seed = elevationParam.seed;
|
||||
this.precomputed = precalculateNoise(makeRandFloat(elevationParam.seed), this.mesh);
|
||||
}
|
||||
|
||||
this.assignTriangleElevation(elevationParam, constraints);
|
||||
this.assignRegionElevation(elevationParam);
|
||||
}
|
||||
|
||||
void assignRainfall(biomesParam) {
|
||||
const {mesh, wind_order_r, r_wind_sort, r_humidity, r_rainfall, r_elevation} = this;
|
||||
const {numRegions, _r_in_s, _halfedges} = mesh;
|
||||
|
||||
if (biomesParam.wind_angle_deg != this.windAngleDeg) {
|
||||
this.windAngleDeg = biomesParam.wind_angle_deg;
|
||||
const windAngleRad = Math.PI / 180 * this.windAngleDeg;
|
||||
const windAngleVec = [Math.cos(windAngleRad), Math.sin(windAngleRad)];
|
||||
for (let r = 0; r < numRegions; r++) {
|
||||
wind_order_r[r] = r;
|
||||
r_wind_sort[r] = mesh.r_x(r) * windAngleVec[0] + mesh.r_y(r) * windAngleVec[1];
|
||||
}
|
||||
wind_order_r.sort((r1, r2) => r_wind_sort[r1] - r_wind_sort[r2]);
|
||||
}
|
||||
|
||||
for (let r of wind_order_r) {
|
||||
let count = 0, sum = 0.0;
|
||||
let s0 = _r_in_s[r], incoming = s0;
|
||||
do {
|
||||
let neighbor_r = mesh.s_begin_r(incoming);
|
||||
if (r_wind_sort[neighbor_r] < r_wind_sort[r]) {
|
||||
count++;
|
||||
sum += r_humidity[neighbor_r];
|
||||
}
|
||||
let outgoing = mesh.s_next_s(incoming);
|
||||
incoming = _halfedges[outgoing];
|
||||
} while (incoming !== s0);
|
||||
|
||||
let humidity = 0.0, rainfall = 0.0;
|
||||
if (count > 0) {
|
||||
humidity = sum / count;
|
||||
rainfall += biomesParam.raininess * humidity;
|
||||
}
|
||||
if (mesh.r_boundary(r)) {
|
||||
humidity = 1.0;
|
||||
}
|
||||
if (r_elevation[r] < 0.0) {
|
||||
let evaporation = biomesParam.evaporation * -r_elevation[r];
|
||||
humidity += evaporation;
|
||||
}
|
||||
if (humidity > 1.0 - r_elevation[r]) {
|
||||
let orographicRainfall = biomesParam.rain_shadow * (humidity - (1.0 - r_elevation[r]));
|
||||
rainfall += biomesParam.raininess * orographicRainfall;
|
||||
humidity -= orographicRainfall;
|
||||
}
|
||||
r_rainfall[r] = rainfall;
|
||||
r_humidity[r] = humidity;
|
||||
}
|
||||
}
|
||||
|
||||
void assignRivers(riversParam) {
|
||||
let {mesh, t_moisture, r_rainfall, t_elevation, t_downslope_s, order_t, t_flow, s_flow} = this;
|
||||
assignDownslope(mesh, t_elevation, t_downslope_s, order_t);
|
||||
assignMoisture(mesh, r_rainfall, t_moisture);
|
||||
assignFlow(mesh, riversParam, order_t, t_elevation, t_moisture, t_downslope_s, t_flow, s_flow);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Use prioritized graph exploration to assign river flow direction
|
||||
*
|
||||
* @param {Mesh} mesh
|
||||
* @param {Float32Array} t_elevation - elevation per triangle
|
||||
* @param {Int32Array} t_downslope_s - OUT parameter - the side each triangle flows out of
|
||||
* @param {Int32Array} order_t - OUT parameter - pre-order in which the graph was traversed,
|
||||
* so roots of the tree always get visited before leaves; use reverse to visit leaves before roots
|
||||
*/
|
||||
let queue = new FlatQueue();
|
||||
|
||||
void assignDownslope(mesh, t_elevation, /* out */ t_downslope_s, /* out */ order_t) {
|
||||
/* Use a priority queue, starting with the ocean triangles and
|
||||
* moving upwards using elevation as the priority, to visit all
|
||||
* the land triangles */
|
||||
let {numTriangles} = mesh,
|
||||
queue_in = 0;
|
||||
t_downslope_s.fill(-999);
|
||||
/* Part 1: non-shallow ocean triangles get downslope assigned to the lowest neighbor */
|
||||
for (let t = 0; t < numTriangles; t++) {
|
||||
if (t_elevation[t] < -0.1) {
|
||||
let best_s = -1, best_e = t_elevation[t];
|
||||
for (let j = 0; j < 3; j++) {
|
||||
let s = 3 * t + j,
|
||||
e = t_elevation[mesh.s_outer_t(s)];
|
||||
if (e < best_e) {
|
||||
best_e = e;
|
||||
best_s = s;
|
||||
}
|
||||
}
|
||||
order_t[queue_in++] = t;
|
||||
t_downslope_s[t] = best_s;
|
||||
queue.push(t, t_elevation[t]);
|
||||
}
|
||||
}
|
||||
/* Part 2: land triangles get visited in elevation priority */
|
||||
for (let queue_out = 0; queue_out < numTriangles; queue_out++) {
|
||||
let current_t = queue.pop();
|
||||
for (let j = 0; j < 3; j++) {
|
||||
let s = 3 * current_t + j;
|
||||
let neighbor_t = mesh.s_outer_t(s); // uphill from current_t
|
||||
if (t_downslope_s[neighbor_t] === -999) {
|
||||
t_downslope_s[neighbor_t] = mesh.s_opposite_s(s);
|
||||
order_t[queue_in++] = neighbor_t;
|
||||
queue.push(neighbor_t, t_elevation[neighbor_t]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Mesh} mesh
|
||||
* @param {Float32Array} r_rainfall - per region
|
||||
* @param {Float32Array} t_moisture - OUT parameter - per triangle
|
||||
*/
|
||||
void assignMoisture(mesh, r_rainfall, /* out */ t_moisture) {
|
||||
const {numTriangles} = mesh;
|
||||
for (let t = 0; t < numTriangles; t++) {
|
||||
let moisture = 0.0;
|
||||
for (let i = 0; i < 3; i++) {
|
||||
let s = 3 * t + i,
|
||||
r = mesh.s_begin_r(s);
|
||||
moisture += r_rainfall[r] / 3;
|
||||
}
|
||||
t_moisture[t] = moisture;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Int32Array} order_t
|
||||
* @param {any} riversParam
|
||||
* @param {Float32Array} t_elevation
|
||||
* @param {Float32Array} t_moisture
|
||||
* @param {Int32Array} t_downslope_s
|
||||
* @param {Float32Array} t_flow
|
||||
*/
|
||||
void assignFlow(mesh, riversParam, order_t, t_elevation, t_moisture, t_downslope_s, /* out */ t_flow, /* out */ s_flow) {
|
||||
let {numTriangles, _halfedges} = mesh;
|
||||
s_flow.fill(0);
|
||||
for (let t = 0; t < numTriangles; t++) {
|
||||
if (t_elevation[t] >= 0.0) {
|
||||
t_flow[t] = riversParam.flow * t_moisture[t] * t_moisture[t];
|
||||
} else {
|
||||
t_flow[t] = 0;
|
||||
}
|
||||
}
|
||||
for (let i = order_t.length-1; i >= 0; i--) {
|
||||
let tributary_t = order_t[i];
|
||||
let flow_s = t_downslope_s[tributary_t];
|
||||
let trunk_t = (_halfedges[flow_s] / 3) | 0;
|
||||
if (flow_s >= 0) {
|
||||
t_flow[trunk_t] += t_flow[tributary_t];
|
||||
s_flow[flow_s] += t_flow[tributary_t]; // TODO: s_flow[t_downslope_s[t]] === t_flow[t]; redundant?
|
||||
if (t_elevation[trunk_t] > t_elevation[tributary_t] && t_elevation[tributary_t] >= 0.0) {
|
||||
t_elevation[trunk_t] = t_elevation[tributary_t];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package org.atriasoft.arkon;
|
||||
/* I use the TriangleMesh from my dual mesh library, but I add fields to it,
|
||||
* so I'm declaring that here for type checking purposes. */
|
||||
|
||||
//#import TriangleMesh from'@redblobgames/dual-mesh';
|
||||
|
||||
class Mesh extends TriangleMesh {
|
||||
float[] s_length; /* indexed on s */
|
||||
}
|
@ -1,553 +0,0 @@
|
||||
package org.atriasoft.arkon;
|
||||
/*
|
||||
* From http://www.redblobgames.com/maps/mapgen4/
|
||||
* Copyright 2018 Red Blob Games <redblobgames@gmail.com>
|
||||
* License: Apache v2.0 <http://www.apache.org/licenses/LICENSE-2.0.html>
|
||||
*
|
||||
* This module uses webgl+regl to render the generated maps
|
||||
*/
|
||||
|
||||
|
||||
import colormap from './colormap';
|
||||
import Geometry from './geometry';
|
||||
import createREGL from 'regl';
|
||||
const regl = createREGL({
|
||||
canvas: "#mapgen4",
|
||||
extensions: ['OES_element_index_uint']
|
||||
});
|
||||
|
||||
|
||||
const river_texturemap = regl.texture({data: Geometry.createRiverBitmap(), mipmap: 'nice', min: 'mipmap', mag: 'linear', premultiplyAlpha: true});
|
||||
const fbo_texture_size = 2048;
|
||||
const fbo_land_texture = regl.texture({width: fbo_texture_size, height: fbo_texture_size});
|
||||
const fbo_land = regl.framebuffer({color: [fbo_land_texture]});
|
||||
const fbo_depth_texture = regl.texture({width: fbo_texture_size, height: fbo_texture_size});
|
||||
const fbo_z = regl.framebuffer({color: [fbo_depth_texture]});
|
||||
const fbo_river_texture = regl.texture({width: fbo_texture_size, height: fbo_texture_size});
|
||||
const fbo_river = regl.framebuffer({color: [fbo_river_texture]});
|
||||
const fbo_final_texture = regl.texture({width: fbo_texture_size, height: fbo_texture_size, min: 'linear', mag: 'linear'});
|
||||
const fbo_final = regl.framebuffer({color: [fbo_final_texture]});
|
||||
|
||||
|
||||
/* draw rivers to a texture, which will be draped on the map surface */
|
||||
const drawRivers = regl({
|
||||
frag: `
|
||||
precision mediump float;
|
||||
uniform sampler2D u_rivertexturemap;
|
||||
varying vec2 v_uv;
|
||||
const vec3 blue = vec3(0.2, 0.5, 0.7);
|
||||
void main() {
|
||||
vec4 color = texture2D(u_rivertexturemap, v_uv);
|
||||
gl_FragColor = vec4(blue * color.a, color.a);
|
||||
// gl_FragColor = color;
|
||||
}`,
|
||||
|
||||
vert: `
|
||||
precision highp float;
|
||||
uniform mat4 u_projection;
|
||||
attribute vec4 a_xyuv;
|
||||
varying vec2 v_uv;
|
||||
void main() {
|
||||
v_uv = a_xyuv.ba;
|
||||
gl_Position = vec4(u_projection * vec4(a_xyuv.xy, 0, 1));
|
||||
}`,
|
||||
|
||||
uniforms: {
|
||||
u_projection: regl.prop('u_projection'),
|
||||
u_rivertexturemap: river_texturemap,
|
||||
},
|
||||
|
||||
framebuffer: fbo_river,
|
||||
blend: {
|
||||
enable: true,
|
||||
func: {src:'one', dst:'one minus src alpha'},
|
||||
equation: {
|
||||
rgb: 'add',
|
||||
alpha: 'add'
|
||||
},
|
||||
color: [0, 0, 0, 0]
|
||||
},
|
||||
depth: {
|
||||
enable: false,
|
||||
},
|
||||
count: regl.prop('count'),
|
||||
attributes: {
|
||||
a_xyuv: regl.prop('a_xyuv'),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
/* write 16-bit elevation to a texture's G,R channels; the B,A channels are empty */
|
||||
const drawLand = regl({
|
||||
frag: `
|
||||
precision highp float;
|
||||
uniform sampler2D u_water;
|
||||
uniform float u_outline_water;
|
||||
varying float v_e;
|
||||
varying vec2 v_xy;
|
||||
void main() {
|
||||
float e = 0.5 * (1.0 + v_e);
|
||||
float river = texture2D(u_water, v_xy).a;
|
||||
if (e >= 0.5) {
|
||||
float bump = u_outline_water / 256.0;
|
||||
float L1 = e + bump;
|
||||
float L2 = (e - 0.5) * (bump * 100.0) + 0.5;
|
||||
// TODO: simplify equation
|
||||
e = min(L1, mix(L1, L2, river));
|
||||
}
|
||||
gl_FragColor = vec4(fract(256.0*e), e, 0, 1);
|
||||
// NOTE: it should be using the floor instead of rounding, but
|
||||
// rounding produces a nice looking artifact, so I'll keep that
|
||||
// until I can produce the artifact properly (e.g. bug → feature).
|
||||
// Using linear filtering on the texture also smooths out the artifacts.
|
||||
// gl_FragColor = vec4(fract(256.0*e), floor(256.0*e)/256.0, 0, 1);
|
||||
// NOTE: need to use GL_NEAREST filtering for this texture because
|
||||
// blending R,G channels independently isn't going to give the right answer
|
||||
}`,
|
||||
|
||||
vert: `
|
||||
precision highp float;
|
||||
uniform mat4 u_projection;
|
||||
attribute vec2 a_xy;
|
||||
attribute vec2 a_em; // NOTE: moisture channel unused
|
||||
varying float v_e;
|
||||
varying vec2 v_xy;
|
||||
void main() {
|
||||
vec4 pos = vec4(u_projection * vec4(a_xy, 0, 1));
|
||||
v_xy = (1.0 + pos.xy) * 0.5;
|
||||
v_e = a_em.x;
|
||||
gl_Position = pos;
|
||||
}`,
|
||||
|
||||
uniforms: {
|
||||
u_projection: regl.prop('u_projection'),
|
||||
u_water: regl.prop('u_water'),
|
||||
u_outline_water: regl.prop('u_outline_water'),
|
||||
u_m: regl.prop('u_m'),
|
||||
},
|
||||
|
||||
framebuffer: fbo_land,
|
||||
depth: {
|
||||
enable: false,
|
||||
},
|
||||
elements: regl.prop('elements'),
|
||||
attributes: {
|
||||
a_xy: regl.prop('a_xy'),
|
||||
a_em: regl.prop('a_em'),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
/* using the same perspective as the final output, write the depth
|
||||
to a texture, G,R channels; used for outline shader */
|
||||
const drawDepth = regl({
|
||||
frag: `
|
||||
precision highp float;
|
||||
varying float v_z;
|
||||
void main() {
|
||||
gl_FragColor = vec4(fract(256.0*v_z), floor(256.0*v_z)/256.0, 0, 1);
|
||||
}`,
|
||||
|
||||
vert: `
|
||||
precision highp float;
|
||||
uniform mat4 u_projection;
|
||||
attribute vec2 a_xy;
|
||||
attribute vec2 a_em;
|
||||
varying float v_z;
|
||||
void main() {
|
||||
vec4 pos = vec4(u_projection * vec4(a_xy, max(0.0, a_em.x), 1));
|
||||
v_z = a_em.x;
|
||||
gl_Position = pos;
|
||||
}`,
|
||||
|
||||
framebuffer: fbo_z,
|
||||
elements: regl.prop('elements'),
|
||||
attributes: {
|
||||
a_xy: regl.prop('a_xy'),
|
||||
a_em: regl.prop('a_em'),
|
||||
},
|
||||
uniforms: {
|
||||
u_projection: regl.prop('u_projection'),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
/* draw the final image by draping the biome colors over the geometry;
|
||||
note that u_depth and u_mapdata are both encoded with G,R channels
|
||||
for 16 bits */
|
||||
const drawDrape = regl({
|
||||
frag: `
|
||||
precision highp float;
|
||||
uniform sampler2D u_colormap;
|
||||
uniform sampler2D u_mapdata;
|
||||
uniform sampler2D u_water;
|
||||
uniform sampler2D u_depth;
|
||||
uniform vec2 u_light_angle;
|
||||
uniform float u_inverse_texture_size,
|
||||
u_slope, u_flat,
|
||||
u_ambient, u_overhead,
|
||||
u_outline_strength, u_outline_coast, u_outline_water,
|
||||
u_outline_depth, u_outline_threshold,
|
||||
u_biome_colors;
|
||||
varying vec2 v_uv, v_xy, v_em;
|
||||
|
||||
const vec2 _decipher = vec2(1.0/256.0, 1);
|
||||
float decipher(vec4 v) {
|
||||
return dot(_decipher, v.xy);
|
||||
}
|
||||
|
||||
const vec3 neutral_land_biome = vec3(0.9, 0.8, 0.7);
|
||||
const vec3 neutral_water_biome = 0.8 * neutral_land_biome;
|
||||
|
||||
void main() {
|
||||
vec2 sample_offset = vec2(0.5*u_inverse_texture_size, 0.5*u_inverse_texture_size);
|
||||
vec2 pos = v_uv + sample_offset;
|
||||
vec2 dx = vec2(u_inverse_texture_size, 0),
|
||||
dy = vec2(0, u_inverse_texture_size);
|
||||
|
||||
float zE = decipher(texture2D(u_mapdata, pos + dx));
|
||||
float zN = decipher(texture2D(u_mapdata, pos - dy));
|
||||
float zW = decipher(texture2D(u_mapdata, pos - dx));
|
||||
float zS = decipher(texture2D(u_mapdata, pos + dy));
|
||||
vec3 slope_vector = normalize(vec3(zS-zN, zE-zW, u_overhead*2.0*u_inverse_texture_size));
|
||||
vec3 light_vector = normalize(vec3(u_light_angle, mix(u_slope, u_flat, slope_vector.z)));
|
||||
float light = u_ambient + max(0.0, dot(light_vector, slope_vector));
|
||||
vec2 em = texture2D(u_mapdata, pos).yz;
|
||||
em.y = v_em.y;
|
||||
vec3 neutral_biome_color = neutral_land_biome;
|
||||
vec4 water_color = texture2D(u_water, pos);
|
||||
if (em.x >= 0.5) { em.x -= u_outline_water / 256.0 * (1.0 - water_color.a); }
|
||||
vec3 biome_color = texture2D(u_colormap, em).rgb;
|
||||
if (em.x < 0.5) { water_color.a = 0.0; neutral_biome_color = neutral_water_biome; } // don't draw rivers in the ocean
|
||||
water_color = mix(vec4(neutral_water_biome * (1.2 - water_color.a), water_color.a), water_color, u_biome_colors);
|
||||
biome_color = mix(neutral_biome_color, biome_color, u_biome_colors);
|
||||
// if (fract(em.x * 10.0) < 10.0 * fwidth(em.x)) { biome_color = vec3(0,0,0); } // contour lines
|
||||
|
||||
// TODO: add noise texture based on biome
|
||||
|
||||
// TODO: once I remove the elevation rounding artifact I can simplify
|
||||
// this by taking the max first and then deciphering
|
||||
float depth0 = decipher(texture2D(u_depth, v_xy)),
|
||||
depth1 = max(max(decipher(texture2D(u_depth, v_xy + u_outline_depth*(-dy-dx))),
|
||||
decipher(texture2D(u_depth, v_xy + u_outline_depth*(-dy+dx)))),
|
||||
decipher(texture2D(u_depth, v_xy + u_outline_depth*(-dy)))),
|
||||
depth2 = max(max(decipher(texture2D(u_depth, v_xy + u_outline_depth*(dy-dx))),
|
||||
decipher(texture2D(u_depth, v_xy + u_outline_depth*(dy+dx)))),
|
||||
decipher(texture2D(u_depth, v_xy + u_outline_depth*(dy))));
|
||||
float outline = 1.0 + u_outline_strength * (max(u_outline_threshold, depth1-depth0) - u_outline_threshold);
|
||||
|
||||
// Add coast outline, but avoid it if there's a river nearby
|
||||
float neighboring_river = max(
|
||||
max(
|
||||
texture2D(u_water, pos + u_outline_depth * dx).a,
|
||||
texture2D(u_water, pos - u_outline_depth * dx).a
|
||||
),
|
||||
max(
|
||||
texture2D(u_water, pos + u_outline_depth * dy).a,
|
||||
texture2D(u_water, pos - u_outline_depth * dy).a
|
||||
)
|
||||
);
|
||||
if (em.x <= 0.5 && max(depth1, depth2) > 1.0/256.0 && neighboring_river <= 0.2) { outline += u_outline_coast * 256.0 * (max(depth1, depth2) - 2.0*(em.x - 0.5)); }
|
||||
|
||||
gl_FragColor = vec4(mix(biome_color, water_color.rgb, water_color.a) * light / outline, 1);
|
||||
}`,
|
||||
|
||||
vert: `
|
||||
precision highp float;
|
||||
uniform mat4 u_projection;
|
||||
attribute vec2 a_xy;
|
||||
attribute vec2 a_em;
|
||||
varying vec2 v_em, v_uv, v_xy;
|
||||
varying float v_e, v_m;
|
||||
void main() {
|
||||
vec4 pos = vec4(u_projection * vec4(a_xy, max(0.0, a_em.x), 1));
|
||||
v_uv = a_xy / 1000.0;
|
||||
v_em = a_em;
|
||||
v_xy = (1.0 + pos.xy) * 0.5;
|
||||
gl_Position = pos;
|
||||
}`,
|
||||
|
||||
framebuffer: fbo_final,
|
||||
elements: regl.prop('elements'),
|
||||
attributes: {
|
||||
a_xy: regl.prop('a_xy'),
|
||||
a_em: regl.prop('a_em'),
|
||||
},
|
||||
uniforms: {
|
||||
u_projection: regl.prop('u_projection'),
|
||||
u_depth: regl.prop('u_depth'),
|
||||
u_colormap: regl.texture({width: colormap.width, height: colormap.height, data: colormap.data, wrapS: 'clamp', wrapT: 'clamp'}),
|
||||
u_mapdata: () => fbo_land_texture,
|
||||
u_water: regl.prop('u_water'),
|
||||
u_inverse_texture_size: 1.5 / fbo_texture_size,
|
||||
u_light_angle: regl.prop('u_light_angle'),
|
||||
u_slope: regl.prop('u_slope'),
|
||||
u_flat: regl.prop('u_flat'),
|
||||
u_ambient: regl.prop('u_ambient'),
|
||||
u_overhead: regl.prop('u_overhead'),
|
||||
u_outline_depth: regl.prop('u_outline_depth'),
|
||||
u_outline_coast: regl.prop('u_outline_coast'),
|
||||
u_outline_water: regl.prop('u_outline_water'),
|
||||
u_outline_strength: regl.prop('u_outline_strength'),
|
||||
u_outline_threshold: regl.prop('u_outline_threshold'),
|
||||
u_biome_colors: regl.prop('u_biome_colors'),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
/* draw the high resolution final output to the screen, smoothed and resized */
|
||||
const drawFinal = regl({
|
||||
frag: `
|
||||
precision mediump float;
|
||||
uniform sampler2D u_texture;
|
||||
uniform vec2 u_offset;
|
||||
varying vec2 v_uv;
|
||||
void main() {
|
||||
gl_FragColor = texture2D(u_texture, v_uv + u_offset);
|
||||
}`,
|
||||
|
||||
vert: `
|
||||
precision highp float;
|
||||
attribute vec2 a_uv;
|
||||
varying vec2 v_uv;
|
||||
void main() {
|
||||
v_uv = a_uv;
|
||||
gl_Position = vec4(2.0 * v_uv - 1.0, 0.0, 1.0);
|
||||
}`,
|
||||
|
||||
uniforms: {
|
||||
u_texture: fbo_final_texture,
|
||||
u_offset: regl.prop('u_offset'),
|
||||
},
|
||||
depth: {
|
||||
enable: false,
|
||||
},
|
||||
count: 3,
|
||||
attributes: {
|
||||
a_uv: [-2, 0, 0, -2, 2, 2]
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
||||
class Renderer {
|
||||
constructor (mesh) {
|
||||
this.resizeCanvas();
|
||||
|
||||
this.topdown = mat4.create();
|
||||
mat4.translate(this.topdown, this.topdown, [-1, -1, 0, 0]);
|
||||
mat4.scale(this.topdown, this.topdown, [1/500, 1/500, 1, 1]);
|
||||
|
||||
this.projection = mat4.create();
|
||||
this.inverse_projection = mat4.create();
|
||||
|
||||
this.a_quad_xy = new Float32Array(2 * (mesh.numRegions + mesh.numTriangles));
|
||||
this.a_quad_em = new Float32Array(2 * (mesh.numRegions + mesh.numTriangles));
|
||||
this.quad_elements = new Int32Array(3 * mesh.numSolidSides);
|
||||
/* NOTE: The maximum number of river triangles will be when
|
||||
* there's a single binary tree that has every node filled.
|
||||
* Each of the N/2 leaves will produce 1 output triangle and
|
||||
* each of the N/2 nodes will produce 2 triangles. On average
|
||||
* there will be 1.5 output triangles per input triangle. */
|
||||
this.a_river_xyuv = new Float32Array(1.5 * 3 * 4 * mesh.numSolidTriangles);
|
||||
this.numRiverTriangles = 0;
|
||||
|
||||
Geometry.setMeshGeometry(mesh, this.a_quad_xy);
|
||||
|
||||
this.buffer_quad_xy = regl.buffer({
|
||||
usage: 'static',
|
||||
type: 'float',
|
||||
data: this.a_quad_xy,
|
||||
});
|
||||
|
||||
this.buffer_quad_em = regl.buffer({
|
||||
usage: 'dynamic',
|
||||
type: 'float',
|
||||
length: 4 * this.a_quad_em.length,
|
||||
});
|
||||
|
||||
this.buffer_quad_elements = regl.elements({
|
||||
primitive: 'triangles',
|
||||
usage: 'dynamic',
|
||||
type: 'uint32',
|
||||
length: 4 * this.quad_elements.length,
|
||||
count: this.quad_elements.length,
|
||||
});
|
||||
|
||||
this.buffer_river_xyuv = regl.buffer({
|
||||
usage: 'dynamic',
|
||||
type: 'float',
|
||||
length: 4 * this.a_river_xyuv.length,
|
||||
});
|
||||
|
||||
this.screenshotCanvas = document.createElement('canvas');
|
||||
this.screenshotCanvas.width = fbo_texture_size;
|
||||
this.screenshotCanvas.height = fbo_texture_size;
|
||||
this.screenshotCallback = null;
|
||||
|
||||
this.renderParam = undefined;
|
||||
this.startDrawingLoop();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {[number, number]} coords - screen coordinates 0 ≤ x ≤ 1, 0 ≤ y ≤ 1
|
||||
* @returns {[number, number]} - world coords 0 ≤ x ≤ 1000, 0 ≤ y ≤ 1000
|
||||
*/
|
||||
screenToWorld(coords) {
|
||||
/* convert from screen 2d (inverted y) to 4d for matrix multiply */
|
||||
let glCoords = vec4.fromValues(
|
||||
coords[0] * 2 - 1,
|
||||
1 - coords[1] * 2,
|
||||
/* TODO: z should be 0 only when tilt_deg is 0;
|
||||
* need to figure out the proper z value here */
|
||||
0,
|
||||
1
|
||||
);
|
||||
/* it returns vec4 but we only need vec2; they're compatible */
|
||||
return vec4.transformMat4([], glCoords, this.inverse_projection);
|
||||
}
|
||||
|
||||
/* Update the buffers with the latest map data */
|
||||
updateMap() {
|
||||
this.buffer_quad_em.subdata(this.a_quad_em);
|
||||
this.buffer_quad_elements.subdata(this.quad_elements);
|
||||
this.buffer_river_xyuv.subdata(this.a_river_xyuv.subarray(0, 4 * 3 * this.numRiverTriangles));
|
||||
}
|
||||
|
||||
/* Allow drawing at a different resolution than the internal texture size */
|
||||
resizeCanvas() {
|
||||
let canvas = /** @type{HTMLCanvasElement} */(document.getElementById('mapgen4'));
|
||||
let size = canvas.clientWidth;
|
||||
size = 2048; /* could be smaller to increase performance */
|
||||
if (canvas.width !== size || canvas.height !== size) {
|
||||
console.log(`Resizing canvas from ${canvas.width}x${canvas.height} to ${size}x${size}`);
|
||||
canvas.width = canvas.height = size;
|
||||
regl.poll();
|
||||
}
|
||||
}
|
||||
|
||||
startDrawingLoop() {
|
||||
/* Only draw when render parameters have been passed in;
|
||||
* otherwise skip the render and wait for the next tick */
|
||||
regl.frame(context => {
|
||||
const renderParam = this.renderParam;
|
||||
if (!renderParam) { return; }
|
||||
this.renderParam = undefined;
|
||||
|
||||
if (this.numRiverTriangles > 0) {
|
||||
drawRivers({
|
||||
count: 3 * this.numRiverTriangles,
|
||||
a_xyuv: this.buffer_river_xyuv,
|
||||
u_projection: this.topdown,
|
||||
});
|
||||
}
|
||||
|
||||
drawLand({
|
||||
elements: this.buffer_quad_elements,
|
||||
a_xy: this.buffer_quad_xy,
|
||||
a_em: this.buffer_quad_em,
|
||||
u_projection: this.topdown,
|
||||
u_water: fbo_river_texture,
|
||||
u_outline_water: renderParam.outline_water,
|
||||
});
|
||||
|
||||
/* Standard rotation for orthographic view */
|
||||
mat4.identity(this.projection);
|
||||
mat4.rotateX(this.projection, this.projection, (180 + renderParam.tilt_deg) * Math.PI/180);
|
||||
mat4.rotateZ(this.projection, this.projection, renderParam.rotate_deg * Math.PI/180);
|
||||
|
||||
/* Top-down oblique copies column 2 (y input) to row 3 (z
|
||||
* output). Typical matrix libraries such as glm's mat4 or
|
||||
* Unity's Matrix4x4 or Unreal's FMatrix don't have this
|
||||
* this.projection built-in. For mapgen4 I merge orthographic
|
||||
* (which will *move* part of y-input to z-output) and
|
||||
* top-down oblique (which will *copy* y-input to z-output).
|
||||
* <https://en.wikipedia.org/wiki/Oblique_projection> */
|
||||
this.projection[9] = 1;
|
||||
|
||||
/* Scale and translate works on the hybrid this.projection */
|
||||
mat4.scale(this.projection, this.projection, [renderParam.zoom/100, renderParam.zoom/100, renderParam.mountain_height * renderParam.zoom/100, 1]);
|
||||
mat4.translate(this.projection, this.projection, [-renderParam.x, -renderParam.y, 0, 0]);
|
||||
|
||||
/* Keep track of the inverse matrix for mapping mouse to world coordinates */
|
||||
mat4.invert(this.inverse_projection, this.projection);
|
||||
|
||||
if (renderParam.outline_depth > 0) {
|
||||
drawDepth({
|
||||
elements: this.buffer_quad_elements,
|
||||
a_xy: this.buffer_quad_xy,
|
||||
a_em: this.buffer_quad_em,
|
||||
u_projection: this.projection
|
||||
});
|
||||
}
|
||||
|
||||
drawDrape({
|
||||
elements: this.buffer_quad_elements,
|
||||
a_xy: this.buffer_quad_xy,
|
||||
a_em: this.buffer_quad_em,
|
||||
u_water: fbo_river_texture,
|
||||
u_depth: fbo_depth_texture,
|
||||
u_projection: this.projection,
|
||||
u_light_angle: [
|
||||
Math.cos(Math.PI/180 * (renderParam.light_angle_deg + renderParam.rotate_deg)),
|
||||
Math.sin(Math.PI/180 * (renderParam.light_angle_deg + renderParam.rotate_deg)),
|
||||
],
|
||||
u_slope: renderParam.slope,
|
||||
u_flat: renderParam.flat,
|
||||
u_ambient: renderParam.ambient,
|
||||
u_overhead: renderParam.overhead,
|
||||
u_outline_depth: renderParam.outline_depth * 5 * renderParam.zoom,
|
||||
u_outline_coast: renderParam.outline_coast,
|
||||
u_outline_water: renderParam.outline_water,
|
||||
u_outline_strength: renderParam.outline_strength,
|
||||
u_outline_threshold: renderParam.outline_threshold / 1000,
|
||||
u_biome_colors: renderParam.biome_colors,
|
||||
});
|
||||
|
||||
drawFinal({
|
||||
u_offset: [0.5 / fbo_texture_size, 0.5 / fbo_texture_size],
|
||||
});
|
||||
|
||||
if (this.screenshotCallback) {
|
||||
// TODO: regl says I need to use preserveDrawingBuffer
|
||||
const gl = regl._gl;
|
||||
const ctx = this.screenshotCanvas.getContext('2d');
|
||||
const imageData = ctx.getImageData(0, 0, fbo_texture_size, fbo_texture_size);
|
||||
const bytesPerRow = 4 * fbo_texture_size;
|
||||
const buffer = new Uint8Array(bytesPerRow * fbo_texture_size);
|
||||
gl.readPixels(0, 0, fbo_texture_size, fbo_texture_size, gl.RGBA, gl.UNSIGNED_BYTE, buffer);
|
||||
|
||||
// Flip row order from WebGL to Canvas
|
||||
for (let y = 0; y < fbo_texture_size; y++) {
|
||||
const rowBuffer = new Uint8Array(buffer.buffer, y * bytesPerRow, bytesPerRow);
|
||||
imageData.data.set(rowBuffer, (fbo_texture_size-y-1) * bytesPerRow);
|
||||
}
|
||||
ctx.putImageData(imageData, 0, 0);
|
||||
|
||||
this.screenshotCallback();
|
||||
this.screenshotCallback = null;
|
||||
}
|
||||
|
||||
// I don't have to clear fbo_em because it doesn't have depth
|
||||
// and will be redrawn every frame. I do have to clear
|
||||
// fbo_river because even though it doesn't have depth, it
|
||||
// doesn't draw all triangles.
|
||||
fbo_river.use(() => {
|
||||
regl.clear({color: [0, 0, 0, 0]});
|
||||
});
|
||||
fbo_z.use(() => {
|
||||
regl.clear({color: [0, 0, 0, 1], depth: 1});
|
||||
});
|
||||
fbo_final.use(() => {
|
||||
regl.clear({color: [0.2, 0.3, 0.5, 1], depth: 1});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
updateView(renderParam) {
|
||||
this.renderParam = renderParam;
|
||||
}
|
||||
}
|
||||
|
||||
export default Renderer;
|
@ -1,5 +0,0 @@
|
||||
package org.atriasoft.arkon;
|
||||
|
||||
public class TriangleMesh {
|
||||
|
||||
}
|
@ -1,127 +0,0 @@
|
||||
/*
|
||||
* From https://www.redblobgames.com/x/1845-draggable/
|
||||
* Copyright 2018 Red Blob Games <redblobgames@gmail.com>
|
||||
* License: Apache v2.0 <http://www.apache.org/licenses/LICENSE-2.0.html>
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
class Draggable {
|
||||
/** Props should be an object:
|
||||
*
|
||||
* el: HTMLElement - required - the element where the drag handlers are attached
|
||||
* reference: HTMLElement - defaults to el - the element where positions are calculated
|
||||
*
|
||||
* The reference element should not move during the drag operation.
|
||||
*
|
||||
* start(event) - optional - called when drag operation starts
|
||||
* drag(event) - optional - called each time mouse/finger moves
|
||||
* end(event) - optional - called when the drag operation ends
|
||||
*
|
||||
* event.raw will have the raw (native) event
|
||||
*
|
||||
* TODO: document (coords, uninstall, mouse_button, touch_identifier)
|
||||
*/
|
||||
constructor(props) {
|
||||
this.reference = props.el;
|
||||
Object.assign(this, props);
|
||||
|
||||
let mouse_cleanup = () => null;
|
||||
const mouseDown = (event) => {
|
||||
if (event.button != 0) { return; /* don't trap right click */ }
|
||||
mouse_cleanup(); // in case a drag is already in progress
|
||||
const rect = this.reference.getBoundingClientRect();
|
||||
let operation = Object.create(this);
|
||||
operation.mouse_button = event.button;
|
||||
operation.raw = event;
|
||||
operation.start(operation.coords(rect, event));
|
||||
|
||||
function mouseMove(event) {
|
||||
operation.raw = event;
|
||||
operation.drag(operation.coords(rect, event));
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
function mouseUp(event) {
|
||||
operation.raw = event;
|
||||
operation.end(operation.coords(rect, event));
|
||||
mouse_cleanup();
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
mouse_cleanup = () => {
|
||||
window.removeEventListener('mousemove', mouseMove);
|
||||
window.removeEventListener('mouseup', mouseUp);
|
||||
mouse_cleanup = () => null;
|
||||
};
|
||||
|
||||
window.addEventListener('mousemove', mouseMove);
|
||||
window.addEventListener('mouseup', mouseUp);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
};
|
||||
|
||||
let touch_begin = [];
|
||||
const touchEvent = (event) => {
|
||||
const rect = this.reference.getBoundingClientRect();
|
||||
for (let i = 0; i < event.changedTouches.length; i++) {
|
||||
const touch = event.changedTouches[i];
|
||||
let current = this.coords(rect, touch);
|
||||
current.raw = touch;
|
||||
switch (event.type) {
|
||||
case 'touchstart':
|
||||
touch_begin[touch.identifier] = Object.create(this);
|
||||
touch_begin[touch.identifier].touch_identifier = touch.identifier;
|
||||
touch_begin[touch.identifier].start(current);
|
||||
break;
|
||||
case 'touchmove':
|
||||
touch_begin[touch.identifier].drag(current);
|
||||
break;
|
||||
case 'touchend':
|
||||
touch_begin[touch.identifier].end(current);
|
||||
touch_begin[touch.identifier] = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
};
|
||||
|
||||
this.el.style.touchAction = 'none';
|
||||
this.el.addEventListener('mousedown', mouseDown);
|
||||
this.el.addEventListener('touchstart', touchEvent);
|
||||
this.el.addEventListener('touchmove', touchEvent);
|
||||
this.el.addEventListener('touchend', touchEvent);
|
||||
|
||||
this.uninstall = function() {
|
||||
this.el.style.touchAction = '';
|
||||
this.el.removeEventListener('mousedown', mouseDown);
|
||||
this.el.removeEventListener('touchstart', touchEvent);
|
||||
this.el.removeEventListener('touchmove', touchEvent);
|
||||
this.el.removeEventListener('touchend', touchEvent);
|
||||
mouse_cleanup();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// NOTE: this doesn't take into account css transforms
|
||||
// <https://bugzilla.mozilla.org/show_bug.cgi?id=972041>
|
||||
coords(rect, event) {
|
||||
let coords = {x: event.clientX - rect.left, y: event.clientY - rect.top};
|
||||
const svg = this.reference instanceof SVGSVGElement? this.reference : this.reference.ownerSVGElement;
|
||||
if (svg) {
|
||||
// NOTE: svg.getScreenCTM already factors in the bounding rect
|
||||
// so there's no need to subtract rect, or even call getBoundingClientRect
|
||||
let point = svg.createSVGPoint();
|
||||
point.x = event.clientX;
|
||||
point.y = event.clientY;
|
||||
coords = point.matrixTransform(svg.getScreenCTM().inverse());
|
||||
}
|
||||
return coords;
|
||||
}
|
||||
|
||||
start(_event) {}
|
||||
drag(_event) {}
|
||||
end(_event) {}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
<div style="width:auto">
|
||||
<style>
|
||||
html, body { margin: 0; padding: 0; }
|
||||
button { text-align: center; padding: 0; background: hsl(60,20%,90%); border-radius: 4px; cursor: pointer; }
|
||||
button svg { width: 100%; height: 100%; }
|
||||
button text { text-anchor: middle; font-size: 24px; font-family: var(--sans-serif, Arial); }
|
||||
button.current-control { background: hsl(60,100%,80%); outline: 2px solid hsl(220,50%,50%); }
|
||||
button:focus { outline: none; }
|
||||
input[type="range"] { cursor: ew-resize; margin-left: 0; margin-right: 0; }
|
||||
button:disabled, input:disabled { cursor: unset; opacity: 0.25; }
|
||||
#ui {
|
||||
display: grid;
|
||||
min-height: calc(100vmin - 130px);
|
||||
grid-template-rows: repeat(3, 40px) calc(100vmin - 130px - 120px - 40px);
|
||||
grid-template-columns: 1fr calc(100vmin - 130px) repeat(6, 20px) 1fr;
|
||||
grid-row-gap: 10px;
|
||||
grid-column-gap: 10px;
|
||||
}
|
||||
#map { grid-area: 1 / 2 / span 4 / span 1; width:100%; height:100%; }
|
||||
#small { grid-area: 1 / 3 / span 1 / span 2; }
|
||||
#medium { grid-area: 1 / 5 / span 1 / span 2; }
|
||||
#large { grid-area: 1 / 7 / span 1 / span 2; }
|
||||
#ocean { grid-area: 2 / 3 / span 1 / span 3; }
|
||||
#shallow { grid-area: 2 / 6 / span 1 / span 3; }
|
||||
#valley { grid-area: 3 / 3 / span 1 / span 3; }
|
||||
#mountain { grid-area: 3 / 6 / span 1 / span 3; }
|
||||
#sliders { grid-area: 4 / 3 / span 1 / span 6; overflow-y: scroll; overflow-x: clip; line-height: 1.1; }
|
||||
|
||||
@media (orientation: portrait) {
|
||||
/* Put the buttons on bottom instead of on the right */
|
||||
#ui {
|
||||
grid-template-rows: calc(100vmin) repeat(6, 20px) 1fr;
|
||||
grid-template-columns: 50px repeat(2, 70px) calc(100vmin - 50px - 140px - 40px);
|
||||
}
|
||||
#map { grid-area: 1 / 1 / span 1 / span 6; }
|
||||
#small { grid-area: 2 / 1 / span 2 / span 1; }
|
||||
#medium { grid-area: 4 / 1 / span 2 / span 1; }
|
||||
#large { grid-area: 6 / 1 / span 2 / span 1; }
|
||||
#ocean { grid-area: 2 / 2 / span 3 / span 1; }
|
||||
#shallow { grid-area: 2 / 3 / span 3 / span 1; }
|
||||
#valley { grid-area: 5 / 2 / span 3 / span 1; }
|
||||
#mountain { grid-area: 5 / 3 / span 3 / span 1; }
|
||||
#sliders { grid-area: 2 / 4 / span 7 / span 1; justify-self: end; width: 100%; column-width: 20ch; }
|
||||
}
|
||||
|
||||
#mapgen4 { width: 100%; height: 100%; cursor: crosshair; }
|
||||
#sliders h3 {
|
||||
background-color: hsl(60,20%,90%);
|
||||
margin: 0.5em 0;
|
||||
padding: 0.5em;
|
||||
font-family: var(--sans-serif, sans-serif);
|
||||
font-size: 66%;
|
||||
}
|
||||
#sliders label {
|
||||
display: block;
|
||||
font-size: 66%;
|
||||
}
|
||||
#sliders label > * {
|
||||
max-width: 99%;
|
||||
}
|
||||
#sliders label span {
|
||||
font-family: var(--monospace, monospace);
|
||||
display: inline-block;
|
||||
width: 17ch;
|
||||
}
|
||||
#button-reset {
|
||||
display: inline-block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
width: 100%;
|
||||
height: 2em;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div id="ui">
|
||||
|
||||
<button id="small"><svg viewBox="-50 -50 100 100"><circle r="20"/></svg></button>
|
||||
<button id="medium"><svg viewBox="-50 -50 100 100"><circle r="35"/></svg></button>
|
||||
<button id="large"><svg viewBox="-50 -50 100 100"><circle r="50"/></svg></button>
|
||||
|
||||
<button id="ocean" title="Ocean"><svg viewBox="-50 -50 100 100"><text y="45">Ocean</text><path d="M -50,-30 q 25,-20 50,0 q 25,20 50,0 l 0,50 l -100,0 z" fill="hsl(240,50%,40%)"/></svg></button>
|
||||
<button id="shallow" title="Water"><svg viewBox="-50 -50 100 100"><text y="45">Water</text><path d="M -50,-20 q 15,20 30,0 q 20,20 40,0 q 15,20 30,0 l 0,40 l -100,0 z" fill="hsl(200,50%,70%)"/></svg></button>
|
||||
<button id="valley" title="Valley"><svg viewBox="-50 -50 100 100"><text y="45">Valley</text><path d="M -50,-20 c 20,10 80,10 100,0 l 0,40 l -100,0 z" fill="hsl(100,40%,60%)"/></svg></button>
|
||||
<button id="mountain" title="Mountain"><svg viewBox="-50 -50 100 100"><text y="45">Mountains</text><g fill="hsl(60,50%,40%)" stroke="white" stroke-width="2"><path d="M -30,20 l 30,-60 l 30,60 z"/><path d="M -50,20 l 20,-40 l 20,40 z"/><path d="M 10,20 l 15,-30 l 15,30 z"/></g></svg></button>
|
||||
|
||||
<div id="sliders">
|
||||
<button id="button-reset">Reset</button>
|
||||
</div>
|
||||
|
||||
<div id="map"><canvas id="mapgen4" width="2048" height="2048"/></div>
|
||||
</div>
|
||||
<script defer="defer" src="draggable.v2.js"></script>
|
||||
<script defer="defer" src="build/_bundle.js"></script>
|
||||
</div>
|
||||
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* From https://www.redblobgames.com/maps/mapgen4/
|
||||
* Copyright 2018 Red Blob Games <redblobgames@gmail.com>
|
||||
* License: Apache v2.0 <http://www.apache.org/licenses/LICENSE-2.0.html>
|
||||
*
|
||||
* Generate the points used for the mountains peaks and the mesh.
|
||||
*
|
||||
* This step is slow and it doesn't vary from one run to the next so
|
||||
* it makes sense to precompute the results and save them to a file.
|
||||
*
|
||||
* File format: Int16Array, where first element is the number of
|
||||
* mountain peaks M, then the next M elements are the mountainIndices into the
|
||||
* mesh that have mountain peaks, then the rest are X,Y
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const {makeRandFloat} = require('@redblobgames/prng');
|
||||
const Poisson = require('poisson-disk-sampling');
|
||||
const {mesh, spacing, mountainSpacing} = require('./config');
|
||||
|
||||
const filename = `build/points-${spacing}.data`;
|
||||
|
||||
/* First generate the mountain points */
|
||||
let mountainPoints = new Poisson([1000, 1000], mountainSpacing, undefined, undefined, makeRandFloat(mesh.seed)).fill();
|
||||
|
||||
/* Generate the rest of the mesh points with the mountain points as constraints */
|
||||
let generator = new Poisson([1000, 1000], spacing, undefined, undefined, makeRandFloat(mesh.seed));
|
||||
for (let p of mountainPoints) { generator.addPoint(p); }
|
||||
let meshPoints = generator.fill();
|
||||
|
||||
/* For better compression, I want to sort the points. However, that
|
||||
* means the mountain points are no longer at the beginning of the
|
||||
* array, so I need some way to find them. Solution: keep track of the
|
||||
* original position of the points, then write out the new positions
|
||||
* of the mountain points. */
|
||||
meshPoints = meshPoints.map((p, i) => [p[0] | 0, p[1] | 0, i]);
|
||||
meshPoints.sort((a, b) => a[0] === b[0] ? a[1] - b[1] : a[0] - b[0]);
|
||||
|
||||
/* File format described at top */
|
||||
let mountainIndices = [];
|
||||
for (let i = 0; i < meshPoints.length; i++) {
|
||||
if (meshPoints[i][2] < mountainPoints.length) {
|
||||
mountainIndices.push(i);
|
||||
}
|
||||
}
|
||||
let flat = [mountainPoints.length].concat(mountainIndices);
|
||||
for (let p of meshPoints) {
|
||||
flat.push(p[0], p[1]);
|
||||
}
|
||||
|
||||
|
||||
fs.writeFileSync(filename, Uint16Array.from(flat));
|
||||
|
||||
/* For debugging, write an ascii version: */
|
||||
// fs.writeFileSync(filename, JSON.stringify(flat));
|
@ -1,268 +0,0 @@
|
||||
/*
|
||||
* From http://www.redblobgames.com/maps/magpen4/
|
||||
* Copyright 2017 Red Blob Games <redblobgames@gmail.com>
|
||||
* License: Apache v2.0 <http://www.apache.org/licenses/LICENSE-2.0.html>
|
||||
*/
|
||||
|
||||
import {vec2} from 'gl-matrix';
|
||||
import Map from './map';
|
||||
|
||||
/**
|
||||
* @typedef { import("./types").Mesh } Mesh
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Fill a buffer with data from the mesh.
|
||||
*
|
||||
* @param {Mesh} mesh
|
||||
* @param {Float32Array} P - x,y for each region, then for each triangle
|
||||
*/
|
||||
function setMeshGeometry(mesh, P) {
|
||||
let {numRegions, numTriangles} = mesh;
|
||||
if (P.length !== 2 * (numRegions + numTriangles)) { throw "wrong size"; }
|
||||
|
||||
let p = 0;
|
||||
for (let r = 0; r < numRegions; r++) {
|
||||
P[p++] = mesh.r_x(r);
|
||||
P[p++] = mesh.r_y(r);
|
||||
}
|
||||
for (let t = 0; t < numTriangles; t++) {
|
||||
P[p++] = mesh.t_x(t);
|
||||
P[p++] = mesh.t_y(t);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Fill an indexed buffer with data from the map.
|
||||
*
|
||||
* @param {Map} map
|
||||
* @param {Int32Array} I - indices into the data array
|
||||
* @param {Float32Array} P - elevation, rainfall data
|
||||
*/
|
||||
function setMapGeometry(map, I, P) {
|
||||
// TODO: V should probably depend on the slope, or elevation, or maybe it should be 0.95 in mountainous areas and 0.99 elsewhere
|
||||
const V = 0.95; // reduce elevation in valleys
|
||||
let {mesh, s_flow, r_elevation, t_elevation, r_rainfall} = map;
|
||||
let {numSolidSides, numRegions, numTriangles} = mesh;
|
||||
|
||||
if (I.length !== 3 * numSolidSides) { throw "wrong size"; }
|
||||
if (P.length !== 2 * (numRegions + numTriangles)) { throw "wrong size"; }
|
||||
|
||||
let p = 0;
|
||||
for (let r = 0; r < numRegions; r++) {
|
||||
P[p++] = r_elevation[r];
|
||||
P[p++] = r_rainfall[r];
|
||||
}
|
||||
for (let t = 0; t < numTriangles; t++) {
|
||||
P[p++] = V * t_elevation[t];
|
||||
let s0 = 3*t;
|
||||
let r1 = mesh.s_begin_r(s0),
|
||||
r2 = mesh.s_begin_r(s0+1),
|
||||
r3 = mesh.s_begin_r(s0+2);
|
||||
P[p++] = 1/3 * (r_rainfall[r1] + r_rainfall[r2] + r_rainfall[r3]);
|
||||
}
|
||||
|
||||
// TODO: split this into its own function; it can be updated separately, and maybe not as often
|
||||
let i = 0;
|
||||
for (let s = 0; s < numSolidSides; s++) {
|
||||
let opposite_s = mesh.s_opposite_s(s),
|
||||
r1 = mesh.s_begin_r(s),
|
||||
r2 = mesh.s_begin_r(opposite_s),
|
||||
t1 = mesh.s_inner_t(s),
|
||||
t2 = mesh.s_inner_t(opposite_s);
|
||||
|
||||
// Each quadrilateral is turned into two triangles, so each
|
||||
// half-edge gets turned into one. There are two ways to fold
|
||||
// a quadrilateral. This is usually a nuisance but in this
|
||||
// case it's a feature. See the explanation here
|
||||
// https://www.redblobgames.com/x/1725-procedural-elevation/#rendering
|
||||
let coast = r_elevation[r1] < 0.0 || r_elevation[r2] < 0.0;
|
||||
if (coast || s_flow[s] > 0 || s_flow[opposite_s] > 0) {
|
||||
// It's a coastal or river edge, forming a valley
|
||||
I[i++] = r1; I[i++] = numRegions+t2; I[i++] = numRegions+t1;
|
||||
} else {
|
||||
// It's a ridge
|
||||
I[i++] = r1; I[i++] = r2; I[i++] = numRegions+t1;
|
||||
}
|
||||
}
|
||||
|
||||
if (I.length !== i) { throw "wrong size"; }
|
||||
if (P.length !== p) { throw "wrong size"; }
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a bitmap that will be used for texture mapping
|
||||
* BEND textures will be ordered: {blank side, input side, output side}
|
||||
* FORK textures will be ordered: {passive input side, active input side, output side}
|
||||
*
|
||||
* Cols will be the input flow rate
|
||||
* Rows will be the output flow rate
|
||||
*/
|
||||
function assignTextureCoordinates(spacing, numSizes, textureSize) {
|
||||
/* create (numSizes+1)^2 size combinations, each with two triangles */
|
||||
function UV(x, y) {
|
||||
return {xy: [x, y], uv: [(x+0.5)/textureSize, (y+0.5)/textureSize]};
|
||||
}
|
||||
|
||||
let triangles = [[]];
|
||||
let width = Math.floor((textureSize - 2*spacing) / (2*numSizes+3)) - spacing,
|
||||
height = Math.floor((textureSize - 2*spacing) / (numSizes+1)) - spacing;
|
||||
for (let row = 0; row <= numSizes; row++) {
|
||||
triangles[row] = [];
|
||||
for (let col = 0; col <= numSizes; col++) {
|
||||
let baseX = spacing + (2 * spacing + 2 * width) * col,
|
||||
baseY = spacing + (spacing + height) * row;
|
||||
triangles[row][col] = [
|
||||
[UV(baseX + width, baseY),
|
||||
UV(baseX, baseY + height),
|
||||
UV(baseX + 2*width, baseY + height)],
|
||||
[UV(baseX + 2*width + spacing, baseY + height),
|
||||
UV(baseX + 3*width + spacing, baseY),
|
||||
UV(baseX + width + spacing, baseY)]
|
||||
];
|
||||
}
|
||||
}
|
||||
return triangles;
|
||||
}
|
||||
|
||||
|
||||
// TODO: turn this into an object :-/
|
||||
const riverTextureSpacing = 40; // TODO: should depend on river size
|
||||
const numRiverSizes = 24; // NOTE: too high and rivers are low quality; too low and there's not enough variation
|
||||
const riverTextureSize = 4096;
|
||||
const riverMaximumFractionOfWidth = 0.5;
|
||||
const riverTexturePositions = assignTextureCoordinates(riverTextureSpacing, numRiverSizes, riverTextureSize);
|
||||
function createRiverBitmap() {
|
||||
let canvas = document.createElement('canvas');
|
||||
canvas.width = canvas.height = riverTextureSize;
|
||||
let ctx = canvas.getContext('2d');
|
||||
|
||||
function lineWidth(i) {
|
||||
const spriteSize = riverTexturePositions[0][1][0][0].xy[0] - riverTexturePositions[0][0][0][0].xy[0];
|
||||
return i / numRiverSizes * spriteSize * riverMaximumFractionOfWidth;
|
||||
}
|
||||
ctx.lineCap = "round";
|
||||
for (let row = 0; row <= numRiverSizes; row++) {
|
||||
for (let col = 0; col <= numRiverSizes; col++) {
|
||||
for (let type = 0; type < 2; type++) {
|
||||
let pos = riverTexturePositions[row][col][type];
|
||||
ctx.save();
|
||||
ctx.beginPath();
|
||||
ctx.rect(pos[1].xy[0] - riverTextureSpacing/2, pos[0].xy[1] - riverTextureSpacing/2,
|
||||
pos[2].xy[0] - pos[1].xy[0] + riverTextureSpacing, pos[2].xy[1] - pos[0].xy[1] + riverTextureSpacing);
|
||||
// ctx.clip(); // TODO: to make this work right, the spacing needs to vary based on the river size, I think
|
||||
|
||||
let center = [(pos[0].xy[0] + pos[1].xy[0] + pos[2].xy[0]) / 3,
|
||||
(pos[0].xy[1] + pos[1].xy[1] + pos[2].xy[1]) / 3];
|
||||
let midpoint12 = vec2.lerp([], pos[1].xy, pos[2].xy, 0.5);
|
||||
let midpoint20 = vec2.lerp([], pos[2].xy, pos[0].xy, 0.5);
|
||||
|
||||
ctx.strokeStyle = "hsl(200,50%,35%)";
|
||||
if (type === 1) {
|
||||
// TODO: river delta/fork sprite
|
||||
} else {
|
||||
const w = 1; /* TODO: draw a path and fill it; that will allow variable width */
|
||||
let c = vec2.lerp([], pos[1].xy, pos[2].xy, 0.5 - w),
|
||||
d = vec2.lerp([], pos[1].xy, pos[2].xy, 0.5 + w),
|
||||
a = vec2.lerp([], pos[0].xy, pos[1].xy, 0.5 - w),
|
||||
f = vec2.lerp([], pos[0].xy, pos[1].xy, 0.5 + w),
|
||||
b = null /* TODO: intersect lines */,
|
||||
e = null /* TODO: intersect lines */;
|
||||
|
||||
if (col > 0) {
|
||||
ctx.lineWidth = Math.min(lineWidth(col), lineWidth(row));
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(midpoint12[0], midpoint12[1]);
|
||||
ctx.quadraticCurveTo(center[0], center[1], midpoint20[0], midpoint20[1]);
|
||||
ctx.stroke();
|
||||
} else {
|
||||
ctx.lineWidth = lineWidth(row);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(center[0], center[1]);
|
||||
ctx.lineTo(midpoint20[0], midpoint20[1]);
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return canvas;
|
||||
};
|
||||
|
||||
|
||||
function clamp(x, lo, hi) {
|
||||
if (x < lo) { x = lo; }
|
||||
if (x > hi) { x = hi; }
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill a buffer with river geometry
|
||||
*
|
||||
* @param {Map} map
|
||||
* @param {number} spacing - global param.spacing value
|
||||
* @param {any} riversParam - global param.rivers
|
||||
* @param {Float32Array} P - array of x,y,u,v triples for the river triangles
|
||||
* @returns {number} - how many triangles were needed (at most numSolidTriangles)
|
||||
*/
|
||||
function setRiverTextures(map, spacing, riversParam, P) {
|
||||
const MIN_FLOW = Math.exp(riversParam.lg_min_flow);
|
||||
const RIVER_WIDTH = Math.exp(riversParam.lg_river_width);
|
||||
let {mesh, t_downslope_s, s_flow} = map;
|
||||
let {numSolidTriangles, s_length} = mesh;
|
||||
|
||||
function riverSize(s, flow) {
|
||||
// TODO: performance: build a table of flow to width
|
||||
if (s < 0) { return 1; }
|
||||
let width = Math.sqrt(flow - MIN_FLOW) * spacing * RIVER_WIDTH;
|
||||
let size = Math.ceil(width * numRiverSizes / s_length[s]);
|
||||
return clamp(size, 1, numRiverSizes);
|
||||
}
|
||||
|
||||
let p = 0, uv = [0, 0, 0, 0, 0, 0];
|
||||
for (let t = 0; t < numSolidTriangles; t++) {
|
||||
let out_s = t_downslope_s[t];
|
||||
let out_flow = s_flow[out_s];
|
||||
if (out_s < 0 || out_flow < MIN_FLOW) continue;
|
||||
let r1 = mesh.s_begin_r(3*t ),
|
||||
r2 = mesh.s_begin_r(3*t + 1),
|
||||
r3 = mesh.s_begin_r(3*t + 2);
|
||||
let in1_s = mesh.s_next_s(out_s);
|
||||
let in2_s = mesh.s_next_s(in1_s);
|
||||
let in1_flow = s_flow[mesh.s_opposite_s(in1_s)];
|
||||
let in2_flow = s_flow[mesh.s_opposite_s(in2_s)];
|
||||
let textureRow = riverSize(out_s, out_flow);
|
||||
|
||||
function add(r, c, i, j, k) {
|
||||
const T = riverTexturePositions[r][c][0];
|
||||
P[p ] = mesh.r_x(r1);
|
||||
P[p + 1] = mesh.r_y(r1);
|
||||
P[p + 4] = mesh.r_x(r2);
|
||||
P[p + 5] = mesh.r_y(r2);
|
||||
P[p + 8] = mesh.r_x(r3);
|
||||
P[p + 9] = mesh.r_y(r3);
|
||||
P[p + 4*(out_s - 3*t) + 2] = T[i].uv[0];
|
||||
P[p + 4*(out_s - 3*t) + 3] = T[i].uv[1];
|
||||
P[p + 4*(in1_s - 3*t) + 2] = T[j].uv[0];
|
||||
P[p + 4*(in1_s - 3*t) + 3] = T[j].uv[1];
|
||||
P[p + 4*(in2_s - 3*t) + 2] = T[k].uv[0];
|
||||
P[p + 4*(in2_s - 3*t) + 3] = T[k].uv[1];
|
||||
p += 12;
|
||||
}
|
||||
|
||||
if (in1_flow >= MIN_FLOW) {
|
||||
add(textureRow, riverSize(in1_s, in1_flow), 0, 2, 1);
|
||||
}
|
||||
if (in2_flow >= MIN_FLOW) {
|
||||
add(textureRow, riverSize(in2_s, in2_flow), 2, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return p / 12;
|
||||
};
|
||||
|
||||
export default {setMeshGeometry, createRiverBitmap, setMapGeometry, setRiverTextures};
|
@ -1,186 +0,0 @@
|
||||
/*
|
||||
* From http://www.redblobgames.com/maps/mapgen4/
|
||||
* Copyright 2018 Red Blob Games <redblobgames@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
import param from './config'; // param in the Config
|
||||
import {makeMesh} from './mesh';
|
||||
import Painting from './painting';
|
||||
import Renderer from './render';
|
||||
|
||||
|
||||
Config initialParams = new Config();
|
||||
|
||||
|
||||
/** @typedef { import("./types").Mesh } Mesh */
|
||||
|
||||
/**
|
||||
* Starts the UI, once the mesh has been loaded in.
|
||||
*
|
||||
* @param {{mesh: Mesh, peaks_t: number[]}} _
|
||||
*/
|
||||
function main(Mesh mesh, float[] peaks_t}) {
|
||||
Renderer render = new Renderer(mesh);
|
||||
|
||||
/* set initial parameters */
|
||||
for (let phase of ['elevation', 'biomes', 'rivers', 'render']) {
|
||||
const container = document.createElement('div');
|
||||
const header = document.createElement('h3');
|
||||
header.appendChild(document.createTextNode(phase));
|
||||
container.appendChild(header);
|
||||
document.getElementById('sliders').appendChild(container);
|
||||
for (let [name, initialValue, min, max] of initialParams[phase]) {
|
||||
const step = name === 'seed'? 1 : 0.001;
|
||||
param[phase][name] = initialValue;
|
||||
|
||||
let span = document.createElement('span');
|
||||
span.appendChild(document.createTextNode(name));
|
||||
|
||||
let slider = document.createElement('input');
|
||||
slider.setAttribute('type', name === 'seed'? 'number' : 'range');
|
||||
slider.setAttribute('min', min);
|
||||
slider.setAttribute('max', max);
|
||||
slider.setAttribute('step', step);
|
||||
slider.addEventListener('input', event => {
|
||||
param[phase][name] = slider.valueAsNumber;
|
||||
requestAnimationFrame(() => {
|
||||
if (phase == 'render') { redraw(); }
|
||||
else { generate(); }
|
||||
});
|
||||
});
|
||||
|
||||
/* improve slider behavior on iOS */
|
||||
function handleTouch(e) {
|
||||
let rect = slider.getBoundingClientRect();
|
||||
let value = (e.changedTouches[0].clientX - rect.left) / rect.width;
|
||||
value = min + value * (max - min);
|
||||
value = Math.round(value / step) * step;
|
||||
if (value < min) { value = min; }
|
||||
if (value > max) { value = max; }
|
||||
slider.value = value.toString();
|
||||
slider.dispatchEvent(new Event('input'));
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
};
|
||||
slider.addEventListener('touchmove', handleTouch);
|
||||
slider.addEventListener('touchstart', handleTouch);
|
||||
|
||||
let label = document.createElement('label');
|
||||
label.setAttribute('id', `slider-${name}`);
|
||||
label.appendChild(span);
|
||||
label.appendChild(slider);
|
||||
|
||||
container.appendChild(label);
|
||||
slider.value = initialValue;
|
||||
}
|
||||
}
|
||||
|
||||
function redraw() {
|
||||
render.updateView(param.render);
|
||||
}
|
||||
|
||||
/* Ask render module to copy WebGL into Canvas */
|
||||
function download() {
|
||||
render.screenshotCallback = () => {
|
||||
let a = document.createElement('a');
|
||||
render.screenshotCanvas.toBlob(blob => {
|
||||
// TODO: Firefox doesn't seem to allow a.click() to
|
||||
// download; is it everyone or just my setup?
|
||||
a.href = URL.createObjectURL(blob);
|
||||
a.setAttribute('download', `mapgen4-${param.elevation.seed}.png`);
|
||||
a.click();
|
||||
});
|
||||
};
|
||||
render.updateView(param.render);
|
||||
}
|
||||
|
||||
Painting.screenToWorldCoords = (coords) => {
|
||||
let out = render.screenToWorld(coords);
|
||||
return [out[0] / 1000, out[1] / 1000];
|
||||
};
|
||||
|
||||
Painting.onUpdate = () => {
|
||||
generate();
|
||||
};
|
||||
|
||||
const worker = new window.Worker("build/_worker.js");
|
||||
let working = false;
|
||||
let workRequested = false;
|
||||
let elapsedTimeHistory = [];
|
||||
|
||||
worker.addEventListener('messageerror', event => {
|
||||
console.log("WORKER ERROR", event);
|
||||
});
|
||||
|
||||
worker.addEventListener('message', event => {
|
||||
working = false;
|
||||
let {elapsed, numRiverTriangles, quad_elements_buffer, a_quad_em_buffer, a_river_xyuv_buffer} = event.data;
|
||||
elapsedTimeHistory.push(elapsed | 0);
|
||||
if (elapsedTimeHistory.length > 10) { elapsedTimeHistory.splice(0, 1); }
|
||||
const timingDiv = document.getElementById('timing');
|
||||
if (timingDiv) { timingDiv.innerText = `${elapsedTimeHistory.join(' ')} milliseconds`; }
|
||||
render.quad_elements = new Int32Array(quad_elements_buffer);
|
||||
render.a_quad_em = new Float32Array(a_quad_em_buffer);
|
||||
render.a_river_xyuv = new Float32Array(a_river_xyuv_buffer);
|
||||
render.numRiverTriangles = numRiverTriangles;
|
||||
render.updateMap();
|
||||
redraw();
|
||||
if (workRequested) {
|
||||
requestAnimationFrame(() => {
|
||||
workRequested = false;
|
||||
generate();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function updateUI() {
|
||||
let userHasPainted = Painting.userHasPainted();
|
||||
document.querySelector("#slider-seed input").disabled = userHasPainted;
|
||||
document.querySelector("#slider-island input").disabled = userHasPainted;
|
||||
document.querySelector("#button-reset").disabled = !userHasPainted;
|
||||
}
|
||||
|
||||
function generate() {
|
||||
if (!working) {
|
||||
working = true;
|
||||
Painting.setElevationParam(param.elevation);
|
||||
updateUI();
|
||||
worker.postMessage({
|
||||
param,
|
||||
constraints: {
|
||||
size: Painting.size,
|
||||
constraints: Painting.constraints,
|
||||
},
|
||||
quad_elements_buffer: render.quad_elements.buffer,
|
||||
a_quad_em_buffer: render.a_quad_em.buffer,
|
||||
a_river_xyuv_buffer: render.a_river_xyuv.buffer,
|
||||
}, [
|
||||
render.quad_elements.buffer,
|
||||
render.a_quad_em.buffer,
|
||||
render.a_river_xyuv.buffer,
|
||||
]
|
||||
);
|
||||
} else {
|
||||
workRequested = true;
|
||||
}
|
||||
}
|
||||
|
||||
worker.postMessage({mesh, peaks_t, param});
|
||||
generate();
|
||||
|
||||
const downloadButton = document.getElementById('button-download');
|
||||
if (downloadButton) downloadButton.addEventListener('click', download);
|
||||
}
|
||||
|
||||
makeMesh().then(main);
|
@ -1,172 +0,0 @@
|
||||
package org.atriasoft.arkon;
|
||||
/*
|
||||
* From https://www.redblobgames.com/maps/mapgen4/
|
||||
* Copyright 2018 Red Blob Games <redblobgames@gmail.com>
|
||||
* License: Apache v2.0 <http://www.apache.org/licenses/LICENSE-2.0.html>
|
||||
*
|
||||
* Point selection (blue noise or jittered grid), mountain peak
|
||||
* selection, and mesh building.
|
||||
*
|
||||
* Points are regions (r), and either come from a jittered hexagonal
|
||||
* grid or a precomputed blue noise set. Mountain peaks are triangles
|
||||
* (t), and either come from a random subset of triangles or from a
|
||||
* non-random subset of the blue noise points. However, since the blue
|
||||
* noise points are regions and mountain peaks are triangles, I
|
||||
* arbitrarily pick one triangle from each region.
|
||||
*
|
||||
* The precomputed points are read from the network, so the module
|
||||
* uses async functions that build the mesh only after the points are
|
||||
* read in.
|
||||
*/
|
||||
|
||||
//import param from './config';
|
||||
import Config;
|
||||
//import MeshBuilder from '@redblobgames/dual-mesh/create';
|
||||
import Create.MeshBuilder;
|
||||
import {makeRandFloat} from '@redblobgames/prng';
|
||||
|
||||
|
||||
/**
|
||||
* @typedef { import("./types").Mesh } Mesh
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Apply random circular jitter to a set of points.
|
||||
*
|
||||
* @param {number[][]} points
|
||||
* @param {number} dr
|
||||
* @param {function(): number} randFloat
|
||||
*/
|
||||
function applyJitter(points, dr, randFloat) {
|
||||
let newPoints = [];
|
||||
for (let p of points) {
|
||||
let r = dr * Math.sqrt(Math.abs(randFloat()));
|
||||
let a = Math.PI * randFloat();
|
||||
let dx = r * Math.cos(a);
|
||||
let dy = r * Math.sin(a);
|
||||
newPoints.push([p[0] + dx, p[1] + dy]);
|
||||
}
|
||||
|
||||
return newPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a hexagonal grid with a given spacing. This is used when NOT
|
||||
* reading points from a file.
|
||||
*
|
||||
* @param {number} spacing - horizontal spacing between adjacent hexagons
|
||||
* @returns {[number, number][]} - list of [x, y] points
|
||||
*/
|
||||
function hexagonGrid(spacing) {
|
||||
let points = /** @type{[number, number][]} */([]);
|
||||
let offset = 0;
|
||||
for (let y = spacing/2; y < 1000-spacing/2; y += spacing * 3/4) {
|
||||
offset = (offset === 0)? spacing/2 : 0;
|
||||
for (let x = offset + spacing/2; x < 1000-spacing/2; x += spacing) {
|
||||
points.push([x, y]);
|
||||
}
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose a random set of regions for mountain peaks. This is used
|
||||
* when NOT reading points from a file.
|
||||
*
|
||||
* @param {number} numPoints
|
||||
* @param {number} spacing - param.spacing parameter, used to calculate density
|
||||
* @param {function(): number} randFloat - random number generator (0-1)
|
||||
* @returns {number[]} - array of point indices
|
||||
*/
|
||||
function chooseMountainPeaks(numPoints, spacing, randFloat) {
|
||||
const fractionOfPeaks = spacing*spacing / param.mountainDensity;
|
||||
let peaks_r = [];
|
||||
for (let r = 0; r < numPoints; r++) {
|
||||
if (randFloat() < fractionOfPeaks) {
|
||||
peaks_r.push(r);
|
||||
}
|
||||
}
|
||||
return peaks_r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read mesh and mountain peak points from a file saved by generate-points.js
|
||||
*
|
||||
* The points are [x,y]; the peaks in the index are an index into the
|
||||
* points[] array, *not* region ids. The mesh creation process can
|
||||
* insert new regions before and after this array, so these indices
|
||||
* have to be adjusted later.
|
||||
*
|
||||
* @param {ArrayBuffer} buffer - data read from the mesh file
|
||||
* @returns {{points: number[][], peaks_index: number[]}}
|
||||
*/
|
||||
function extractPoints(buffer) {
|
||||
/* See file format in generate-points.js */
|
||||
const pointData = new Uint16Array(buffer);
|
||||
const numMountainPeaks = pointData[0];
|
||||
let peaks_index = Array.from(pointData.slice(1, 1 + numMountainPeaks));
|
||||
const numRegions = (pointData.length - numMountainPeaks - 1) / 2;
|
||||
let points = [];
|
||||
for (let i = 0; i < numRegions; i++) {
|
||||
let j = 1 + numMountainPeaks + 2*i;
|
||||
points.push([pointData[j], pointData[j+1]]);
|
||||
}
|
||||
return {points, peaks_index};
|
||||
}
|
||||
|
||||
/**
|
||||
* Either read mesh and mountain peak points, or generate locally.
|
||||
*
|
||||
* TODO: This hard-codes the spacing of 5; it should be a parameter
|
||||
*/
|
||||
async function choosePoints() {
|
||||
let points = undefined, peaks_index = undefined;
|
||||
const jitter = 0.5;
|
||||
if (param.spacing === 5) {
|
||||
let buffer = await fetch("build/points-5.data").then(response => response.arrayBuffer());
|
||||
let extraction = extractPoints(buffer);
|
||||
points = applyJitter(extraction.points, param.spacing * jitter * 0.5, makeRandFloat(param.mesh.seed));
|
||||
peaks_index = extraction.peaks_index;
|
||||
} else {
|
||||
points = applyJitter(hexagonGrid(1.5 * param.spacing), param.spacing * jitter, makeRandFloat(param.mesh.seed));
|
||||
peaks_index = chooseMountainPeaks(points.length, param.spacing, makeRandFloat(param.mesh.seed));
|
||||
};
|
||||
return {points, peaks_index};
|
||||
}
|
||||
|
||||
|
||||
export async function makeMesh() {
|
||||
let {points, peaks_index} = await choosePoints();
|
||||
|
||||
let builder = new MeshBuilder({boundarySpacing: param.spacing * 1.5})
|
||||
.addPoints(points);
|
||||
let mesh = /** @type {Mesh} */(builder.create());
|
||||
console.log(`triangles = ${mesh.numTriangles} regions = ${mesh.numRegions}`);
|
||||
|
||||
mesh.s_length = new Float32Array(mesh.numSides);
|
||||
for (let s = 0; s < mesh.numSides; s++) {
|
||||
let r1 = mesh.s_begin_r(s),
|
||||
r2 = mesh.s_end_r(s);
|
||||
let dx = mesh.r_x(r1) - mesh.r_x(r2),
|
||||
dy = mesh.r_y(r1) - mesh.r_y(r2);
|
||||
mesh.s_length[s] = Math.sqrt(dx*dx + dy*dy);
|
||||
}
|
||||
|
||||
/* The input points get assigned to different positions in the
|
||||
* output mesh. The peaks_index has indices into the original
|
||||
* array. This test makes sure that the logic for mapping input
|
||||
* indices to output indices hasn't changed. */
|
||||
if (points[200][0] !== mesh.r_x(200 + mesh.numBoundaryRegions)
|
||||
|| points[200][1] !== mesh.r_y(200 + mesh.numBoundaryRegions)) {
|
||||
throw "Mapping from input points to output points has changed";
|
||||
}
|
||||
let peaks_r = peaks_index.map(i => i + mesh.numBoundaryRegions);
|
||||
|
||||
let peaks_t = [];
|
||||
for (let r of peaks_r) {
|
||||
peaks_t.push(mesh.s_inner_t(mesh._r_in_s[r]));
|
||||
}
|
||||
|
||||
return {mesh, peaks_t};
|
||||
}
|
@ -1,223 +0,0 @@
|
||||
/*
|
||||
* From https://www.redblobgames.com/maps/mapgen4/
|
||||
* Copyright 2018 Red Blob Games <redblobgames@gmail.com>
|
||||
* License: Apache v2.0 <http://www.apache.org/licenses/LICENSE-2.0.html>
|
||||
*
|
||||
* This module allows the user to paint constraints for the map generator
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
/* global Draggable */
|
||||
|
||||
/*
|
||||
* The painting interface uses a square array of elevations. As you
|
||||
* drag the mouse it will paint filled circles into the elevation map,
|
||||
* then send the elevation map to the generator to produce the output.
|
||||
*/
|
||||
|
||||
import SimplexNoise from 'simplex-noise';
|
||||
import {makeRandFloat} from '@redblobgames/prng';
|
||||
|
||||
const CANVAS_SIZE = 128;
|
||||
|
||||
const currentStroke = {
|
||||
/* elevation before the current paint stroke began */
|
||||
previousElevation: new Float32Array(CANVAS_SIZE * CANVAS_SIZE),
|
||||
/* how long, in milliseconds, was spent painting */
|
||||
time: new Float32Array(CANVAS_SIZE * CANVAS_SIZE),
|
||||
/* maximum strength applied */
|
||||
strength: new Float32Array(CANVAS_SIZE * CANVAS_SIZE),
|
||||
};
|
||||
|
||||
|
||||
/* The elevation is -1.0 to 0.0 → water, 0.0 to +1.0 → land */
|
||||
class Generator {
|
||||
constructor () {
|
||||
this.userHasPainted = false;
|
||||
this.elevation = new Float32Array(CANVAS_SIZE * CANVAS_SIZE);
|
||||
}
|
||||
|
||||
setElevationParam(elevationParam) {
|
||||
if ( elevationParam.seed !== this.seed
|
||||
|| elevationParam.island !== this.island) {
|
||||
this.seed = elevationParam.seed;
|
||||
this.island = elevationParam.island;
|
||||
this.generate();
|
||||
}
|
||||
}
|
||||
|
||||
/** Use a noise function to determine the shape */
|
||||
generate() {
|
||||
const {elevation, island} = this;
|
||||
const noise = new SimplexNoise(makeRandFloat(this.seed));
|
||||
const persistence = 1/2;
|
||||
const amplitudes = Array.from({length: 5}, (_, octave) => Math.pow(persistence, octave));
|
||||
|
||||
function fbm_noise(nx, ny) {
|
||||
let sum = 0, sumOfAmplitudes = 0;
|
||||
for (let octave = 0; octave < amplitudes.length; octave++) {
|
||||
let frequency = 1 << octave;
|
||||
sum += amplitudes[octave] * noise.noise2D(nx * frequency, ny * frequency);
|
||||
sumOfAmplitudes += amplitudes[octave];
|
||||
}
|
||||
return sum / sumOfAmplitudes;
|
||||
}
|
||||
|
||||
for (let y = 0; y < CANVAS_SIZE; y++) {
|
||||
for (let x = 0; x < CANVAS_SIZE; x++) {
|
||||
let p = y * CANVAS_SIZE + x;
|
||||
let nx = 2 * x/CANVAS_SIZE - 1,
|
||||
ny = 2 * y/CANVAS_SIZE - 1;
|
||||
let distance = Math.max(Math.abs(nx), Math.abs(ny));
|
||||
let e = 0.5 * (fbm_noise(nx, ny) + island * (0.75 - 2 * distance * distance));
|
||||
if (e < -1.0) { e = -1.0; }
|
||||
if (e > +1.0) { e = +1.0; }
|
||||
elevation[p] = e;
|
||||
if (e > 0.0) {
|
||||
let m = (0.5 * noise.noise2D(nx + 30, ny + 50)
|
||||
+ 0.5 * noise.noise2D(2*nx + 33, 2*ny + 55));
|
||||
// TODO: make some of these into parameters
|
||||
let mountain = Math.min(1.0, e * 5.0) * (1 - Math.abs(m) / 0.5);
|
||||
if (mountain > 0.0) {
|
||||
elevation[p] = Math.max(e, Math.min(e * 3, mountain));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.userHasPainted = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paint a circular region
|
||||
*
|
||||
* @param {{elevation: number}} tool
|
||||
* @param {number} x0 - should be 0 to 1
|
||||
* @param {number} y0 - should be 0 to 1
|
||||
* @param {{innerRadius: number, outerRadius: number, rate: number}} size
|
||||
* @param {number} deltaTimeInMs
|
||||
*/
|
||||
paintAt(tool, x0, y0, size, deltaTimeInMs) {
|
||||
let {elevation} = this;
|
||||
/* This has two effects: first time you click the mouse it has a
|
||||
* strong effect, and it also limits the amount in case you
|
||||
* pause */
|
||||
deltaTimeInMs = Math.min(100, deltaTimeInMs);
|
||||
|
||||
let newElevation = tool.elevation;
|
||||
let {innerRadius, outerRadius, rate} = size;
|
||||
let xc = (x0 * CANVAS_SIZE) | 0, yc = (y0 * CANVAS_SIZE) | 0;
|
||||
let top = Math.max(0, yc - outerRadius),
|
||||
bottom = Math.min(CANVAS_SIZE-1, yc + outerRadius);
|
||||
for (let y = top; y <= bottom; y++) {
|
||||
let s = Math.sqrt(outerRadius * outerRadius - (y - yc) * (y - yc)) | 0;
|
||||
let left = Math.max(0, xc - s),
|
||||
right = Math.min(CANVAS_SIZE-1, xc + s);
|
||||
for (let x = left; x <= right; x++) {
|
||||
let p = y * CANVAS_SIZE + x;
|
||||
let distance = Math.sqrt((x - xc) * (x - xc) + (y - yc) * (y - yc));
|
||||
let strength = 1.0 - Math.min(1, Math.max(0, (distance - innerRadius) / (outerRadius - innerRadius)));
|
||||
let factor = rate/1000 * deltaTimeInMs;
|
||||
currentStroke.time[p] += strength * factor;
|
||||
if (strength > currentStroke.strength[p]) {
|
||||
currentStroke.strength[p] = (1 - factor) * currentStroke.strength[p] + factor * strength;
|
||||
}
|
||||
let mix = currentStroke.strength[p] * Math.min(1, currentStroke.time[p]);
|
||||
elevation[p] = (1 - mix) * currentStroke.previousElevation[p] + mix * newElevation;
|
||||
}
|
||||
}
|
||||
|
||||
this.userHasPainted = true;
|
||||
}
|
||||
}
|
||||
let heightMap = new Generator();
|
||||
|
||||
let exported = {
|
||||
size: CANVAS_SIZE,
|
||||
onUpdate: () => {},
|
||||
screenToWorldCoords: coords => coords,
|
||||
constraints: heightMap.elevation,
|
||||
setElevationParam: elevationParam => heightMap.setElevationParam(elevationParam),
|
||||
userHasPainted: () => heightMap.userHasPainted,
|
||||
};
|
||||
|
||||
document.getElementById('button-reset').addEventListener('click', () => {
|
||||
heightMap.generate();
|
||||
exported.onUpdate();
|
||||
});
|
||||
|
||||
|
||||
const SIZES = {
|
||||
// rate is effect per second
|
||||
small: {key: '1', rate: 8, innerRadius: 2, outerRadius: 6},
|
||||
medium: {key: '2', rate: 5, innerRadius: 5, outerRadius: 10},
|
||||
large: {key: '3', rate: 3, innerRadius: 10, outerRadius: 16},
|
||||
};
|
||||
|
||||
const TOOLS = {
|
||||
ocean: {elevation: -0.25},
|
||||
shallow: {elevation: -0.05},
|
||||
valley: {elevation: +0.05},
|
||||
mountain: {elevation: +1.0},
|
||||
};
|
||||
|
||||
let currentTool = 'mountain';
|
||||
let currentSize = 'small';
|
||||
|
||||
function displayCurrentTool() {
|
||||
const className = 'current-control';
|
||||
for (let c of document.querySelectorAll("."+className)) {
|
||||
c.classList.remove(className);
|
||||
}
|
||||
document.getElementById(currentTool).classList.add(className);
|
||||
document.getElementById(currentSize).classList.add(className);
|
||||
}
|
||||
|
||||
/** @type {[string, string, function][]} */
|
||||
const controls = [
|
||||
['1', "small", () => { currentSize = 'small'; }],
|
||||
['2', "medium", () => { currentSize = 'medium'; }],
|
||||
['3', "large", () => { currentSize = 'large'; }],
|
||||
['q', "ocean", () => { currentTool = 'ocean'; }],
|
||||
['w', "shallow", () => { currentTool = 'shallow'; }],
|
||||
['e', "valley", () => { currentTool = 'valley'; }],
|
||||
['r', "mountain", () => { currentTool = 'mountain'; }],
|
||||
];
|
||||
|
||||
window.addEventListener('keydown', e => {
|
||||
for (let control of controls) {
|
||||
if (e.key === control[0]) { control[2](); displayCurrentTool(); }
|
||||
}
|
||||
});
|
||||
|
||||
for (let control of controls) {
|
||||
document.getElementById(control[1]).addEventListener('click', () => { control[2](); displayCurrentTool(); } );
|
||||
}
|
||||
displayCurrentTool();
|
||||
|
||||
|
||||
const output = document.getElementById('mapgen4');
|
||||
new Draggable({
|
||||
// TODO: replace with pointer events, now that they're widely supported
|
||||
el: output,
|
||||
start(event) {
|
||||
this.timestamp = Date.now();
|
||||
currentStroke.time.fill(0);
|
||||
currentStroke.strength.fill(0);
|
||||
currentStroke.previousElevation.set(heightMap.elevation);
|
||||
this.drag(event);
|
||||
},
|
||||
drag(event) {
|
||||
const nowMs = Date.now();
|
||||
let coords = [event.x / output.clientWidth,
|
||||
event.y / output.clientHeight];
|
||||
coords = exported.screenToWorldCoords(coords);
|
||||
heightMap.paintAt(TOOLS[currentTool], coords[0], coords[1], SIZES[currentSize], nowMs - this.timestamp);
|
||||
this.timestamp = nowMs;
|
||||
exported.onUpdate();
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
||||
export default exported;
|
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* From https://www.redblobgames.com/maps/mapgen4/
|
||||
* Copyright 2018 Red Blob Games <redblobgames@gmail.com>
|
||||
* License: Apache v2.0 <http://www.apache.org/licenses/LICENSE-2.0.html>
|
||||
*
|
||||
* This module runs the worker thread that calculates the map data.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
import DualMesh from '@redblobgames/dual-mesh';
|
||||
import Map from './map';
|
||||
import Geometry from './geometry';
|
||||
|
||||
/**
|
||||
* @typedef { import("./types").Mesh } Mesh
|
||||
*/
|
||||
|
||||
// This handler is for the initial message
|
||||
let handler = event => {
|
||||
const param = event.data.param;
|
||||
|
||||
// NOTE: web worker messages only include the data; to
|
||||
// reconstruct the full object I call the constructor again
|
||||
// and then copy the data over
|
||||
const mesh = /** @type{Mesh} */(new DualMesh(event.data.mesh));
|
||||
Object.assign(mesh, event.data.mesh);
|
||||
|
||||
const map = new Map(mesh, event.data.peaks_t, param);
|
||||
|
||||
// TODO: placeholder
|
||||
const run = {elevation: true, biomes: true, rivers: true};
|
||||
|
||||
// This handler is for all subsequent messages
|
||||
handler = event => {
|
||||
let {param, constraints, quad_elements_buffer, a_quad_em_buffer, a_river_xyuv_buffer} = event.data;
|
||||
|
||||
let numRiverTriangles = 0;
|
||||
let start_time = performance.now();
|
||||
|
||||
if (run.elevation) { map.assignElevation(param.elevation, constraints); }
|
||||
if (run.biomes) { map.assignRainfall(param.biomes); }
|
||||
if (run.rivers) { map.assignRivers(param.rivers); }
|
||||
if (run.elevation || run.rivers) {
|
||||
Geometry.setMapGeometry(map, new Int32Array(quad_elements_buffer), new Float32Array(a_quad_em_buffer));
|
||||
}
|
||||
if (run.rivers) { numRiverTriangles = Geometry.setRiverTextures(map, param.spacing, param.rivers, new Float32Array(a_river_xyuv_buffer)); }
|
||||
let elapsed = performance.now() - start_time;
|
||||
|
||||
self.postMessage(
|
||||
{elapsed,
|
||||
numRiverTriangles,
|
||||
quad_elements_buffer,
|
||||
a_quad_em_buffer,
|
||||
a_river_xyuv_buffer,
|
||||
},
|
||||
[
|
||||
quad_elements_buffer,
|
||||
a_quad_em_buffer,
|
||||
a_river_xyuv_buffer,
|
||||
]
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
onmessage = event => handler(event);
|
||||
|
@ -1,68 +0,0 @@
|
||||
package org.atriasoft.eagle.internal;
|
||||
|
||||
import org.atriasoft.reggol.LogLevel;
|
||||
import org.atriasoft.reggol.Logger;
|
||||
|
||||
public class Log {
|
||||
private static final String LIB_NAME = "eagle";
|
||||
private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME);
|
||||
private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(LIB_NAME, LogLevel.CRITICAL);
|
||||
private static final boolean PRINT_ERROR = Logger.getNeedPrint(LIB_NAME, LogLevel.ERROR);
|
||||
private static final boolean PRINT_WARNING = Logger.getNeedPrint(LIB_NAME, LogLevel.WARNING);
|
||||
private static final boolean PRINT_INFO = Logger.getNeedPrint(LIB_NAME, LogLevel.INFO);
|
||||
private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG);
|
||||
private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(LIB_NAME, LogLevel.VERBOSE);
|
||||
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
|
||||
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
|
||||
|
||||
public static void critical(final String data) {
|
||||
if (PRINT_CRITICAL) {
|
||||
Logger.critical(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void debug(final String data) {
|
||||
if (PRINT_DEBUG) {
|
||||
Logger.debug(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void error(final String data) {
|
||||
if (PRINT_ERROR) {
|
||||
Logger.error(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void info(final String data) {
|
||||
if (PRINT_INFO) {
|
||||
Logger.info(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void print(final String data) {
|
||||
if (PRINT_PRINT) {
|
||||
Logger.print(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void todo(final String data) {
|
||||
if (PRINT_TODO) {
|
||||
Logger.todo(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verbose(final String data) {
|
||||
if (PRINT_VERBOSE) {
|
||||
Logger.verbose(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void warning(final String data) {
|
||||
if (PRINT_WARNING) {
|
||||
Logger.warning(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
private Log() {}
|
||||
|
||||
}
|
@ -3,7 +3,6 @@ package org.atriasoft.ege;
|
||||
import org.atriasoft.ege.camera.Camera;
|
||||
import org.atriasoft.ege.components.ComponentPlayer;
|
||||
import org.atriasoft.ege.components.ComponentPositionPlayer;
|
||||
import org.atriasoft.ege.internal.Log;
|
||||
import org.atriasoft.etk.math.Transform3D;
|
||||
import org.atriasoft.etk.math.Vector2f;
|
||||
import org.atriasoft.etk.math.Vector3f;
|
||||
@ -13,8 +12,11 @@ import org.atriasoft.ewol.event.EventTime;
|
||||
import org.atriasoft.gale.Gale;
|
||||
import org.atriasoft.gale.key.KeyKeyboard;
|
||||
import org.atriasoft.gale.key.KeyStatus;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ControlCameraPlayer implements ControlInterface {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(ControlCameraPlayer.class);
|
||||
private final Camera camera;
|
||||
private float distanceFromCenter = 2.5f;
|
||||
private boolean fpsMode = false;
|
||||
@ -26,7 +28,7 @@ public class ControlCameraPlayer implements ControlInterface {
|
||||
private boolean moveLeft = false;
|
||||
private boolean moveRight = false;
|
||||
private boolean walk = false;
|
||||
|
||||
|
||||
public ControlCameraPlayer(final Camera camera, final Entity playerEntity) {
|
||||
this.camera = camera;
|
||||
this.playerEntity = playerEntity;
|
||||
@ -35,7 +37,7 @@ public class ControlCameraPlayer implements ControlInterface {
|
||||
}
|
||||
this.player = (ComponentPlayer) this.playerEntity.getComponent("player");
|
||||
}
|
||||
|
||||
|
||||
private boolean getState(final KeyStatus state, final boolean previousState) {
|
||||
if (state == KeyStatus.down) {
|
||||
return true;
|
||||
@ -45,19 +47,23 @@ public class ControlCameraPlayer implements ControlInterface {
|
||||
}
|
||||
return previousState;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onEventEntry(final EventEntry event) {
|
||||
if (event.type() == KeyKeyboard.UP || (event.type() == KeyKeyboard.CHARACTER && (event.getChar() == 'z' || event.getChar() == 'Z'))) {
|
||||
if (event.type() == KeyKeyboard.UP
|
||||
|| (event.type() == KeyKeyboard.CHARACTER && (event.getChar() == 'z' || event.getChar() == 'Z'))) {
|
||||
this.moveUp = getState(event.status(), this.moveUp);
|
||||
}
|
||||
if (event.type() == KeyKeyboard.LEFT || (event.type() == KeyKeyboard.CHARACTER && (event.getChar() == 'q' || event.getChar() == 'Q'))) {
|
||||
if (event.type() == KeyKeyboard.LEFT
|
||||
|| (event.type() == KeyKeyboard.CHARACTER && (event.getChar() == 'q' || event.getChar() == 'Q'))) {
|
||||
this.moveLeft = getState(event.status(), this.moveLeft);
|
||||
}
|
||||
if (event.type() == KeyKeyboard.RIGHT || (event.type() == KeyKeyboard.CHARACTER && (event.getChar() == 'd' || event.getChar() == 'D'))) {
|
||||
if (event.type() == KeyKeyboard.RIGHT
|
||||
|| (event.type() == KeyKeyboard.CHARACTER && (event.getChar() == 'd' || event.getChar() == 'D'))) {
|
||||
this.moveRight = getState(event.status(), this.moveRight);
|
||||
}
|
||||
if (event.type() == KeyKeyboard.DOWN || (event.type() == KeyKeyboard.CHARACTER && (event.getChar() == 's' || event.getChar() == 'S'))) {
|
||||
if (event.type() == KeyKeyboard.DOWN
|
||||
|| (event.type() == KeyKeyboard.CHARACTER && (event.getChar() == 's' || event.getChar() == 'S'))) {
|
||||
this.moveDown = getState(event.status(), this.moveDown);
|
||||
}
|
||||
if (event.type() == KeyKeyboard.SHIFT_LEFT || event.type() == KeyKeyboard.SHIFT_RIGHT) {
|
||||
@ -76,7 +82,7 @@ public class ControlCameraPlayer implements ControlInterface {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onEventInput(final EventInput event, final Vector3f relativePosition) {
|
||||
// LOGGER.info("{}", event);
|
||||
@ -111,7 +117,8 @@ public class ControlCameraPlayer implements ControlInterface {
|
||||
final Vector2f delta = event.pos();
|
||||
//angleZ += delta.x;
|
||||
//this.camera.setYaw(this.camera.getYaw() + (float)Math.toRadians(delta.x));
|
||||
this.camera.setPitch(this.camera.getPitch() + (float) Math.toRadians(delta.y() * this.player.getTurnSpeed()));
|
||||
this.camera
|
||||
.setPitch(this.camera.getPitch() + (float) Math.toRadians(delta.y() * this.player.getTurnSpeed()));
|
||||
if (this.camera.getPitch() > 0) {
|
||||
this.camera.setPitch(0);
|
||||
}
|
||||
@ -132,7 +139,7 @@ public class ControlCameraPlayer implements ControlInterface {
|
||||
if (this.playerPosition != null) {
|
||||
final float playerZAngle = this.playerPosition.getAngles().z();
|
||||
float tmpAngle = playerZAngle + (float) Math.toRadians(delta.x() * this.player.getTurnSpeed());
|
||||
|
||||
|
||||
if (tmpAngle > Math.PI) {
|
||||
tmpAngle -= (float) Math.PI * 2.0f;
|
||||
}
|
||||
@ -146,7 +153,7 @@ public class ControlCameraPlayer implements ControlInterface {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void periodicCall(final EventTime event) {
|
||||
float speed = 0;
|
||||
@ -199,7 +206,9 @@ public class ControlCameraPlayer implements ControlInterface {
|
||||
final float offsetX = (float) (tmp * Math.sin(-theta));
|
||||
final float offsetY = (float) (tmp * Math.cos(-theta));
|
||||
//LOGGER.info(" res=({},{})", offsetX, offsetY);
|
||||
this.camera.setPosition(new Vector3f(playerTransform.getPosition().x() + offsetX, playerTransform.getPosition().y() + offsetY, playerTransform.getPosition().z() + 1.6f + verticalDistance));
|
||||
this.camera.setPosition(
|
||||
new Vector3f(playerTransform.getPosition().x() + offsetX, playerTransform.getPosition().y() + offsetY,
|
||||
playerTransform.getPosition().z() + 1.6f + verticalDistance));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package org.atriasoft.ege;
|
||||
import org.atriasoft.ege.camera.Camera;
|
||||
import org.atriasoft.ege.components.ComponentPlayer;
|
||||
import org.atriasoft.ege.components.ComponentPositionPlayer;
|
||||
import org.atriasoft.ege.internal.Log;
|
||||
import org.atriasoft.etk.math.Vector2f;
|
||||
import org.atriasoft.etk.math.Vector3f;
|
||||
import org.atriasoft.ewol.event.EventEntry;
|
||||
@ -12,24 +11,27 @@ import org.atriasoft.ewol.event.EventTime;
|
||||
import org.atriasoft.gale.Gale;
|
||||
import org.atriasoft.gale.key.KeyKeyboard;
|
||||
import org.atriasoft.gale.key.KeyStatus;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ControlCameraPlayerFPS implements ControlInterface {
|
||||
private Camera camera;
|
||||
private Entity playerEntity;
|
||||
private ComponentPositionPlayer playerPosition;
|
||||
private ComponentPlayer player;
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(ControlCameraPlayerFPS.class);
|
||||
private final Camera camera;
|
||||
private final Entity playerEntity;
|
||||
private final ComponentPositionPlayer playerPosition;
|
||||
private final ComponentPlayer player;
|
||||
private boolean moveUp = false;
|
||||
private boolean moveDown = false;
|
||||
private boolean moveLeft = false;
|
||||
private boolean moveRight = false;
|
||||
|
||||
|
||||
public ControlCameraPlayerFPS(final Camera camera, final Entity playerEntity) {
|
||||
this.camera = camera;
|
||||
this.playerEntity = playerEntity;
|
||||
this.playerPosition = (ComponentPositionPlayer) this.playerEntity.getComponent("position");
|
||||
this.player = (ComponentPlayer) this.playerEntity.getComponent("player");
|
||||
}
|
||||
|
||||
|
||||
private boolean getState(final KeyStatus state, final boolean previousState) {
|
||||
if (state == KeyStatus.down) {
|
||||
return true;
|
||||
@ -39,24 +41,28 @@ public class ControlCameraPlayerFPS implements ControlInterface {
|
||||
}
|
||||
return previousState;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onEventEntry(final EventEntry event) {
|
||||
if (event.type() == KeyKeyboard.UP || (event.type() == KeyKeyboard.CHARACTER && (event.getChar() == 'z' || event.getChar() == 'Z'))) {
|
||||
if (event.type() == KeyKeyboard.UP
|
||||
|| (event.type() == KeyKeyboard.CHARACTER && (event.getChar() == 'z' || event.getChar() == 'Z'))) {
|
||||
this.moveUp = getState(event.status(), this.moveUp);
|
||||
}
|
||||
if (event.type() == KeyKeyboard.LEFT || (event.type() == KeyKeyboard.CHARACTER && (event.getChar() == 'q' || event.getChar() == 'Q'))) {
|
||||
if (event.type() == KeyKeyboard.LEFT
|
||||
|| (event.type() == KeyKeyboard.CHARACTER && (event.getChar() == 'q' || event.getChar() == 'Q'))) {
|
||||
this.moveLeft = getState(event.status(), this.moveLeft);
|
||||
}
|
||||
if (event.type() == KeyKeyboard.RIGHT || (event.type() == KeyKeyboard.CHARACTER && (event.getChar() == 'd' || event.getChar() == 'D'))) {
|
||||
if (event.type() == KeyKeyboard.RIGHT
|
||||
|| (event.type() == KeyKeyboard.CHARACTER && (event.getChar() == 'd' || event.getChar() == 'D'))) {
|
||||
this.moveRight = getState(event.status(), this.moveRight);
|
||||
}
|
||||
if (event.type() == KeyKeyboard.DOWN || (event.type() == KeyKeyboard.CHARACTER && (event.getChar() == 's' || event.getChar() == 'S'))) {
|
||||
if (event.type() == KeyKeyboard.DOWN
|
||||
|| (event.type() == KeyKeyboard.CHARACTER && (event.getChar() == 's' || event.getChar() == 'S'))) {
|
||||
this.moveDown = getState(event.status(), this.moveDown);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onEventInput(final EventInput event, final Vector3f relativePosition) {
|
||||
// LOGGER.info("{}", event);
|
||||
@ -65,10 +71,11 @@ public class ControlCameraPlayerFPS implements ControlInterface {
|
||||
return false;
|
||||
}
|
||||
if (event.status() == KeyStatus.move) {
|
||||
Vector2f delta = event.pos();
|
||||
final Vector2f delta = event.pos();
|
||||
//angleZ += delta.x;
|
||||
//this.camera.setYaw(this.camera.getYaw() + (float)Math.toRadians(delta.x));
|
||||
this.camera.setPitch(this.camera.getPitch() + (float) Math.toRadians(delta.y() * this.player.getTurnSpeed()));
|
||||
this.camera
|
||||
.setPitch(this.camera.getPitch() + (float) Math.toRadians(delta.y() * this.player.getTurnSpeed()));
|
||||
if (this.camera.getPitch() > 0) {
|
||||
this.camera.setPitch(0);
|
||||
}
|
||||
@ -87,7 +94,7 @@ public class ControlCameraPlayerFPS implements ControlInterface {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void periodicCall(final EventTime event) {
|
||||
float speed = 0;
|
||||
@ -99,8 +106,8 @@ public class ControlCameraPlayerFPS implements ControlInterface {
|
||||
}
|
||||
}
|
||||
float distance = speed * event.getTimeDeltaCallSecond();
|
||||
float dx = (float) (distance * Math.sin(this.playerPosition.getAngles().z()));
|
||||
float dy = (float) (distance * Math.cos(this.playerPosition.getAngles().z()));
|
||||
final float dx = (float) (distance * Math.sin(this.playerPosition.getAngles().z()));
|
||||
final float dy = (float) (distance * Math.cos(this.playerPosition.getAngles().z()));
|
||||
speed = 0;
|
||||
if (this.moveRight != this.moveLeft) {
|
||||
if (this.moveRight) {
|
||||
@ -110,11 +117,14 @@ public class ControlCameraPlayerFPS implements ControlInterface {
|
||||
}
|
||||
}
|
||||
distance = speed * event.getTimeDeltaCallSecond();
|
||||
float dxStraf = (float) (distance * Math.sin((float) Math.PI * 0.5f + this.playerPosition.getAngles().z()));
|
||||
float dyStraf = (float) (distance * Math.cos((float) Math.PI * 0.5f + this.playerPosition.getAngles().z()));
|
||||
final float dxStraf = (float) (distance
|
||||
* Math.sin((float) Math.PI * 0.5f + this.playerPosition.getAngles().z()));
|
||||
final float dyStraf = (float) (distance
|
||||
* Math.cos((float) Math.PI * 0.5f + this.playerPosition.getAngles().z()));
|
||||
//LOGGER.error("update position ... {} {}", dx, dy);
|
||||
this.playerPosition.setTransform(this.playerPosition.getTransform().withPosition(this.playerPosition.getTransform().getPosition().add(dx + dxStraf, dy + dyStraf, 0)));
|
||||
this.playerPosition.setTransform(this.playerPosition.getTransform()
|
||||
.withPosition(this.playerPosition.getTransform().getPosition().add(dx + dxStraf, dy + dyStraf, 0)));
|
||||
this.camera.setPosition(this.playerPosition.getTransform().getPosition());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.atriasoft.ege;
|
||||
|
||||
import org.atriasoft.ege.camera.Camera;
|
||||
import org.atriasoft.ege.internal.Log;
|
||||
import org.atriasoft.etk.math.Vector2f;
|
||||
import org.atriasoft.etk.math.Vector3f;
|
||||
import org.atriasoft.ewol.event.EventEntry;
|
||||
@ -9,8 +8,11 @@ import org.atriasoft.ewol.event.EventInput;
|
||||
import org.atriasoft.ewol.event.EventTime;
|
||||
import org.atriasoft.gale.key.KeyKeyboard;
|
||||
import org.atriasoft.gale.key.KeyStatus;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ControlCameraSimple implements ControlInterface {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(ControlCameraSimple.class);
|
||||
private final Camera camera;
|
||||
private Vector2f lastMousePosition = null;
|
||||
private boolean moveUp = false;
|
||||
@ -18,11 +20,11 @@ public class ControlCameraSimple implements ControlInterface {
|
||||
private boolean moveRight = false;
|
||||
private boolean moveDown = false;
|
||||
private boolean ctrlIsSet = false;
|
||||
|
||||
|
||||
public ControlCameraSimple(final Camera camera) {
|
||||
this.camera = camera;
|
||||
}
|
||||
|
||||
|
||||
private boolean getState(final KeyStatus state, final boolean previousState) {
|
||||
if (state == KeyStatus.down) {
|
||||
return true;
|
||||
@ -32,7 +34,7 @@ public class ControlCameraSimple implements ControlInterface {
|
||||
}
|
||||
return previousState;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onEventEntry(final EventEntry event) {
|
||||
if (event.type() == KeyKeyboard.UP) {
|
||||
@ -50,18 +52,18 @@ public class ControlCameraSimple implements ControlInterface {
|
||||
this.ctrlIsSet = event.specialKey().getCtrl();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onEventInput(final EventInput event, final Vector3f relativePosition) {
|
||||
// TODO Auto-generated method stub
|
||||
if (event.inputId() == 4) {
|
||||
Vector3f delta = this.camera.getConvertionMatrix().transpose().multiply(new Vector3f(0,0,-1));
|
||||
final Vector3f delta = this.camera.getConvertionMatrix().transpose().multiply(new Vector3f(0, 0, -1));
|
||||
if (event.status() == KeyStatus.down) {
|
||||
this.camera.setPosition(this.camera.getPosition().add(delta.multiply(1.0f)));
|
||||
}
|
||||
}
|
||||
if (event.inputId() == 5) {
|
||||
Vector3f delta = this.camera.getConvertionMatrix().transpose().multiply(new Vector3f(0,0,-1));
|
||||
final Vector3f delta = this.camera.getConvertionMatrix().transpose().multiply(new Vector3f(0, 0, -1));
|
||||
if (event.status() == KeyStatus.down) {
|
||||
this.camera.setPosition(this.camera.getPosition().add(delta.multiply(-1.0f)));
|
||||
}
|
||||
@ -93,12 +95,12 @@ public class ControlCameraSimple implements ControlInterface {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void periodicCall(final EventTime event) {
|
||||
float roll = this.camera.getRoll();
|
||||
final float roll = this.camera.getRoll();
|
||||
if (this.moveLeft != this.moveRight) {
|
||||
Vector3f orientation = new Vector3f(-(float)Math.cos(roll), (float)Math.sin(roll), 0);
|
||||
final Vector3f orientation = new Vector3f(-(float) Math.cos(roll), (float) Math.sin(roll), 0);
|
||||
if (this.moveRight) {
|
||||
this.camera.setPosition(this.camera.getPosition().add(orientation.multiply(-0.1f)));
|
||||
} else {
|
||||
@ -107,7 +109,7 @@ public class ControlCameraSimple implements ControlInterface {
|
||||
}
|
||||
if (!this.ctrlIsSet) {
|
||||
if (this.moveUp != this.moveDown) {
|
||||
Vector3f orientation = new Vector3f((float)Math.sin(roll), (float)Math.cos(roll), 0);
|
||||
final Vector3f orientation = new Vector3f((float) Math.sin(roll), (float) Math.cos(roll), 0);
|
||||
if (this.moveUp) {
|
||||
this.camera.setPosition(this.camera.getPosition().add(orientation.multiply(0.1f)));
|
||||
} else {
|
||||
@ -122,5 +124,5 @@ public class ControlCameraSimple implements ControlInterface {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,12 +4,14 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.atriasoft.etk.math.Vector3f;
|
||||
import org.atriasoft.ege.internal.Log;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Entity {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(Entity.class);
|
||||
private static int uIDGlobal = 0; //!< This is a reference on a basic Entity ID
|
||||
protected Environement env = null;
|
||||
protected List<Component> component = new ArrayList<Component>();
|
||||
protected List<Component> component = new ArrayList<>();
|
||||
|
||||
private final int uID = uIDGlobal++; //!< This is a reference on a basic Entity ID
|
||||
protected float life = 100; //!< Current life of the object
|
||||
@ -34,14 +36,14 @@ public class Entity {
|
||||
}
|
||||
// Remove component with the same name.
|
||||
this.removeComponent(ref.getType());
|
||||
LOGGER.print("Entity: Add New component ... [START]");
|
||||
LOGGER.info("Entity: Add New component ... [START]");
|
||||
this.component.add(ref);
|
||||
this.env.engineComponentAdd(ref);
|
||||
for (final Component it : this.component) {
|
||||
ref.addFriendComponent(it);
|
||||
it.addFriendComponent(ref);
|
||||
}
|
||||
LOGGER.print("Entity: Add New component ... [END]");
|
||||
LOGGER.info("Entity: Add New component ... [END]");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,11 +86,11 @@ public class Entity {
|
||||
public void entityIsRemoved(final Entity removedEntity) {};
|
||||
|
||||
public boolean exist(final String type) {
|
||||
for (int iii = 0; iii < this.component.size(); ++iii) {
|
||||
if (this.component.get(iii) == null) {
|
||||
for (final Component element : this.component) {
|
||||
if (element == null) {
|
||||
continue;
|
||||
}
|
||||
if (this.component.get(iii).getType().contentEquals(type)) {
|
||||
if (element.getType().contentEquals(type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -97,12 +99,12 @@ public class Entity {
|
||||
|
||||
public Component getComponent(final String type) {
|
||||
// check if not exist
|
||||
for (int iii = 0; iii < this.component.size(); ++iii) {
|
||||
if (this.component.get(iii) == null) {
|
||||
for (final Component element : this.component) {
|
||||
if (element == null) {
|
||||
continue;
|
||||
}
|
||||
if (this.component.get(iii).getType().contentEquals(type)) {
|
||||
return this.component.get(iii);
|
||||
if (element.getType().contentEquals(type)) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -233,7 +235,7 @@ public class Entity {
|
||||
LOGGER.error("try to remove an empty component");
|
||||
return;
|
||||
}
|
||||
if (this.component.remove(ref) == false) {
|
||||
if (!this.component.remove(ref)) {
|
||||
LOGGER.error("try to remove an unexisting component");
|
||||
return;
|
||||
}
|
||||
@ -255,7 +257,7 @@ public class Entity {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (findIt == false) {
|
||||
if (!findIt) {
|
||||
//LOGGER.error("try to remove an unknown component type : '{}'", type);
|
||||
return;
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ import org.atriasoft.ege.engines.EngineParticle;
|
||||
import org.atriasoft.ege.engines.EnginePhysics;
|
||||
import org.atriasoft.ege.engines.EnginePlayer;
|
||||
import org.atriasoft.ege.engines.EngineRender;
|
||||
import org.atriasoft.ege.internal.Log;
|
||||
//import org.atriasoft.ege.resource.Mesh;
|
||||
import org.atriasoft.etk.math.Vector2f;
|
||||
import org.atriasoft.etk.math.Vector3f;
|
||||
@ -28,10 +27,13 @@ import org.atriasoft.gale.key.KeyKeyboard;
|
||||
import org.atriasoft.gale.key.KeySpecial;
|
||||
import org.atriasoft.gale.key.KeyStatus;
|
||||
import org.atriasoft.gale.key.KeyType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Environement {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(Environement.class);
|
||||
private static Map<String, CreatorEntity> creators = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* add a creator entity system
|
||||
* @param type Type of the entity.
|
||||
@ -45,26 +47,26 @@ public class Environement {
|
||||
LOGGER.debug("Add creator: {}", type);
|
||||
creators.put(type, creator);
|
||||
LOGGER.debug("Add creator: {} (done)", type);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Signal<Float> signalPlayTimeChange = new Signal<>();
|
||||
private GameStatus propertyStatus = GameStatus.gameStop; // !< the display is running (not in pause)
|
||||
public float propertyRatio = 1.0f; // !< Speed ratio
|
||||
protected List<Engine> engines = new ArrayList<>(); // !< EGE sub engine interface (like physique, rendering,
|
||||
// audio, ...).
|
||||
private final List<Entity> listEntity = new ArrayList<>(); // !< List of all entity added in the Game
|
||||
|
||||
|
||||
List<ControlInterface> controls = new ArrayList<>();
|
||||
long lastCallTime = 0;
|
||||
// ! list of all camera in the world
|
||||
protected Map<String, Camera> listCamera = new HashMap<>();
|
||||
|
||||
|
||||
protected long gameTime = 0; // !< time of the game running
|
||||
|
||||
|
||||
long startTime = 0;
|
||||
Clock startClock = null;
|
||||
|
||||
|
||||
//protected List<Mesh> listMeshToDrawFirst = new ArrayList<Mesh>();
|
||||
public Environement() {
|
||||
addEngine(new EngineGravity(this));
|
||||
@ -77,7 +79,7 @@ public class Environement {
|
||||
addEngine(new EngineLight(this));
|
||||
this.startClock = Clock.systemUTC();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a camera in the camera pool.
|
||||
* @param name Name of the camera.
|
||||
@ -86,11 +88,11 @@ public class Environement {
|
||||
public void addCamera(final String name, final Camera camera) {
|
||||
this.listCamera.put(name, camera);
|
||||
}
|
||||
|
||||
|
||||
public void addControlInterface(final ControlInterface ref) {
|
||||
this.controls.add(ref);
|
||||
}
|
||||
|
||||
|
||||
public void addEngine(final Engine ref) {
|
||||
if (ref == null) {
|
||||
LOGGER.error("try to add an empty Engine");
|
||||
@ -106,7 +108,7 @@ public class Environement {
|
||||
// add it at the end ...
|
||||
this.engines.add(ref);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add an entity on the list availlable.
|
||||
* @param newEntity Entity to add.
|
||||
@ -119,18 +121,18 @@ public class Environement {
|
||||
this.listEntity.add(newEntity);
|
||||
newEntity.dynamicEnable();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove all from the current environement
|
||||
*/
|
||||
public void clear() {
|
||||
this.listEntity.clear();
|
||||
}
|
||||
|
||||
|
||||
public Entity createEntity(final String type, final boolean autoAddEntity) {
|
||||
return this.createEntity(type, null, autoAddEntity);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an entity on the curent scene.
|
||||
* @param type Type of the entity that might be created.
|
||||
@ -143,7 +145,7 @@ public class Environement {
|
||||
* @note Pointer is return in case of setting properties on it...
|
||||
*/
|
||||
public Entity createEntity(final String type, final Object value, final boolean autoAddEntity) {
|
||||
if (creators.containsKey(type) == false) {
|
||||
if (!creators.containsKey(type)) {
|
||||
LOGGER.error("Request creating of an type that is not known '{}'", type);
|
||||
return null;
|
||||
}
|
||||
@ -157,13 +159,13 @@ public class Environement {
|
||||
LOGGER.error("allocation error ''{}'", type);
|
||||
return null;
|
||||
}
|
||||
if (autoAddEntity == true) {
|
||||
if (autoAddEntity) {
|
||||
addEntity(tmpEntity);
|
||||
}
|
||||
return tmpEntity;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void engineComponentAdd(final Component ref) {
|
||||
for (final Engine it : this.engines) {
|
||||
if (it.getType().contentEquals(ref.getType())) {
|
||||
@ -172,7 +174,7 @@ public class Environement {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void engineComponentRemove(final Component ref) {
|
||||
for (final Engine it : this.engines) {
|
||||
if (it.getType().contentEquals(ref.getType())) {
|
||||
@ -181,7 +183,7 @@ public class Environement {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* generate an event on all the sub entity of the game == > usefull for
|
||||
* explosion, or lazer fire ...
|
||||
@ -189,8 +191,8 @@ public class Environement {
|
||||
*/
|
||||
public void generateInteraction(final EntityInteraction event) {
|
||||
// inform the entity that an entity has been removed ==> this permit to keep pointer on entitys ...
|
||||
for (int iii = 0; iii < this.listEntity.size(); iii++) {
|
||||
event.applyEvent(this.listEntity.get(iii));
|
||||
for (final Entity element : this.listEntity) {
|
||||
event.applyEvent(element);
|
||||
/*
|
||||
Vector3f destPosition = mlistEntity[iii].getPosition();
|
||||
float dist = (sourcePosition - destPosition).length;
|
||||
@ -201,7 +203,7 @@ public class Environement {
|
||||
glistEntity[iii].setFireOn(groupIdSource, type, -inpact, sourcePosition);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// private void onCallbackPeriodicCall(ewol::event::Time event) {
|
||||
// float curentDelta = event.getDeltaCall();
|
||||
@ -274,7 +276,7 @@ public class Environement {
|
||||
// }
|
||||
// */
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Get a specific camera.
|
||||
* @param name Name of the camera.
|
||||
@ -283,7 +285,7 @@ public class Environement {
|
||||
public Camera getCamera(final String name) {
|
||||
return this.listCamera.get(name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get List of all camera.
|
||||
* @return All the camera registerred.
|
||||
@ -291,7 +293,7 @@ public class Environement {
|
||||
public Map<String, Camera> getCameraList() {
|
||||
return this.listCamera;
|
||||
}
|
||||
|
||||
|
||||
public Engine getEngine(final String type) {
|
||||
for (final Engine it : this.engines) {
|
||||
if (it.getType().contains(type)) {
|
||||
@ -301,7 +303,7 @@ public class Environement {
|
||||
LOGGER.error("try to get an unexisting engine type: ''{}'", type);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @breif get a reference on the curent list of entity games
|
||||
* @return all entity list
|
||||
@ -309,25 +311,34 @@ public class Environement {
|
||||
public List<Entity> getEntity() {
|
||||
return this.listEntity;
|
||||
}
|
||||
|
||||
|
||||
public GameStatus getPropertyStatus() {
|
||||
return this.propertyStatus;
|
||||
}
|
||||
|
||||
public void onKeyboard(final KeySpecial special, final KeyKeyboard type, final Character value, final KeyStatus state) {
|
||||
|
||||
public void onKeyboard(
|
||||
final KeySpecial special,
|
||||
final KeyKeyboard type,
|
||||
final Character value,
|
||||
final KeyStatus state) {
|
||||
final EventEntry event = new EventEntry(special, type, state, value);
|
||||
for (final ControlInterface elem : this.controls) {
|
||||
elem.onEventEntry(event);
|
||||
}
|
||||
}
|
||||
|
||||
public void onPointer(final KeySpecial special, final KeyType type, final int pointerID, final Vector3f pos, final KeyStatus state) {
|
||||
|
||||
public void onPointer(
|
||||
final KeySpecial special,
|
||||
final KeyType type,
|
||||
final int pointerID,
|
||||
final Vector3f pos,
|
||||
final KeyStatus state) {
|
||||
final EventInput event = new EventInput(type, state, pointerID, new Vector2f(pos.x(), pos.y()), special);
|
||||
for (final ControlInterface elem : this.controls) {
|
||||
elem.onEventInput(event, pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void periodicCall() {
|
||||
if (this.lastCallTime == 0) {
|
||||
this.startTime = System.nanoTime();
|
||||
@ -335,13 +346,13 @@ public class Environement {
|
||||
}
|
||||
long lastUpdate = this.lastCallTime;
|
||||
this.lastCallTime = System.nanoTime();
|
||||
Clock currentClock = Clock.systemUTC();
|
||||
final Clock currentClock = Clock.systemUTC();
|
||||
// in the simulation, we need to limit the delta...
|
||||
if (this.lastCallTime - lastUpdate > 1000000000) {
|
||||
lastUpdate = this.lastCallTime - 5100000;
|
||||
}
|
||||
final EventTime event = new EventTime(currentClock, this.startClock, this.lastCallTime, this.startTime, Duration.ofNanos(this.lastCallTime - lastUpdate),
|
||||
Duration.ofNanos(this.lastCallTime - lastUpdate));
|
||||
final EventTime event = new EventTime(currentClock, this.startClock, this.lastCallTime, this.startTime,
|
||||
Duration.ofNanos(this.lastCallTime - lastUpdate), Duration.ofNanos(this.lastCallTime - lastUpdate));
|
||||
for (final ControlInterface elem : this.controls) {
|
||||
elem.periodicCall(event);
|
||||
}
|
||||
@ -349,11 +360,11 @@ public class Environement {
|
||||
engine.update((this.lastCallTime - lastUpdate) / 1000000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void removeControlInterface(final ControlInterface ref) {
|
||||
this.controls.remove(ref);
|
||||
}
|
||||
|
||||
|
||||
public void render(final long deltaMilli, final String cameraName) {
|
||||
//LOGGER.error("Render: {} time: {}", cameraName, deltaMilli);
|
||||
// get the correct camera:
|
||||
@ -374,13 +385,13 @@ public class Environement {
|
||||
// LOGGER.trace(" render: {}", it.getType());
|
||||
// it.renderDebug(deltaMilli, camera);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void rmEngine(final Engine ref) {
|
||||
this.engines.remove(ref);
|
||||
}
|
||||
|
||||
|
||||
// public void addStaticMeshToDraw(Mesh mesh) {
|
||||
// listMeshToDrawFirst.add(mesh);
|
||||
// }
|
||||
@ -388,7 +399,7 @@ public class Environement {
|
||||
// public List<Mesh> getStaticMeshToDraw() {
|
||||
// return listMeshToDrawFirst;
|
||||
// }
|
||||
|
||||
|
||||
public void rmEngine(final String type) {
|
||||
for (final Engine it : this.engines) {
|
||||
if (it.getType().contains(type)) {
|
||||
@ -397,7 +408,7 @@ public class Environement {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* remove an entity on the list availlable.
|
||||
* @param removeEntity Entity to remove.
|
||||
@ -406,16 +417,16 @@ public class Environement {
|
||||
if (removeEntity == null) {
|
||||
return;
|
||||
}
|
||||
for (int iii = 0; iii < this.listEntity.size(); iii++) {
|
||||
this.listEntity.get(iii).entityIsRemoved(removeEntity);
|
||||
for (final Entity element : this.listEntity) {
|
||||
element.entityIsRemoved(removeEntity);
|
||||
}
|
||||
if (this.listEntity.remove(removeEntity) == true) {
|
||||
if (this.listEntity.remove(removeEntity)) {
|
||||
removeEntity.onDestroy();
|
||||
removeEntity.dynamicDisable();
|
||||
removeEntity.unInit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setPropertyStatus(final GameStatus propertyStatus) {
|
||||
if (this.propertyStatus == propertyStatus) {
|
||||
return;
|
||||
@ -441,7 +452,7 @@ public class Environement {
|
||||
* destPosition).length(); //EGE.debug("Distance : " + distance + " >? " +
|
||||
* distance + " id=" + iii); if (distanceMax>result.dist) {
|
||||
* resultList.pushBack(result); } } }
|
||||
*
|
||||
*
|
||||
* void Environement::getEntityNearestFixed( Vector3f sourcePosition, float
|
||||
* distanceMax, List<Environement::ResultNearestEntity> resultList) {
|
||||
* resultList.clear(); Environement::ResultNearestEntity result; result.dist =
|
||||
|
@ -3,10 +3,12 @@ package org.atriasoft.ege.components;
|
||||
import org.atriasoft.ege.Component;
|
||||
import org.atriasoft.ege.Light;
|
||||
import org.atriasoft.ege.components.part.PositionningInterface;
|
||||
import org.atriasoft.ege.internal.Log;
|
||||
import org.atriasoft.etk.math.Vector3f;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ComponentLight extends Component {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(ComponentLight.class);
|
||||
// the material is not a resource, it can change in time... with AI or selection...
|
||||
private final Light light;
|
||||
private PositionningInterface position = null;
|
||||
@ -22,10 +24,11 @@ public class ComponentLight extends Component {
|
||||
@Override
|
||||
public void addFriendComponent(final Component component) {
|
||||
if (component.getType().contentEquals("position") || component.getType().contentEquals("physics")) {
|
||||
if (component instanceof PositionningInterface tmp) {
|
||||
if (component instanceof final PositionningInterface tmp) {
|
||||
this.position = tmp;
|
||||
} else {
|
||||
LOGGER.error("component: {} is not an instance of {}", component.getClass().getCanonicalName(), PositionningInterface.class.getCanonicalName());
|
||||
LOGGER.error("component: {} is not an instance of {}", component.getClass().getCanonicalName(),
|
||||
PositionningInterface.class.getCanonicalName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import org.atriasoft.ege.Component;
|
||||
import org.atriasoft.ege.Environement;
|
||||
import org.atriasoft.ege.engines.EngineGravity;
|
||||
import org.atriasoft.ege.engines.EnginePhysics;
|
||||
import org.atriasoft.ege.internal.Log;
|
||||
import org.atriasoft.etk.Color;
|
||||
import org.atriasoft.etk.math.FMath;
|
||||
import org.atriasoft.etk.math.Matrix4f;
|
||||
@ -31,17 +30,20 @@ import org.atriasoft.phyligram.math.ToolCollisionSphereWithHeightMapChunk;
|
||||
import org.atriasoft.phyligram.math.ToolCollisionSphereWithSphere;
|
||||
import org.atriasoft.phyligram.math.ToolCollisionSphereWithTriangle;
|
||||
import org.atriasoft.phyligram.shape.AABB;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ComponentPhysics extends Component {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(ComponentPhysics.class);
|
||||
public static float MINIMUM_BOUNCING_STOP = 0.0001f;
|
||||
//public static float ANGLE_MAX_BOUNCING = 0.02f;
|
||||
public static float globalMaxSpeed = Float.MAX_VALUE;
|
||||
private AABB aabb;
|
||||
private List<ComponentPhysics> aabbIntersection = new ArrayList<>();
|
||||
private final List<ComponentPhysics> aabbIntersection = new ArrayList<>();
|
||||
private Set<ComponentPhysics> collisionPrevious = new HashSet<>();
|
||||
private Map<ComponentPhysics, List<ColisionPoint>> collisionCurrent = new HashMap<>();
|
||||
private final Map<ComponentPhysics, List<ColisionPoint>> collisionCurrent = new HashMap<>();
|
||||
//List<ColisionPoint> collisionPoints = new ArrayList<>();
|
||||
private List<PhysicShape> shapes = new ArrayList<>();
|
||||
private final List<PhysicShape> shapes = new ArrayList<>();
|
||||
// collision already exist ==> prepare friction:
|
||||
Transform3D previousPosition;
|
||||
private ComponentPosition position;
|
||||
@ -52,12 +54,12 @@ public class ComponentPhysics extends Component {
|
||||
// current acceleration of the object
|
||||
private Vector3f acceleration = new Vector3f(0, 0, 0);
|
||||
// Applied static force on it
|
||||
private Vector3f staticForce = new Vector3f(0, 0, 0);
|
||||
private final Vector3f staticForce = new Vector3f(0, 0, 0);
|
||||
// Apply dynamic force on it
|
||||
private Vector3f dynamicForce = new Vector3f(0, 0, 0);
|
||||
private final Vector3f dynamicForce = new Vector3f(0, 0, 0);
|
||||
// Apply dynamic force on it
|
||||
private Vector3f dynamicForceGlobal = new Vector3f(0, 0, 0);
|
||||
private EnginePhysics engine;
|
||||
private final Vector3f dynamicForceGlobal = new Vector3f(0, 0, 0);
|
||||
private final EnginePhysics engine;
|
||||
private PhysicBodyType bodyType;
|
||||
|
||||
public ComponentPhysics(final Environement _env) {
|
||||
@ -65,9 +67,9 @@ public class ComponentPhysics extends Component {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFriendComponent(Component component) {
|
||||
public void addFriendComponent(final Component component) {
|
||||
if (component.getType().contentEquals("position")) {
|
||||
if (component instanceof ComponentPosition tmp) {
|
||||
if (component instanceof final ComponentPosition tmp) {
|
||||
this.position = tmp;
|
||||
} else {
|
||||
LOGGER.error("Not manage position model...");
|
||||
@ -75,7 +77,7 @@ public class ComponentPhysics extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
public void addIntersection(ComponentPhysics component) {
|
||||
public void addIntersection(final ComponentPhysics component) {
|
||||
// do not add multiple times
|
||||
if (this.aabbIntersection.contains(component)) {
|
||||
return;
|
||||
@ -83,19 +85,19 @@ public class ComponentPhysics extends Component {
|
||||
this.aabbIntersection.add(component);
|
||||
}
|
||||
|
||||
public void addShape(PhysicShape shape) {
|
||||
public void addShape(final PhysicShape shape) {
|
||||
this.shapes.add(shape);
|
||||
}
|
||||
|
||||
public void applyColisionForce(float timeStep) {
|
||||
for (Entry<ComponentPhysics, List<ColisionPoint>> elem : this.collisionCurrent.entrySet()) {
|
||||
public void applyColisionForce(final float timeStep) {
|
||||
for (final Entry<ComponentPhysics, List<ColisionPoint>> elem : this.collisionCurrent.entrySet()) {
|
||||
Float globalBouncing = null;
|
||||
if (!this.collisionPrevious.contains(elem.getKey())) {
|
||||
globalBouncing = elem.getKey().getBouncingCoefficient();
|
||||
}
|
||||
float globalFriction = elem.getKey().getFrictionCoefficient();
|
||||
Vector3f globalForce = Vector3f.ZERO;
|
||||
for (ColisionPoint impact : elem.getValue()) {
|
||||
for (final ColisionPoint impact : elem.getValue()) {
|
||||
globalForce = globalForce.add(impact.force);
|
||||
}
|
||||
// nothing to apply ?
|
||||
@ -125,7 +127,7 @@ public class ComponentPhysics extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
public void applyForces(float timeStep, EngineGravity gravity) {
|
||||
public void applyForces(final float timeStep, final EngineGravity gravity) {
|
||||
// get the gravity at the specific position...
|
||||
Vector3f gravityAcceleration;
|
||||
if (this.manageGravity) {
|
||||
@ -136,14 +138,14 @@ public class ComponentPhysics extends Component {
|
||||
// apply this force on the Object
|
||||
LOGGER.info("apply gravity: {}", gravityAcceleration);
|
||||
// relative to the object
|
||||
Vector3f staticForce = this.staticForce;
|
||||
final Vector3f staticForce = this.staticForce;
|
||||
float globalMass = 0;
|
||||
for (PhysicShape shape : this.shapes) {
|
||||
for (final PhysicShape shape : this.shapes) {
|
||||
globalMass += shape.getMass();
|
||||
}
|
||||
// note the acceleration is not real, it depend on the current delta time...
|
||||
Vector3f staticforceOriented = this.position.getTransform().getOrientation().multiply(staticForce);
|
||||
Vector3f dynamicforceOriented = this.position.getTransform().getOrientation().multiply(this.dynamicForce);
|
||||
final Vector3f staticforceOriented = this.position.getTransform().getOrientation().multiply(staticForce);
|
||||
final Vector3f dynamicforceOriented = this.position.getTransform().getOrientation().multiply(this.dynamicForce);
|
||||
Vector3f globalForce = staticforceOriented.add(dynamicforceOriented);
|
||||
if (globalMass > 0.0) {
|
||||
globalForce = globalForce.divide(globalMass);
|
||||
@ -158,7 +160,8 @@ public class ComponentPhysics extends Component {
|
||||
limitWithMaxSpeed();
|
||||
LOGGER.info("apply acceleration: {}", this.acceleration);
|
||||
LOGGER.info("apply speed: {}", this.speed);
|
||||
this.position.setTransform(this.position.getTransform().withPosition(this.position.getTransform().getPosition().add(this.speed)));
|
||||
this.position.setTransform(
|
||||
this.position.getTransform().withPosition(this.position.getTransform().getPosition().add(this.speed)));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -209,61 +212,61 @@ public class ComponentPhysics extends Component {
|
||||
}
|
||||
*/
|
||||
|
||||
private boolean checkCollide(PhysicShape shapeCurrent) {
|
||||
if (shapeCurrent instanceof PhysicBox shape111) {
|
||||
for (PhysicShape shape : this.shapes) {
|
||||
if (shape instanceof PhysicHeightMapChunk shape222) {
|
||||
private boolean checkCollide(final PhysicShape shapeCurrent) {
|
||||
if (shapeCurrent instanceof final PhysicBox shape111) {
|
||||
for (final PhysicShape shape : this.shapes) {
|
||||
if (shape instanceof final PhysicHeightMapChunk shape222) {
|
||||
// detect collision from cube on height-map !!!
|
||||
|
||||
} else if (shape instanceof PhysicBox shape222) {
|
||||
} else if (shape instanceof final PhysicBox shape222) {
|
||||
// detect collision between 2 cubes
|
||||
if (ToolCollisionOBBWithOBB.testCollide(shape111, shape222)) {
|
||||
return true;
|
||||
}
|
||||
} else if (shape instanceof PhysicSphere shape222) {
|
||||
} else if (shape instanceof final PhysicSphere shape222) {
|
||||
|
||||
} else if (shape instanceof PhysicMapVoxel shape222) {
|
||||
} else if (shape instanceof final PhysicMapVoxel shape222) {
|
||||
|
||||
} else {
|
||||
LOGGER.error("Not manage collision model... {}", shape);
|
||||
}
|
||||
}
|
||||
} else if (shapeCurrent instanceof PhysicSphere shape111) {
|
||||
for (PhysicShape shape : this.shapes) {
|
||||
if (shape instanceof PhysicHeightMapChunk shape222) {
|
||||
} else if (shapeCurrent instanceof final PhysicSphere shape111) {
|
||||
for (final PhysicShape shape : this.shapes) {
|
||||
if (shape instanceof final PhysicHeightMapChunk shape222) {
|
||||
// detect collision from sphere on height-map !!!
|
||||
if (ToolCollisionSphereWithHeightMapChunk.testCollide(shape111, shape222)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
} else if (shape instanceof PhysicTriangle shape222) {
|
||||
} else if (shape instanceof final PhysicTriangle shape222) {
|
||||
// detect collision from sphere on height-map !!!
|
||||
if (ToolCollisionSphereWithTriangle.testCollide(shape111, shape222)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
} else if (shape instanceof PhysicBox shape222) {
|
||||
} else if (shape instanceof final PhysicBox shape222) {
|
||||
// detect collision from sphere on cube !!!
|
||||
|
||||
} else if (shape instanceof PhysicSphere shape222) {
|
||||
} else if (shape instanceof final PhysicSphere shape222) {
|
||||
// detect collision from sphere on sphere !!!
|
||||
if (ToolCollisionSphereWithSphere.testCollide(shape111, shape222)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
} else if (shape instanceof PhysicMapVoxel shape222) {
|
||||
} else if (shape instanceof final PhysicMapVoxel shape222) {
|
||||
|
||||
} else {
|
||||
LOGGER.error("Not manage collision model... {}", shape);
|
||||
}
|
||||
}
|
||||
} else if (shapeCurrent instanceof PhysicMapVoxel shape111) {
|
||||
for (PhysicShape shape : this.shapes) {
|
||||
if (shape instanceof PhysicBox shape222) {
|
||||
} else if (shapeCurrent instanceof final PhysicMapVoxel shape111) {
|
||||
for (final PhysicShape shape : this.shapes) {
|
||||
if (shape instanceof final PhysicBox shape222) {
|
||||
|
||||
} else if (shape instanceof PhysicSphere shape222) {
|
||||
} else if (shape instanceof final PhysicSphere shape222) {
|
||||
|
||||
} else if (shape instanceof PhysicMapVoxel shape222) {
|
||||
} else if (shape instanceof final PhysicMapVoxel shape222) {
|
||||
|
||||
} else {
|
||||
LOGGER.error("Not manage collision model... {}", shape);
|
||||
@ -279,9 +282,9 @@ public class ComponentPhysics extends Component {
|
||||
if (this.bodyType != PhysicBodyType.BODY_DYNAMIC) {
|
||||
return false;
|
||||
}
|
||||
for (ComponentPhysics elem : this.aabbIntersection) {
|
||||
for (final ComponentPhysics elem : this.aabbIntersection) {
|
||||
boolean collide = false;
|
||||
for (PhysicShape shapeCurrent : this.shapes) {
|
||||
for (final PhysicShape shapeCurrent : this.shapes) {
|
||||
if (elem.checkCollide(shapeCurrent)) {
|
||||
collide = true;
|
||||
break;
|
||||
@ -329,23 +332,25 @@ public class ComponentPhysics extends Component {
|
||||
|
||||
private float getBouncingCoefficient() {
|
||||
float total = 0.0f;
|
||||
for (PhysicShape shape : this.shapes) {
|
||||
for (final PhysicShape shape : this.shapes) {
|
||||
total = FMath.max(total, shape.getBouncingCoefficient());
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
private List<ColisionPoint> getCollidePoints(PhysicShape shapeRemote) {
|
||||
List<ColisionPoint> out = new ArrayList<>();
|
||||
if (shapeRemote instanceof PhysicSphere remoteShere) {
|
||||
for (PhysicShape shape : this.shapes) {
|
||||
if (shape instanceof PhysicSphere localShape) {
|
||||
ColisionPoint point = ToolCollisionSphereWithSphere.getCollisionPoint(remoteShere, localShape);
|
||||
private List<ColisionPoint> getCollidePoints(final PhysicShape shapeRemote) {
|
||||
final List<ColisionPoint> out = new ArrayList<>();
|
||||
if (shapeRemote instanceof final PhysicSphere remoteShere) {
|
||||
for (final PhysicShape shape : this.shapes) {
|
||||
if (shape instanceof final PhysicSphere localShape) {
|
||||
final ColisionPoint point = ToolCollisionSphereWithSphere.getCollisionPoint(remoteShere,
|
||||
localShape);
|
||||
if (point != null) {
|
||||
out.add(point);
|
||||
}
|
||||
} else if (shape instanceof PhysicTriangle localShape) {
|
||||
ColisionPoint point = ToolCollisionSphereWithTriangle.getCollisionPoint(remoteShere, localShape);
|
||||
} else if (shape instanceof final PhysicTriangle localShape) {
|
||||
final ColisionPoint point = ToolCollisionSphereWithTriangle.getCollisionPoint(remoteShere,
|
||||
localShape);
|
||||
if (point != null) {
|
||||
out.add(point);
|
||||
}
|
||||
@ -362,7 +367,7 @@ public class ComponentPhysics extends Component {
|
||||
|
||||
public float getFrictionCoefficient() {
|
||||
float total = 0.0f;
|
||||
for (PhysicShape shape : this.shapes) {
|
||||
for (final PhysicShape shape : this.shapes) {
|
||||
total = FMath.max(total, shape.getFrictionCoefficient());
|
||||
}
|
||||
return total;
|
||||
@ -401,64 +406,64 @@ public class ComponentPhysics extends Component {
|
||||
if (this.collisionCurrent.size() == 0) {
|
||||
return;
|
||||
}
|
||||
for (Entry<ComponentPhysics, List<ColisionPoint>> elem : this.collisionCurrent.entrySet()) {
|
||||
for (PhysicShape shapeCurrent : this.shapes) {
|
||||
for (final Entry<ComponentPhysics, List<ColisionPoint>> elem : this.collisionCurrent.entrySet()) {
|
||||
for (final PhysicShape shapeCurrent : this.shapes) {
|
||||
//TODO Do a better method we do this many times ...
|
||||
/*
|
||||
if (!elem.checkCollide(shapeCurrent)) {
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
List<ColisionPoint> points = elem.getKey().getCollidePoints(shapeCurrent);
|
||||
final List<ColisionPoint> points = elem.getKey().getCollidePoints(shapeCurrent);
|
||||
elem.getValue().addAll(points);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFriendComponent(Component component) {
|
||||
public void removeFriendComponent(final Component component) {
|
||||
// nothing to do.
|
||||
}
|
||||
|
||||
public void renderDebug(ResourceColored3DObject debugDrawProperty) {
|
||||
public void renderDebug(final ResourceColored3DObject debugDrawProperty) {
|
||||
Color displayColor;
|
||||
displayColor = new Color(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
for (Entry<ComponentPhysics, List<ColisionPoint>> elem : this.collisionCurrent.entrySet()) {
|
||||
for (ColisionPoint impact : elem.getValue()) {
|
||||
debugDrawProperty.drawSquare(new Vector3f(0.02f, 0.02f, 0.02f), Matrix4f.createMatrixTranslate(impact.position), displayColor);
|
||||
for (final Entry<ComponentPhysics, List<ColisionPoint>> elem : this.collisionCurrent.entrySet()) {
|
||||
for (final ColisionPoint impact : elem.getValue()) {
|
||||
debugDrawProperty.drawSquare(new Vector3f(0.02f, 0.02f, 0.02f),
|
||||
Matrix4f.createMatrixTranslate(impact.position), displayColor);
|
||||
}
|
||||
}
|
||||
if (this.aabbIntersection.size() == 0) {
|
||||
displayColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
} else if (this.collisionCurrent.size() == 0) {
|
||||
displayColor = new Color(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
} else {
|
||||
if (this.collisionCurrent.size() == 0) {
|
||||
displayColor = new Color(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
} else {
|
||||
displayColor = new Color(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
displayColor = new Color(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
if (this.aabb != null) {
|
||||
debugDrawProperty.drawCubeLine(this.aabb.getMin(), this.aabb.getMax(), displayColor, Matrix4f.IDENTITY, true, true);
|
||||
debugDrawProperty.drawCubeLine(this.aabb.getMin(), this.aabb.getMax(), displayColor, Matrix4f.IDENTITY,
|
||||
true, true);
|
||||
//debugDrawProperty.drawCubeLine(new Vector3f(0,0,0), new Vector3f(32,32,32), new Color(1,0,1,1), Matrix4f.identity(), true, true);
|
||||
} else {
|
||||
LOGGER.error("no AABB");
|
||||
}
|
||||
|
||||
for (PhysicShape shape : this.shapes) {
|
||||
for (final PhysicShape shape : this.shapes) {
|
||||
shape.renderDebug(this.position.getTransform(), debugDrawProperty);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setBodyType(PhysicBodyType bodyType) {
|
||||
public void setBodyType(final PhysicBodyType bodyType) {
|
||||
this.bodyType = bodyType;
|
||||
}
|
||||
|
||||
public void setManageGravity(boolean manageGravity) {
|
||||
public void setManageGravity(final boolean manageGravity) {
|
||||
this.manageGravity = manageGravity;
|
||||
}
|
||||
|
||||
public void setMaxSpeed(float maxSpeed) {
|
||||
public void setMaxSpeed(final float maxSpeed) {
|
||||
this.maxSpeed = maxSpeed;
|
||||
}
|
||||
|
||||
@ -469,8 +474,8 @@ public class ComponentPhysics extends Component {
|
||||
return;
|
||||
}
|
||||
// TODO Add a flag to check if it is needed to update the AABB...
|
||||
AABB aabbNew = AABB.createInvertedEmpty();
|
||||
for (PhysicShape shape : this.shapes) {
|
||||
final AABB aabbNew = AABB.createInvertedEmpty();
|
||||
for (final PhysicShape shape : this.shapes) {
|
||||
shape.updateAABB(this.position.getTransform(), aabbNew);
|
||||
}
|
||||
this.aabb = aabbNew;
|
||||
@ -485,7 +490,7 @@ public class ComponentPhysics extends Component {
|
||||
LOGGER.info("No position in Entity ");
|
||||
return;
|
||||
}
|
||||
for (PhysicShape shape : this.shapes) {
|
||||
for (final PhysicShape shape : this.shapes) {
|
||||
shape.updateForNarrowCollision(this.position.getTransform());
|
||||
}
|
||||
}
|
||||
|
@ -5,26 +5,29 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.atriasoft.ege.Component;
|
||||
import org.atriasoft.ege.internal.Log;
|
||||
import org.atriasoft.etk.Uri;
|
||||
import org.atriasoft.loader3d.resources.ResourceStaticMesh;
|
||||
import org.atriasoft.loader3d.resources.ResourceStaticMeshObj;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ComponentStaticMeshs extends Component {
|
||||
private final Map<String, ResourceStaticMesh> meshs = new HashMap<String, ResourceStaticMesh>();
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(ComponentStaticMeshs.class);
|
||||
private final Map<String, ResourceStaticMesh> meshs = new HashMap<>();
|
||||
|
||||
public ComponentStaticMeshs() {
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
public ComponentStaticMeshs(Uri meshUrl) {
|
||||
public ComponentStaticMeshs(final Uri meshUrl) {
|
||||
// TODO load Mesh
|
||||
LOGGER.critical("Can not Load the Mesh for now ... {}", meshUrl);
|
||||
LOGGER.error("[CRITICAL]Can not Load the Mesh for now ... {}", meshUrl);
|
||||
System.exit(-1);
|
||||
final ResourceStaticMeshObj mesh = ResourceStaticMeshObj.create(meshUrl);
|
||||
setMesh("default", mesh);
|
||||
}
|
||||
|
||||
public void bindForRendering(String name) {
|
||||
public void bindForRendering(final String name) {
|
||||
final ResourceStaticMesh mesh = this.meshs.get(name);
|
||||
if (mesh == null) {
|
||||
return;
|
||||
@ -36,7 +39,7 @@ public class ComponentStaticMeshs extends Component {
|
||||
return this.meshs.keySet();
|
||||
}
|
||||
|
||||
public ResourceStaticMesh getMesh(String name) {
|
||||
public ResourceStaticMesh getMesh(final String name) {
|
||||
return this.meshs.get(name);
|
||||
}
|
||||
|
||||
@ -46,7 +49,7 @@ public class ComponentStaticMeshs extends Component {
|
||||
return "static-meshs";
|
||||
}
|
||||
|
||||
public void render(String name) {
|
||||
public void render(final String name) {
|
||||
final ResourceStaticMesh mesh = this.meshs.get(name);
|
||||
if (mesh == null) {
|
||||
return;
|
||||
@ -54,11 +57,11 @@ public class ComponentStaticMeshs extends Component {
|
||||
mesh.render();
|
||||
}
|
||||
|
||||
public void setMesh(String name, ResourceStaticMesh mesh) {
|
||||
public void setMesh(final String name, final ResourceStaticMesh mesh) {
|
||||
this.meshs.put(name, mesh);
|
||||
}
|
||||
|
||||
public void unBindForRendering(String name) {
|
||||
public void unBindForRendering(final String name) {
|
||||
final ResourceStaticMesh mesh = this.meshs.get(name);
|
||||
if (mesh == null) {
|
||||
return;
|
||||
|
@ -1,35 +1,37 @@
|
||||
package org.atriasoft.ege.components;
|
||||
|
||||
import org.atriasoft.ege.Component;
|
||||
import org.atriasoft.ege.internal.Log;
|
||||
import org.atriasoft.etk.Uri;
|
||||
import org.atriasoft.gale.resource.ResourceTexture;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ComponentTexture extends Component {
|
||||
|
||||
private ResourceTexture texture;
|
||||
|
||||
public ComponentTexture(Uri textureName) {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(ComponentTexture.class);
|
||||
|
||||
private final ResourceTexture texture;
|
||||
|
||||
public ComponentTexture(final Uri textureName) {
|
||||
this.texture = ResourceTexture.createFromPng(textureName);
|
||||
if (this.texture == null) {
|
||||
LOGGER.error("can not instanciate Texture ...");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void bindForRendering() {
|
||||
this.texture.bindForRendering(0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return "texture";
|
||||
}
|
||||
|
||||
|
||||
public void unBindForRendering() {
|
||||
this.texture.unBindForRendering();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,16 +2,18 @@ package org.atriasoft.ege.components;
|
||||
|
||||
import org.atriasoft.egami.ImageByte;
|
||||
import org.atriasoft.ege.Component;
|
||||
import org.atriasoft.ege.internal.Log;
|
||||
import org.atriasoft.etk.Uri;
|
||||
import org.atriasoft.gale.resource.ResourceTexture2;
|
||||
import org.atriasoft.loader3d.resources.ResourcePaletteFile;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ComponentTexturePalette extends Component {
|
||||
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(ComponentTexturePalette.class);
|
||||
|
||||
private final ResourcePaletteFile palette;
|
||||
private final ResourceTexture2 texture;
|
||||
|
||||
|
||||
public ComponentTexturePalette(final Uri paletteName) {
|
||||
this.palette = ResourcePaletteFile.create(paletteName);
|
||||
this.texture = ResourceTexture2.createNamed("TEXTURE_OF_PALETTE:" + paletteName.toString());
|
||||
@ -25,27 +27,27 @@ public class ComponentTexturePalette extends Component {
|
||||
updateFromPalette();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void updateFromPalette() {
|
||||
LOGGER.warn("update palet environnement");
|
||||
final ImageByte img = this.palette.getImageByte();
|
||||
//IOgami.storePNG(new Uri("/home/heero/000000000aaaaplopppp.png"), img);
|
||||
this.texture.set(img);
|
||||
}
|
||||
|
||||
|
||||
public void bindForRendering() {
|
||||
this.texture.bindForRendering(0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return "texture";
|
||||
}
|
||||
|
||||
|
||||
public void unBindForRendering() {
|
||||
this.texture.unBindForRendering();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,29 +4,31 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.atriasoft.ege.Component;
|
||||
import org.atriasoft.ege.internal.Log;
|
||||
import org.atriasoft.etk.Uri;
|
||||
import org.atriasoft.gale.resource.ResourceTexture;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ComponentTextures extends Component {
|
||||
private final Map<String, ResourceTexture> textures = new HashMap<String, ResourceTexture>();
|
||||
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(ComponentTextures.class);
|
||||
private final Map<String, ResourceTexture> textures = new HashMap<>();
|
||||
|
||||
public ComponentTextures() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void bindForRendering(String name) {
|
||||
|
||||
public void bindForRendering(final String name) {
|
||||
this.textures.get(name).bindForRendering(0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return "textures";
|
||||
}
|
||||
|
||||
public void setTexture(String name, Uri textureName) {
|
||||
|
||||
public void setTexture(final String name, final Uri textureName) {
|
||||
final ResourceTexture texture = ResourceTexture.createFromPng(textureName);
|
||||
if (texture == null) {
|
||||
LOGGER.error("can not instanciate Texture ...");
|
||||
@ -34,9 +36,9 @@ public class ComponentTextures extends Component {
|
||||
}
|
||||
this.textures.put(name, texture);
|
||||
}
|
||||
|
||||
public void unBindForRendering(String name) {
|
||||
|
||||
public void unBindForRendering(final String name) {
|
||||
this.textures.get(name).unBindForRendering();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,72 +9,75 @@ import org.atriasoft.ege.Light;
|
||||
import org.atriasoft.ege.camera.Camera;
|
||||
import org.atriasoft.ege.components.ComponentLight;
|
||||
import org.atriasoft.ege.components.ComponentLightSun;
|
||||
import org.atriasoft.ege.internal.Log;
|
||||
import org.atriasoft.etk.math.Vector3f;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class EngineLight extends Engine {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(EngineLight.class);
|
||||
public static final String ENGINE_NAME = "light";
|
||||
private final Vector<ComponentLight> componentLights = new Vector<ComponentLight>();
|
||||
private final Vector<ComponentLightSun> componentSuns = new Vector<ComponentLightSun>();
|
||||
private final Vector<ComponentLight> componentLights = new Vector<>();
|
||||
private final Vector<ComponentLightSun> componentSuns = new Vector<>();
|
||||
|
||||
public EngineLight(final Environement env) {
|
||||
super(env);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void componentRemove(final Component ref) {
|
||||
this.componentLights.remove(ref);
|
||||
this.componentSuns.remove(ref);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void componentAdd(final Component ref) {
|
||||
if (ref instanceof ComponentLightSun refTyped) {
|
||||
if (ref instanceof final ComponentLightSun refTyped) {
|
||||
this.componentSuns.add(refTyped);
|
||||
return;
|
||||
}
|
||||
if (ref instanceof ComponentLight refTyped) {
|
||||
if (ref instanceof final ComponentLight refTyped) {
|
||||
this.componentLights.add(refTyped);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(final long deltaMili) {
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render(final long deltaMili, final Camera camera) {
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void renderDebug(final long deltaMili, final Camera camera) {
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return EngineLight.ENGINE_NAME;
|
||||
}
|
||||
|
||||
|
||||
public Light[] getNearest(final Vector3f position) {
|
||||
Light[] out = new Light[8];
|
||||
final Light[] out = new Light[8];
|
||||
int count = 0;
|
||||
for (ComponentLightSun elem: this.componentSuns) {
|
||||
for (final ComponentLightSun elem : this.componentSuns) {
|
||||
out[count] = new Light(elem.getLight().getColor(), elem.getPosition(), elem.getLight().getAttenuation());
|
||||
if (count>=8) {
|
||||
if (count >= 8) {
|
||||
LOGGER.error("need to update ligth count");
|
||||
return out;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
//LOGGER.warn("Get {}/{} lights (SUN) ...", count, out.length);
|
||||
float maxDistance = 50*50;
|
||||
for (ComponentLight elem: this.componentLights) {
|
||||
Vector3f pos = elem.getPosition();
|
||||
if (count>=8) {
|
||||
final float maxDistance = 50 * 50;
|
||||
for (final ComponentLight elem : this.componentLights) {
|
||||
final Vector3f pos = elem.getPosition();
|
||||
if (count >= 8) {
|
||||
LOGGER.error("need to update ligth count");
|
||||
return out;
|
||||
}
|
||||
@ -86,5 +89,5 @@ public class EngineLight extends Engine {
|
||||
//LOGGER.warn("Get {} / {} lights...", count, out.length,);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -8,38 +8,41 @@ import org.atriasoft.ege.Environement;
|
||||
import org.atriasoft.ege.camera.Camera;
|
||||
import org.atriasoft.ege.components.ComponentPhysics;
|
||||
import org.atriasoft.ege.components.PhysicBodyType;
|
||||
import org.atriasoft.ege.internal.Log;
|
||||
import org.atriasoft.gale.resource.ResourceColored3DObject;
|
||||
import org.atriasoft.phyligram.DebugDisplay;
|
||||
import org.atriasoft.phyligram.shape.AABB;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class EnginePhysics extends Engine {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(EnginePhysics.class);
|
||||
public static final String ENGINE_NAME = "physics";
|
||||
private static final float TIME_STEP = 0.005f;
|
||||
private float accumulator = 0;
|
||||
private EngineGravity gravity;
|
||||
private final EngineGravity gravity;
|
||||
protected EnginePhysics engine;
|
||||
private Vector<ComponentPhysics> components = new Vector<>();
|
||||
private Vector<ComponentPhysics> componentsWithCollision = new Vector<>();
|
||||
private ResourceColored3DObject debugDrawProperty = ResourceColored3DObject.create();
|
||||
private final Vector<ComponentPhysics> components = new Vector<>();
|
||||
private final Vector<ComponentPhysics> componentsWithCollision = new Vector<>();
|
||||
private final ResourceColored3DObject debugDrawProperty = ResourceColored3DObject.create();
|
||||
|
||||
public EnginePhysics(Environement env) {
|
||||
public EnginePhysics(final Environement env) {
|
||||
super(env);
|
||||
this.gravity = (EngineGravity) env.getEngine("gravity");
|
||||
if (this.gravity == null) {
|
||||
LOGGER.critical("Must initialyse Gravity before physics...");
|
||||
LOGGER.error("[CRITICAL] Must initialyse Gravity before physics...");
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
private void addIncomponentWithCollision(ComponentPhysics elem) {
|
||||
private void addIncomponentWithCollision(final ComponentPhysics elem) {
|
||||
if (this.componentsWithCollision.contains(elem)) {
|
||||
return;
|
||||
}
|
||||
this.componentsWithCollision.add(elem);
|
||||
}
|
||||
|
||||
private void applyForces(float timeStep) {
|
||||
for (ComponentPhysics it : this.components) {
|
||||
private void applyForces(final float timeStep) {
|
||||
for (final ComponentPhysics it : this.components) {
|
||||
it.applyForces(timeStep, this.gravity);
|
||||
}
|
||||
}
|
||||
@ -48,21 +51,21 @@ public class EnginePhysics extends Engine {
|
||||
* Clear the previous data of collision.
|
||||
*/
|
||||
private void clearPreviousCycle() {
|
||||
for (ComponentPhysics it : this.components) {
|
||||
for (final ComponentPhysics it : this.components) {
|
||||
it.clearPreviousCollision();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentAdd(Component ref) {
|
||||
if (ref instanceof ComponentPhysics == false) {
|
||||
public void componentAdd(final Component ref) {
|
||||
if (!(ref instanceof ComponentPhysics)) {
|
||||
return;
|
||||
}
|
||||
this.components.add((ComponentPhysics) ref);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentRemove(Component ref) {
|
||||
public void componentRemove(final Component ref) {
|
||||
this.components.remove(ref);
|
||||
}
|
||||
|
||||
@ -70,8 +73,8 @@ public class EnginePhysics extends Engine {
|
||||
* Collision Detection STEP 4: apply all calculated forces (with containts)
|
||||
* @param timeStep
|
||||
*/
|
||||
private void generateResultCollisionsForces(float timeStep) {
|
||||
for (ComponentPhysics it : this.componentsWithCollision) {
|
||||
private void generateResultCollisionsForces(final float timeStep) {
|
||||
for (final ComponentPhysics it : this.componentsWithCollision) {
|
||||
it.applyColisionForce(timeStep);
|
||||
}
|
||||
}
|
||||
@ -83,9 +86,9 @@ public class EnginePhysics extends Engine {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(long deltaMili, Camera camera) {
|
||||
public void render(final long deltaMili, final Camera camera) {
|
||||
// TODO Auto-generated method stub
|
||||
for (ComponentPhysics it : this.components) {
|
||||
for (final ComponentPhysics it : this.components) {
|
||||
//LOGGER.info("Render {}", it);
|
||||
it.renderDebug(this.debugDrawProperty);
|
||||
}
|
||||
@ -96,13 +99,13 @@ public class EnginePhysics extends Engine {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderDebug(long deltaMili, Camera camera) {
|
||||
public void renderDebug(final long deltaMili, final Camera camera) {
|
||||
DebugDisplay.onDraw();
|
||||
DebugDisplay.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(long deltaMili) {
|
||||
public void update(final long deltaMili) {
|
||||
// Add the time difference in the accumulator
|
||||
this.accumulator += deltaMili * 0.0001f;
|
||||
// While there is enough accumulated time to take one or several physics steps
|
||||
@ -126,8 +129,8 @@ public class EnginePhysics extends Engine {
|
||||
* Collision detection STEP 1: Upadte the AABB positioning of each elements
|
||||
* @param timeStep Delta time since the last check
|
||||
*/
|
||||
private void updateAABB(float timeStep) {
|
||||
for (ComponentPhysics it : this.components) {
|
||||
private void updateAABB(final float timeStep) {
|
||||
for (final ComponentPhysics it : this.components) {
|
||||
it.updateAABB();
|
||||
}
|
||||
}
|
||||
@ -137,23 +140,24 @@ public class EnginePhysics extends Engine {
|
||||
* @param timeStep Delta time since the last check
|
||||
*/
|
||||
// TODO : generate a B-TREE to manage collision, it is faster, but now, this is not the purpose ...
|
||||
private void updateCollisionsAABB(float timeStep) {
|
||||
private void updateCollisionsAABB(final float timeStep) {
|
||||
this.componentsWithCollision.clear();
|
||||
// clear all object intersection
|
||||
for (ComponentPhysics it : this.components) {
|
||||
for (final ComponentPhysics it : this.components) {
|
||||
it.clearAABBIntersection();
|
||||
}
|
||||
// update the current object intersection...
|
||||
for (int iii = 0; iii < this.components.size(); iii++) {
|
||||
ComponentPhysics current = this.components.get(iii);
|
||||
AABB currentAABB = current.getAABB();
|
||||
final ComponentPhysics current = this.components.get(iii);
|
||||
final AABB currentAABB = current.getAABB();
|
||||
for (int jjj = iii + 1; jjj < this.components.size(); jjj++) {
|
||||
ComponentPhysics remote = this.components.get(jjj);
|
||||
if (current.getBodyType() != PhysicBodyType.BODY_DYNAMIC && remote.getBodyType() != PhysicBodyType.BODY_DYNAMIC) {
|
||||
final ComponentPhysics remote = this.components.get(jjj);
|
||||
if (current.getBodyType() != PhysicBodyType.BODY_DYNAMIC
|
||||
&& remote.getBodyType() != PhysicBodyType.BODY_DYNAMIC) {
|
||||
continue;
|
||||
}
|
||||
// prefer checking the collision, this a time-constant operation, check if collision already exist is a unpredictable time.
|
||||
if (currentAABB.intersect(this.components.get(jjj).getAABB()) == true) {
|
||||
if (currentAABB.intersect(this.components.get(jjj).getAABB())) {
|
||||
current.addIntersection(remote);
|
||||
remote.addIntersection(current);
|
||||
addIncomponentWithCollision(remote);
|
||||
@ -167,20 +171,18 @@ public class EnginePhysics extends Engine {
|
||||
* Collision Detection STEP 3: Narrow phase: process the collision between every OBB boxes (or other..)
|
||||
* @param timeStep Delta time since the last check
|
||||
*/
|
||||
private void updateCollisionsNarrowPhase(float timeStep) {
|
||||
private void updateCollisionsNarrowPhase(final float timeStep) {
|
||||
// clear all object intersection
|
||||
for (ComponentPhysics it : this.componentsWithCollision) {
|
||||
for (final ComponentPhysics it : this.componentsWithCollision) {
|
||||
it.updateForNarrowCollision();
|
||||
}
|
||||
// check for every component if the narrow collision is available.
|
||||
for (int iii = 0; iii < this.componentsWithCollision.size(); iii++) {
|
||||
ComponentPhysics current = this.componentsWithCollision.get(iii);
|
||||
boolean collide = current.checkNarrowCollision();
|
||||
for (final ComponentPhysics current : this.componentsWithCollision) {
|
||||
final boolean collide = current.checkNarrowCollision();
|
||||
|
||||
}
|
||||
// update the force of collision available.
|
||||
for (int iii = 0; iii < this.components.size(); iii++) {
|
||||
ComponentPhysics current = this.components.get(iii);
|
||||
for (final ComponentPhysics current : this.components) {
|
||||
current.narrowCollisionCreateContactAndForce();
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package org.atriasoft.ege.engines;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.atriasoft.ege.internal.Log;
|
||||
import org.atriasoft.ege.Component;
|
||||
import org.atriasoft.ege.Engine;
|
||||
import org.atriasoft.ege.Environement;
|
||||
@ -11,46 +10,47 @@ import org.atriasoft.ege.components.ComponentPlayer;
|
||||
|
||||
public class EnginePlayer extends Engine {
|
||||
public static final String ENGINE_NAME = "player";
|
||||
private Vector<ComponentPlayer> components = new Vector<ComponentPlayer>();
|
||||
public EnginePlayer(Environement env) {
|
||||
private final Vector<ComponentPlayer> components = new Vector<>();
|
||||
|
||||
public EnginePlayer(final Environement env) {
|
||||
super(env);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void componentRemove(Component ref) {
|
||||
components.remove(ref);
|
||||
public void componentRemove(final Component ref) {
|
||||
this.components.remove(ref);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void componentAdd(Component ref) {
|
||||
if (ref instanceof ComponentPlayer == false) {
|
||||
public void componentAdd(final Component ref) {
|
||||
if (!(ref instanceof ComponentPlayer)) {
|
||||
return;
|
||||
}
|
||||
components.add((ComponentPlayer)ref);
|
||||
this.components.add((ComponentPlayer) ref);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(long deltaMili) {
|
||||
for (ComponentPlayer it: components) {
|
||||
public void update(final long deltaMili) {
|
||||
for (final ComponentPlayer it : this.components) {
|
||||
it.update(deltaMili);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render(long deltaMili, Camera camera) {
|
||||
public void render(final long deltaMili, final Camera camera) {
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void renderDebug(long deltaMili, Camera camera) {
|
||||
public void renderDebug(final long deltaMili, final Camera camera) {
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return ENGINE_NAME;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,76 +0,0 @@
|
||||
package org.atriasoft.ege.internal;
|
||||
|
||||
import org.atriasoft.reggol.LogLevel;
|
||||
import org.atriasoft.reggol.Logger;
|
||||
|
||||
public class Log {
|
||||
private static final boolean FORCE_ALL = false;
|
||||
private static final String LIB_NAME = "ege";
|
||||
private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME);
|
||||
private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(LIB_NAME, LogLevel.CRITICAL);
|
||||
private static final boolean PRINT_ERROR = Logger.getNeedPrint(LIB_NAME, LogLevel.ERROR);
|
||||
private static final boolean PRINT_WARNING = Logger.getNeedPrint(LIB_NAME, LogLevel.WARNING);
|
||||
private static final boolean PRINT_INFO = Logger.getNeedPrint(LIB_NAME, LogLevel.INFO);
|
||||
private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG);
|
||||
private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(LIB_NAME, LogLevel.VERBOSE);
|
||||
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
|
||||
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
|
||||
|
||||
public static void critical(final Exception e, final String data) {
|
||||
e.printStackTrace();
|
||||
if (PRINT_CRITICAL || FORCE_ALL) {
|
||||
Logger.critical(LIB_NAME_DRAW, data + " : " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void critical(final String data, final Object... objects) {
|
||||
if (PRINT_CRITICAL || FORCE_ALL) {
|
||||
Logger.critical(LIB_NAME_DRAW, data, objects);
|
||||
}
|
||||
}
|
||||
|
||||
public static void debug(final String data, final Object... objects) {
|
||||
if (PRINT_DEBUG || FORCE_ALL) {
|
||||
Logger.debug(LIB_NAME_DRAW, data, objects);
|
||||
}
|
||||
}
|
||||
|
||||
public static void error(final String data, final Object... objects) {
|
||||
if (PRINT_ERROR || FORCE_ALL) {
|
||||
Logger.error(LIB_NAME_DRAW, data, objects);
|
||||
}
|
||||
}
|
||||
|
||||
public static void info(final String data, final Object... objects) {
|
||||
if (PRINT_INFO || FORCE_ALL) {
|
||||
Logger.info(LIB_NAME_DRAW, data, objects);
|
||||
}
|
||||
}
|
||||
|
||||
public static void print(final String data, final Object... objects) {
|
||||
if (PRINT_PRINT || FORCE_ALL) {
|
||||
Logger.print(LIB_NAME_DRAW, data, objects);
|
||||
}
|
||||
}
|
||||
|
||||
public static void todo(final String data, final Object... objects) {
|
||||
if (PRINT_TODO || FORCE_ALL) {
|
||||
Logger.todo(LIB_NAME_DRAW, data, objects);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verbose(final String data, final Object... objects) {
|
||||
if (PRINT_VERBOSE || FORCE_ALL) {
|
||||
Logger.verbose(LIB_NAME_DRAW, data, objects);
|
||||
}
|
||||
}
|
||||
|
||||
public static void warning(final String data, final Object... objects) {
|
||||
if (PRINT_WARNING || FORCE_ALL) {
|
||||
Logger.warning(LIB_NAME_DRAW, data, objects);
|
||||
}
|
||||
}
|
||||
|
||||
private Log() {}
|
||||
|
||||
}
|
@ -1,40 +1,41 @@
|
||||
package org.atriasoft.ege.map;
|
||||
|
||||
import org.atriasoft.ege.components.ComponentDynamicMeshs;
|
||||
import org.atriasoft.ege.internal.Log;
|
||||
import org.atriasoft.etk.math.Vector2f;
|
||||
import org.atriasoft.etk.math.Vector3f;
|
||||
import org.atriasoft.etk.math.Vector3i;
|
||||
import org.atriasoft.gale.backend3d.OpenGL.RenderMode;
|
||||
import org.atriasoft.loader3d.resources.ResourceListTexturedMesh;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ComponentDynamicMeshsVoxelMap extends ComponentDynamicMeshs {
|
||||
private VoxelChunk chunk;
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(ComponentDynamicMeshsVoxelMap.class);
|
||||
private final VoxelChunk chunk;
|
||||
ResourceListTexturedMesh unbreakable = ResourceListTexturedMesh.create(RenderMode.TRIANGLE);
|
||||
ResourceListTexturedMesh stone = ResourceListTexturedMesh.create(RenderMode.TRIANGLE);
|
||||
ResourceListTexturedMesh dirt = ResourceListTexturedMesh.create(RenderMode.TRIANGLE);
|
||||
ResourceListTexturedMesh grass = ResourceListTexturedMesh.create(RenderMode.TRIANGLE);
|
||||
|
||||
|
||||
public ComponentDynamicMeshsVoxelMap(final VoxelChunk chunk) {
|
||||
super();
|
||||
this.chunk = chunk;
|
||||
setMesh("unbreakable", this.unbreakable);
|
||||
setMesh("stone", this.stone);
|
||||
setMesh("dirt", this.dirt);
|
||||
setMesh("grass", this.grass);
|
||||
}
|
||||
|
||||
|
||||
private void drawPlane(final Vector3i base, final int xxx, final int yyy, final int zzz, final int type) {
|
||||
//LOGGER.warn("Add plane Z : {}, {}, {}", (base.x + xxx), (base.y + yyy), (base.z + zzz));
|
||||
Vector3f v1 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz);
|
||||
Vector3f v2 = new Vector3f(base.x() + xxx, base.y() + yyy + 1, base.z() + zzz);
|
||||
Vector3f v3 = new Vector3f(base.x() + xxx + 1, base.y() + yyy + 1, base.z() + zzz);
|
||||
Vector3f v4 = new Vector3f(base.x() + xxx + 1, base.y() + yyy, base.z() + zzz);
|
||||
Vector2f t1 = new Vector2f(0, 0);
|
||||
Vector2f t2 = new Vector2f(0, 1);
|
||||
Vector2f t3 = new Vector2f(1, 1);
|
||||
Vector2f t4 = new Vector2f(1, 0);
|
||||
Vector3f n1 = new Vector3f(0, 0, -1);
|
||||
final Vector3f v1 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz);
|
||||
final Vector3f v2 = new Vector3f(base.x() + xxx, base.y() + yyy + 1, base.z() + zzz);
|
||||
final Vector3f v3 = new Vector3f(base.x() + xxx + 1, base.y() + yyy + 1, base.z() + zzz);
|
||||
final Vector3f v4 = new Vector3f(base.x() + xxx + 1, base.y() + yyy, base.z() + zzz);
|
||||
final Vector2f t1 = new Vector2f(0, 0);
|
||||
final Vector2f t2 = new Vector2f(0, 1);
|
||||
final Vector2f t3 = new Vector2f(1, 1);
|
||||
final Vector2f t4 = new Vector2f(1, 0);
|
||||
final Vector3f n1 = new Vector3f(0, 0, -1);
|
||||
if (type == VoxelType.NATIVE_UNBREAKABLE) {
|
||||
this.unbreakable.addQuad(v1, v2, v3, v4, t1, t2, t3, t4, n1);
|
||||
} else if (type == VoxelType.NATIVE_DIRT) {
|
||||
@ -45,18 +46,18 @@ public class ComponentDynamicMeshsVoxelMap extends ComponentDynamicMeshs {
|
||||
this.grass.addQuad(v1, v2, v3, v4, t1, t2, t3, t4, n1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void drawPlane_anti(final Vector3i base, final int xxx, final int yyy, final int zzz, final int type) {
|
||||
//LOGGER.warn("Add plane Z : {}, {}, {}", (base.x + xxx), (base.y + yyy), (base.z + zzz));
|
||||
Vector3f v1 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz);
|
||||
Vector3f v2 = new Vector3f(base.x() + xxx, base.y() + yyy + 1, base.z() + zzz);
|
||||
Vector3f v3 = new Vector3f(base.x() + xxx + 1, base.y() + yyy + 1, base.z() + zzz);
|
||||
Vector3f v4 = new Vector3f(base.x() + xxx + 1, base.y() + yyy, base.z() + zzz);
|
||||
Vector2f t1 = new Vector2f(0, 0);
|
||||
Vector2f t2 = new Vector2f(0, 1);
|
||||
Vector2f t3 = new Vector2f(1, 1);
|
||||
Vector2f t4 = new Vector2f(1, 0);
|
||||
Vector3f n1 = new Vector3f(0, 0, 1);
|
||||
final Vector3f v1 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz);
|
||||
final Vector3f v2 = new Vector3f(base.x() + xxx, base.y() + yyy + 1, base.z() + zzz);
|
||||
final Vector3f v3 = new Vector3f(base.x() + xxx + 1, base.y() + yyy + 1, base.z() + zzz);
|
||||
final Vector3f v4 = new Vector3f(base.x() + xxx + 1, base.y() + yyy, base.z() + zzz);
|
||||
final Vector2f t1 = new Vector2f(0, 0);
|
||||
final Vector2f t2 = new Vector2f(0, 1);
|
||||
final Vector2f t3 = new Vector2f(1, 1);
|
||||
final Vector2f t4 = new Vector2f(1, 0);
|
||||
final Vector3f n1 = new Vector3f(0, 0, 1);
|
||||
if (type == VoxelType.NATIVE_UNBREAKABLE) {
|
||||
this.unbreakable.addQuad(v1, v4, v3, v2, t1, t4, t3, t2, n1);
|
||||
} else if (type == VoxelType.NATIVE_DIRT) {
|
||||
@ -67,18 +68,18 @@ public class ComponentDynamicMeshsVoxelMap extends ComponentDynamicMeshs {
|
||||
this.grass.addQuad(v1, v4, v3, v2, t1, t4, t3, t2, n1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void drawPlaneVerticalX(final Vector3i base, final int xxx, final int yyy, final int zzz, final int type) {
|
||||
//LOGGER.warn("Add plane X : {}, {}, {}", (base.x + xxx), (base.y + yyy), (base.z + zzz));
|
||||
Vector3f v1 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz);
|
||||
Vector3f v2 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz + 1);
|
||||
Vector3f v3 = new Vector3f(base.x() + xxx, base.y() + yyy + 1, base.z() + zzz + 1);
|
||||
Vector3f v4 = new Vector3f(base.x() + xxx, base.y() + yyy + 1, base.z() + zzz);
|
||||
Vector2f t1 = new Vector2f(0, 0);
|
||||
Vector2f t2 = new Vector2f(0, 1);
|
||||
Vector2f t3 = new Vector2f(1, 1);
|
||||
Vector2f t4 = new Vector2f(1, 0);
|
||||
Vector3f n1 = new Vector3f(-1, 0, 0);
|
||||
final Vector3f v1 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz);
|
||||
final Vector3f v2 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz + 1);
|
||||
final Vector3f v3 = new Vector3f(base.x() + xxx, base.y() + yyy + 1, base.z() + zzz + 1);
|
||||
final Vector3f v4 = new Vector3f(base.x() + xxx, base.y() + yyy + 1, base.z() + zzz);
|
||||
final Vector2f t1 = new Vector2f(0, 0);
|
||||
final Vector2f t2 = new Vector2f(0, 1);
|
||||
final Vector2f t3 = new Vector2f(1, 1);
|
||||
final Vector2f t4 = new Vector2f(1, 0);
|
||||
final Vector3f n1 = new Vector3f(-1, 0, 0);
|
||||
if (type == VoxelType.NATIVE_UNBREAKABLE) {
|
||||
this.unbreakable.addQuad(v1, v2, v3, v4, t1, t2, t3, t4, n1);
|
||||
} else if (type == VoxelType.NATIVE_DIRT) {
|
||||
@ -89,18 +90,23 @@ public class ComponentDynamicMeshsVoxelMap extends ComponentDynamicMeshs {
|
||||
this.grass.addQuad(v1, v2, v3, v4, t1, t2, t3, t4, n1);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawPlaneVerticalX_anti(final Vector3i base, final int xxx, final int yyy, final int zzz, final int type) {
|
||||
|
||||
private void drawPlaneVerticalX_anti(
|
||||
final Vector3i base,
|
||||
final int xxx,
|
||||
final int yyy,
|
||||
final int zzz,
|
||||
final int type) {
|
||||
//LOGGER.warn("Add plane X : {}, {}, {}", (base.x + xxx), (base.y + yyy), (base.z + zzz));
|
||||
Vector3f v1 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz);
|
||||
Vector3f v2 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz + 1);
|
||||
Vector3f v3 = new Vector3f(base.x() + xxx, base.y() + yyy + 1, base.z() + zzz + 1);
|
||||
Vector3f v4 = new Vector3f(base.x() + xxx, base.y() + yyy + 1, base.z() + zzz);
|
||||
Vector2f t1 = new Vector2f(0, 0);
|
||||
Vector2f t2 = new Vector2f(0, 1);
|
||||
Vector2f t3 = new Vector2f(1, 1);
|
||||
Vector2f t4 = new Vector2f(1, 0);
|
||||
Vector3f n1 = new Vector3f(1, 0, 0);
|
||||
final Vector3f v1 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz);
|
||||
final Vector3f v2 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz + 1);
|
||||
final Vector3f v3 = new Vector3f(base.x() + xxx, base.y() + yyy + 1, base.z() + zzz + 1);
|
||||
final Vector3f v4 = new Vector3f(base.x() + xxx, base.y() + yyy + 1, base.z() + zzz);
|
||||
final Vector2f t1 = new Vector2f(0, 0);
|
||||
final Vector2f t2 = new Vector2f(0, 1);
|
||||
final Vector2f t3 = new Vector2f(1, 1);
|
||||
final Vector2f t4 = new Vector2f(1, 0);
|
||||
final Vector3f n1 = new Vector3f(1, 0, 0);
|
||||
if (type == VoxelType.NATIVE_UNBREAKABLE) {
|
||||
this.unbreakable.addQuad(v1, v4, v3, v2, t1, t4, t3, t2, n1);
|
||||
} else if (type == VoxelType.NATIVE_DIRT) {
|
||||
@ -111,18 +117,18 @@ public class ComponentDynamicMeshsVoxelMap extends ComponentDynamicMeshs {
|
||||
this.grass.addQuad(v1, v4, v3, v2, t1, t4, t3, t2, n1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void drawPlaneVerticalY(final Vector3i base, final int xxx, final int yyy, final int zzz, final int type) {
|
||||
//LOGGER.warn("Add plane Y : {}, {}, {}", (base.x + xxx), (base.y + yyy), (base.z + zzz));
|
||||
Vector3f v1 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz);
|
||||
Vector3f v2 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz + 1);
|
||||
Vector3f v3 = new Vector3f(base.x() + xxx + 1, base.y() + yyy, base.z() + zzz + 1);
|
||||
Vector3f v4 = new Vector3f(base.x() + xxx + 1, base.y() + yyy, base.z() + zzz);
|
||||
Vector2f t1 = new Vector2f(0, 0);
|
||||
Vector2f t2 = new Vector2f(0, 1);
|
||||
Vector2f t3 = new Vector2f(1, 1);
|
||||
Vector2f t4 = new Vector2f(1, 0);
|
||||
Vector3f n1 = new Vector3f(0, 1, 0);
|
||||
final Vector3f v1 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz);
|
||||
final Vector3f v2 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz + 1);
|
||||
final Vector3f v3 = new Vector3f(base.x() + xxx + 1, base.y() + yyy, base.z() + zzz + 1);
|
||||
final Vector3f v4 = new Vector3f(base.x() + xxx + 1, base.y() + yyy, base.z() + zzz);
|
||||
final Vector2f t1 = new Vector2f(0, 0);
|
||||
final Vector2f t2 = new Vector2f(0, 1);
|
||||
final Vector2f t3 = new Vector2f(1, 1);
|
||||
final Vector2f t4 = new Vector2f(1, 0);
|
||||
final Vector3f n1 = new Vector3f(0, 1, 0);
|
||||
if (type == VoxelType.NATIVE_UNBREAKABLE) {
|
||||
this.unbreakable.addQuad(v1, v2, v3, v4, t1, t2, t3, t4, n1);
|
||||
} else if (type == VoxelType.NATIVE_DIRT) {
|
||||
@ -133,18 +139,23 @@ public class ComponentDynamicMeshsVoxelMap extends ComponentDynamicMeshs {
|
||||
this.grass.addQuad(v1, v2, v3, v4, t1, t2, t3, t4, n1);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawPlaneVerticalY_anti(final Vector3i base, final int xxx, final int yyy, final int zzz, final int type) {
|
||||
|
||||
private void drawPlaneVerticalY_anti(
|
||||
final Vector3i base,
|
||||
final int xxx,
|
||||
final int yyy,
|
||||
final int zzz,
|
||||
final int type) {
|
||||
//LOGGER.warn("Add plane Y : {}, {}, {}", (base.x + xxx), (base.y + yyy), (base.z + zzz));
|
||||
Vector3f v1 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz);
|
||||
Vector3f v2 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz + 1);
|
||||
Vector3f v3 = new Vector3f(base.x() + xxx + 1, base.y() + yyy, base.z() + zzz + 1);
|
||||
Vector3f v4 = new Vector3f(base.x() + xxx + 1, base.y() + yyy, base.z() + zzz);
|
||||
Vector2f t1 = new Vector2f(0, 0);
|
||||
Vector2f t2 = new Vector2f(0, 1);
|
||||
Vector2f t3 = new Vector2f(1, 1);
|
||||
Vector2f t4 = new Vector2f(1, 0);
|
||||
Vector3f n1 = new Vector3f(0, -1, 0);
|
||||
final Vector3f v1 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz);
|
||||
final Vector3f v2 = new Vector3f(base.x() + xxx, base.y() + yyy, base.z() + zzz + 1);
|
||||
final Vector3f v3 = new Vector3f(base.x() + xxx + 1, base.y() + yyy, base.z() + zzz + 1);
|
||||
final Vector3f v4 = new Vector3f(base.x() + xxx + 1, base.y() + yyy, base.z() + zzz);
|
||||
final Vector2f t1 = new Vector2f(0, 0);
|
||||
final Vector2f t2 = new Vector2f(0, 1);
|
||||
final Vector2f t3 = new Vector2f(1, 1);
|
||||
final Vector2f t4 = new Vector2f(1, 0);
|
||||
final Vector3f n1 = new Vector3f(0, -1, 0);
|
||||
if (type == VoxelType.NATIVE_UNBREAKABLE) {
|
||||
this.unbreakable.addQuad(v1, v4, v3, v2, t1, t4, t3, t2, n1);
|
||||
} else if (type == VoxelType.NATIVE_DIRT) {
|
||||
@ -155,21 +166,21 @@ public class ComponentDynamicMeshsVoxelMap extends ComponentDynamicMeshs {
|
||||
this.grass.addQuad(v1, v4, v3, v2, t1, t4, t3, t2, n1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render(final String name) {
|
||||
//LOGGER.warn("Render : {}", name);
|
||||
super.render(name);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(final float timeStep) {
|
||||
LOGGER.warn("update : {}", timeStep);
|
||||
if (this.chunk.haveChange() == false) {
|
||||
if (!this.chunk.haveChange()) {
|
||||
return;
|
||||
}
|
||||
LOGGER.warn(" ==> YES");
|
||||
Voxel[][][] data = this.chunk.getData();
|
||||
final Voxel[][][] data = this.chunk.getData();
|
||||
this.unbreakable.clear();
|
||||
this.stone.clear();
|
||||
this.dirt.clear();
|
||||
@ -177,32 +188,32 @@ public class ComponentDynamicMeshsVoxelMap extends ComponentDynamicMeshs {
|
||||
for (int xxx = 0; xxx < VoxelChunk.VOXEL_CHUNK_SIZE; xxx++) {
|
||||
for (int yyy = 0; yyy < VoxelChunk.VOXEL_CHUNK_SIZE; yyy++) {
|
||||
for (int zzz = 0; zzz < VoxelChunk.VOXEL_CHUNK_SIZE; zzz++) {
|
||||
Voxel current = data[xxx][yyy][zzz];
|
||||
if (current.active == false) {
|
||||
final Voxel current = data[xxx][yyy][zzz];
|
||||
if (!current.active) {
|
||||
continue;
|
||||
}
|
||||
Voxel bottom = this.chunk.getVoxel(xxx, yyy, zzz - 1);
|
||||
if (bottom == null || bottom.active == false) {
|
||||
final Voxel bottom = this.chunk.getVoxel(xxx, yyy, zzz - 1);
|
||||
if (bottom == null || !bottom.active) {
|
||||
drawPlane(this.chunk.getPosition(), xxx, yyy, zzz, current.type);
|
||||
}
|
||||
Voxel up = this.chunk.getVoxel(xxx, yyy, zzz + 1);
|
||||
if (up == null || up.active == false) {
|
||||
final Voxel up = this.chunk.getVoxel(xxx, yyy, zzz + 1);
|
||||
if (up == null || !up.active) {
|
||||
drawPlane_anti(this.chunk.getPosition(), xxx, yyy, zzz + 1, current.type);
|
||||
}
|
||||
Voxel left = this.chunk.getVoxel(xxx - 1, yyy, zzz);
|
||||
if (left == null || left.active == false) {
|
||||
final Voxel left = this.chunk.getVoxel(xxx - 1, yyy, zzz);
|
||||
if (left == null || !left.active) {
|
||||
drawPlaneVerticalX(this.chunk.getPosition(), xxx, yyy, zzz, current.type);
|
||||
}
|
||||
Voxel right = this.chunk.getVoxel(xxx + 1, yyy, zzz);
|
||||
if (right == null || right.active == false) {
|
||||
final Voxel right = this.chunk.getVoxel(xxx + 1, yyy, zzz);
|
||||
if (right == null || !right.active) {
|
||||
drawPlaneVerticalX_anti(this.chunk.getPosition(), xxx + 1, yyy, zzz, current.type);
|
||||
}
|
||||
Voxel front = this.chunk.getVoxel(xxx, yyy - 1, zzz);
|
||||
if (front == null || front.active == false) {
|
||||
final Voxel front = this.chunk.getVoxel(xxx, yyy - 1, zzz);
|
||||
if (front == null || !front.active) {
|
||||
drawPlaneVerticalY_anti(this.chunk.getPosition(), xxx, yyy, zzz, current.type);
|
||||
}
|
||||
Voxel back = this.chunk.getVoxel(xxx, yyy + 1, zzz);
|
||||
if (back == null || back.active == false) {
|
||||
final Voxel back = this.chunk.getVoxel(xxx, yyy + 1, zzz);
|
||||
if (back == null || !back.active) {
|
||||
drawPlaneVerticalY(this.chunk.getPosition(), xxx, yyy + 1, zzz, current.type);
|
||||
}
|
||||
}
|
||||
@ -213,5 +224,5 @@ public class ComponentDynamicMeshsVoxelMap extends ComponentDynamicMeshs {
|
||||
this.dirt.flush();
|
||||
this.grass.flush();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,68 +0,0 @@
|
||||
package org.atriasoft.garoux.internal;
|
||||
|
||||
import org.atriasoft.reggol.LogLevel;
|
||||
import org.atriasoft.reggol.Logger;
|
||||
|
||||
public class Log {
|
||||
private static final String LIB_NAME = "garoux";
|
||||
private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME);
|
||||
private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(LIB_NAME, LogLevel.CRITICAL);
|
||||
private static final boolean PRINT_ERROR = Logger.getNeedPrint(LIB_NAME, LogLevel.ERROR);
|
||||
private static final boolean PRINT_WARNING = Logger.getNeedPrint(LIB_NAME, LogLevel.WARNING);
|
||||
private static final boolean PRINT_INFO = Logger.getNeedPrint(LIB_NAME, LogLevel.INFO);
|
||||
private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG);
|
||||
private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(LIB_NAME, LogLevel.VERBOSE);
|
||||
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
|
||||
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
|
||||
|
||||
public static void critical(final String data) {
|
||||
if (PRINT_CRITICAL) {
|
||||
Logger.critical(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void debug(final String data) {
|
||||
if (PRINT_DEBUG) {
|
||||
Logger.debug(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void error(final String data) {
|
||||
if (PRINT_ERROR) {
|
||||
Logger.error(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void info(final String data) {
|
||||
if (PRINT_INFO) {
|
||||
Logger.info(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void print(final String data) {
|
||||
if (PRINT_PRINT) {
|
||||
Logger.print(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void todo(final String data) {
|
||||
if (PRINT_TODO) {
|
||||
Logger.todo(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verbose(final String data) {
|
||||
if (PRINT_VERBOSE) {
|
||||
Logger.verbose(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void warning(final String data) {
|
||||
if (PRINT_WARNING) {
|
||||
Logger.warning(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
private Log() {}
|
||||
|
||||
}
|
@ -8,34 +8,38 @@ import org.atriasoft.etk.math.Matrix4f;
|
||||
import org.atriasoft.etk.math.Transform3D;
|
||||
import org.atriasoft.etk.math.Vector3f;
|
||||
import org.atriasoft.gale.resource.ResourceColored3DObject;
|
||||
import org.atriasoft.phyligram.internal.Log;
|
||||
import org.atriasoft.phyligram.shape.AABB;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class PhysicBox extends PhysicShape {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(PhysicBox.class);
|
||||
// Box size property in X, Y and Z
|
||||
private Vector3f size = new Vector3f(1, 1, 1);
|
||||
|
||||
|
||||
// only needed for the narrow phase calculation ...
|
||||
public Vector3f narrowPhaseGlobalPos;
|
||||
|
||||
|
||||
public Vector3f narrowPhaseAxisX = new Vector3f(1, 0, 0);
|
||||
|
||||
|
||||
public Vector3f narrowPhaseAxisY = new Vector3f(1, 0, 0);
|
||||
|
||||
|
||||
public Vector3f narrowPhaseAxisZ = new Vector3f(1, 0, 0);
|
||||
|
||||
|
||||
public Vector3f narrowPhaseHalfSize;
|
||||
|
||||
|
||||
public PhysicBox() {}
|
||||
|
||||
|
||||
public Vector3f getSize() {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void renderDebug(Transform3D transformGlobal, ResourceColored3DObject debugDrawProperty) {
|
||||
debugDrawProperty.drawSquare(this.size.multiply(0.5f), this.transform.getOpenGLMatrix().multiply(transformGlobal.getOpenGLMatrix()), new Color(0, 1, 0, 0.25f));
|
||||
Vector3f dimention = this.size.multiply(0.5f);
|
||||
public void renderDebug(final Transform3D transformGlobal, final ResourceColored3DObject debugDrawProperty) {
|
||||
debugDrawProperty.drawSquare(this.size.multiply(0.5f),
|
||||
this.transform.getOpenGLMatrix().multiply(transformGlobal.getOpenGLMatrix()),
|
||||
new Color(0, 1, 0, 0.25f));
|
||||
final Vector3f dimention = this.size.multiply(0.5f);
|
||||
renderPoint2(new Vector3f(+dimention.x(), +dimention.y(), +dimention.z()), transformGlobal, debugDrawProperty);
|
||||
renderPoint(new Vector3f(-dimention.x(), +dimention.y(), +dimention.z()), transformGlobal, debugDrawProperty);
|
||||
renderPoint(new Vector3f(+dimention.x(), -dimention.y(), +dimention.z()), transformGlobal, debugDrawProperty);
|
||||
@ -44,72 +48,100 @@ public class PhysicBox extends PhysicShape {
|
||||
renderPoint(new Vector3f(-dimention.x(), +dimention.y(), -dimention.z()), transformGlobal, debugDrawProperty);
|
||||
renderPoint(new Vector3f(+dimention.x(), -dimention.y(), -dimention.z()), transformGlobal, debugDrawProperty);
|
||||
renderPoint3(new Vector3f(-dimention.x(), -dimention.y(), -dimention.z()), transformGlobal, debugDrawProperty);
|
||||
for (Collision elem : this.colisionPoints) {
|
||||
for (final Collision elem : this.colisionPoints) {
|
||||
if (elem != null) {
|
||||
if (elem.colisionPointLocal == null) {
|
||||
LOGGER.error("colision point must be set !!!");
|
||||
continue;
|
||||
}
|
||||
for (int iii = 0; iii < elem.colisionPointLocal.length; iii++) {
|
||||
renderPoint4(elem.colisionPointLocal[iii].position, elem.colisionPointLocal[iii].force, debugDrawProperty);
|
||||
for (final ColisionPoint element : elem.colisionPointLocal) {
|
||||
renderPoint4(element.position, element.force, debugDrawProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void renderPoint(Vector3f subPosition, Transform3D transformGlobal, ResourceColored3DObject debugDrawProperty) {
|
||||
Matrix4f transformation = transformGlobal.getOpenGLMatrix().multiply(this.transform.getOpenGLMatrix()).multiply(Matrix4f.createMatrixTranslate(subPosition));
|
||||
|
||||
|
||||
private void renderPoint(
|
||||
final Vector3f subPosition,
|
||||
final Transform3D transformGlobal,
|
||||
final ResourceColored3DObject debugDrawProperty) {
|
||||
final Matrix4f transformation = transformGlobal.getOpenGLMatrix().multiply(this.transform.getOpenGLMatrix())
|
||||
.multiply(Matrix4f.createMatrixTranslate(subPosition));
|
||||
|
||||
debugDrawProperty.drawSquare(new Vector3f(0.08f, 0.08f, 0.08f), transformation, new Color(0, 0, 1, 1));
|
||||
}
|
||||
|
||||
private void renderPoint2(Vector3f subPosition, Transform3D transformGlobal, ResourceColored3DObject debugDrawProperty) {
|
||||
Matrix4f transformation = transformGlobal.getOpenGLMatrix().multiply(this.transform.getOpenGLMatrix()).multiply(Matrix4f.createMatrixTranslate(subPosition));
|
||||
|
||||
private void renderPoint2(
|
||||
final Vector3f subPosition,
|
||||
final Transform3D transformGlobal,
|
||||
final ResourceColored3DObject debugDrawProperty) {
|
||||
final Matrix4f transformation = transformGlobal.getOpenGLMatrix().multiply(this.transform.getOpenGLMatrix())
|
||||
.multiply(Matrix4f.createMatrixTranslate(subPosition));
|
||||
debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), transformation, new Color(0, 1, 0, 1));
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void renderPoint3(Vector3f subPosition, Transform3D transformGlobal, ResourceColored3DObject debugDrawProperty) {
|
||||
Matrix4f transformation = transformGlobal.getOpenGLMatrix().multiply(this.transform.getOpenGLMatrix()).multiply(Matrix4f.createMatrixTranslate(subPosition));
|
||||
|
||||
private void renderPoint3(
|
||||
final Vector3f subPosition,
|
||||
final Transform3D transformGlobal,
|
||||
final ResourceColored3DObject debugDrawProperty) {
|
||||
final Matrix4f transformation = transformGlobal.getOpenGLMatrix().multiply(this.transform.getOpenGLMatrix())
|
||||
.multiply(Matrix4f.createMatrixTranslate(subPosition));
|
||||
debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), transformation, new Color(1, 1, 0, 1));
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void renderPoint4(Vector3f subPosition, Vector3f force, ResourceColored3DObject debugDrawProperty) {
|
||||
debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f), Matrix4f.createMatrixTranslate(subPosition), new Color(1, 0, 0, 1));
|
||||
List<Vector3f> tmp = new ArrayList<>();
|
||||
|
||||
private void renderPoint4(
|
||||
final Vector3f subPosition,
|
||||
final Vector3f force,
|
||||
final ResourceColored3DObject debugDrawProperty) {
|
||||
debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f), Matrix4f.createMatrixTranslate(subPosition),
|
||||
new Color(1, 0, 0, 1));
|
||||
final List<Vector3f> tmp = new ArrayList<>();
|
||||
tmp.add(new Vector3f(0, 0, 0));
|
||||
tmp.add(force);
|
||||
debugDrawProperty.drawLine(tmp, new Color(1, 0, 0, 1), Matrix4f.createMatrixTranslate(subPosition), true, false);
|
||||
debugDrawProperty.drawLine(tmp, new Color(1, 0, 0, 1), Matrix4f.createMatrixTranslate(subPosition), true,
|
||||
false);
|
||||
}
|
||||
|
||||
public void setSize(Vector3f size) {
|
||||
|
||||
public void setSize(final Vector3f size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateAABB(Transform3D transformGlobal, AABB aabb) {
|
||||
public void updateAABB(final Transform3D transformGlobal, final AABB aabb) {
|
||||
// store it, many time usefull...
|
||||
this.transformGlobal = transformGlobal;
|
||||
this.colisionPoints.clear();
|
||||
// TODO Auto-generated method stub
|
||||
aabb.update(transformGlobal.multiply(this.transform.multiply(new Vector3f(this.size.x() * 0.5f, this.size.y() * 0.5f, this.size.z() * 0.5f))));
|
||||
aabb.update(transformGlobal.multiply(this.transform.multiply(new Vector3f(-this.size.x() * 0.5f, this.size.y() * 0.5f, this.size.z() * 0.5f))));
|
||||
aabb.update(transformGlobal.multiply(this.transform.multiply(new Vector3f(-this.size.x() * 0.5f, -this.size.y() * 0.5f, this.size.z() * 0.5f))));
|
||||
aabb.update(transformGlobal.multiply(this.transform.multiply(new Vector3f(this.size.x() * 0.5f, -this.size.y() * 0.5f, this.size.z() * 0.5f))));
|
||||
aabb.update(transformGlobal.multiply(this.transform.multiply(new Vector3f(this.size.x() * 0.5f, this.size.y() * 0.5f, -this.size.z() * 0.5f))));
|
||||
aabb.update(transformGlobal.multiply(this.transform.multiply(new Vector3f(-this.size.x() * 0.5f, this.size.y() * 0.5f, -this.size.z() * 0.5f))));
|
||||
aabb.update(transformGlobal.multiply(this.transform.multiply(new Vector3f(-this.size.x() * 0.5f, -this.size.y() * 0.5f, -this.size.z() * 0.5f))));
|
||||
aabb.update(transformGlobal.multiply(this.transform.multiply(new Vector3f(this.size.x() * 0.5f, -this.size.y() * 0.5f, -this.size.z() * 0.5f))));
|
||||
aabb.update(transformGlobal.multiply(this.transform
|
||||
.multiply(new Vector3f(this.size.x() * 0.5f, this.size.y() * 0.5f, this.size.z() * 0.5f))));
|
||||
aabb.update(transformGlobal.multiply(this.transform
|
||||
.multiply(new Vector3f(-this.size.x() * 0.5f, this.size.y() * 0.5f, this.size.z() * 0.5f))));
|
||||
aabb.update(transformGlobal.multiply(this.transform
|
||||
.multiply(new Vector3f(-this.size.x() * 0.5f, -this.size.y() * 0.5f, this.size.z() * 0.5f))));
|
||||
aabb.update(transformGlobal.multiply(this.transform
|
||||
.multiply(new Vector3f(this.size.x() * 0.5f, -this.size.y() * 0.5f, this.size.z() * 0.5f))));
|
||||
aabb.update(transformGlobal.multiply(this.transform
|
||||
.multiply(new Vector3f(this.size.x() * 0.5f, this.size.y() * 0.5f, -this.size.z() * 0.5f))));
|
||||
aabb.update(transformGlobal.multiply(this.transform
|
||||
.multiply(new Vector3f(-this.size.x() * 0.5f, this.size.y() * 0.5f, -this.size.z() * 0.5f))));
|
||||
aabb.update(transformGlobal.multiply(this.transform
|
||||
.multiply(new Vector3f(-this.size.x() * 0.5f, -this.size.y() * 0.5f, -this.size.z() * 0.5f))));
|
||||
aabb.update(transformGlobal.multiply(this.transform
|
||||
.multiply(new Vector3f(this.size.x() * 0.5f, -this.size.y() * 0.5f, -this.size.z() * 0.5f))));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateForNarrowCollision(Transform3D transformGlobal) {
|
||||
public void updateForNarrowCollision(final Transform3D transformGlobal) {
|
||||
this.narrowPhaseGlobalPos = transformGlobal.multiply(this.transform.multiply(new Vector3f(0, 0, 0)));
|
||||
this.narrowPhaseAxisX = transformGlobal.multiply(this.transform.multiply(new Vector3f(1, 0, 0))).less(this.narrowPhaseGlobalPos);
|
||||
this.narrowPhaseAxisY = transformGlobal.multiply(this.transform.multiply(new Vector3f(0, 1, 0))).less(this.narrowPhaseGlobalPos);
|
||||
this.narrowPhaseAxisZ = transformGlobal.multiply(this.transform.multiply(new Vector3f(0, 0, 1))).less(this.narrowPhaseGlobalPos);
|
||||
this.narrowPhaseAxisX = transformGlobal.multiply(this.transform.multiply(new Vector3f(1, 0, 0)))
|
||||
.less(this.narrowPhaseGlobalPos);
|
||||
this.narrowPhaseAxisY = transformGlobal.multiply(this.transform.multiply(new Vector3f(0, 1, 0)))
|
||||
.less(this.narrowPhaseGlobalPos);
|
||||
this.narrowPhaseAxisZ = transformGlobal.multiply(this.transform.multiply(new Vector3f(0, 0, 1)))
|
||||
.less(this.narrowPhaseGlobalPos);
|
||||
this.narrowPhaseHalfSize = this.size.multiply(0.5f);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,68 +0,0 @@
|
||||
package org.atriasoft.phyligram.internal;
|
||||
|
||||
import org.atriasoft.reggol.LogLevel;
|
||||
import org.atriasoft.reggol.Logger;
|
||||
|
||||
public class Log {
|
||||
private static final String LIB_NAME = "phyligram";
|
||||
private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME);
|
||||
private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(LIB_NAME, LogLevel.CRITICAL);
|
||||
private static final boolean PRINT_ERROR = Logger.getNeedPrint(LIB_NAME, LogLevel.ERROR);
|
||||
private static final boolean PRINT_WARNING = Logger.getNeedPrint(LIB_NAME, LogLevel.WARNING);
|
||||
private static final boolean PRINT_INFO = Logger.getNeedPrint(LIB_NAME, LogLevel.INFO);
|
||||
private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG);
|
||||
private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(LIB_NAME, LogLevel.VERBOSE);
|
||||
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
|
||||
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
|
||||
|
||||
public static void critical(final String data) {
|
||||
if (PRINT_CRITICAL) {
|
||||
Logger.critical(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void debug(final String data) {
|
||||
if (PRINT_DEBUG) {
|
||||
Logger.debug(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void error(final String data) {
|
||||
if (PRINT_ERROR) {
|
||||
Logger.error(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void info(final String data) {
|
||||
if (PRINT_INFO) {
|
||||
Logger.info(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void print(final String data) {
|
||||
if (PRINT_PRINT) {
|
||||
Logger.print(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void todo(final String data) {
|
||||
if (PRINT_TODO) {
|
||||
Logger.todo(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verbose(final String data) {
|
||||
if (PRINT_VERBOSE) {
|
||||
Logger.verbose(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void warning(final String data) {
|
||||
if (PRINT_WARNING) {
|
||||
Logger.warning(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
||||
|
||||
private Log() {}
|
||||
|
||||
}
|
@ -3,18 +3,21 @@ package org.atriasoft.phyligram.math;
|
||||
import org.atriasoft.etk.math.Vector3f;
|
||||
import org.atriasoft.phyligram.ColisionPoint;
|
||||
import org.atriasoft.phyligram.PhysicSphere;
|
||||
import org.atriasoft.phyligram.internal.Log;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ToolCollisionSphereWithSphere {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(ToolCollisionSphereWithSphere.class);
|
||||
|
||||
// Note sphere 2 is the reference ...
|
||||
public static ColisionPoint getCollisionPoint(PhysicSphere sphere1, PhysicSphere shapeReference) {
|
||||
public static ColisionPoint getCollisionPoint(final PhysicSphere sphere1, final PhysicSphere shapeReference) {
|
||||
if (sphere1.getSize() > shapeReference.getSize()) {
|
||||
LOGGER.info("[TODO] implement then reference is smaller than moving");
|
||||
}
|
||||
Vector3f force = sphere1.narrowPhaseGlobalPos.less(shapeReference.narrowPhaseGlobalPos);
|
||||
float distance = shapeReference.getSize() + sphere1.getSize() - force.length();
|
||||
final float distance = shapeReference.getSize() + sphere1.getSize() - force.length();
|
||||
force = force.safeNormalize();
|
||||
Vector3f impact = force.multiply(shapeReference.getSize());
|
||||
final Vector3f impact = force.multiply(shapeReference.getSize());
|
||||
force = force.multiply(distance);
|
||||
force = force.multiply(sphere1.getSize() + distance);
|
||||
// set relative impact position:
|
||||
@ -22,14 +25,14 @@ public class ToolCollisionSphereWithSphere {
|
||||
// set global position
|
||||
return new ColisionPoint(shapeReference.narrowPhaseGlobalPos.add(impact), force);
|
||||
}
|
||||
|
||||
|
||||
// Note sphere 2 is the reference ...
|
||||
public static boolean testCollide(PhysicSphere sphere1, PhysicSphere shapeReference) {
|
||||
float distance1 = sphere1.narrowPhaseGlobalPos.distance2(shapeReference.narrowPhaseGlobalPos);
|
||||
public static boolean testCollide(final PhysicSphere sphere1, final PhysicSphere shapeReference) {
|
||||
final float distance1 = sphere1.narrowPhaseGlobalPos.distance2(shapeReference.narrowPhaseGlobalPos);
|
||||
float distance2 = sphere1.getSize() + shapeReference.getSize();
|
||||
distance2 = distance2 * distance2;
|
||||
return distance1 <= distance2;
|
||||
}
|
||||
|
||||
|
||||
private ToolCollisionSphereWithSphere() {}
|
||||
}
|
||||
|
@ -9,13 +9,15 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.atriasoft.etk.math.Vector3f;
|
||||
import org.atriasoft.ege.internal.Log;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Concave extends Shape {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(Concave.class);
|
||||
private List<Vector3f> vertexes = new ArrayList<>();
|
||||
|
||||
|
||||
private final List<Integer> indices = new ArrayList<>();
|
||||
|
||||
|
||||
public void addTriangle(final List<Integer> index) {
|
||||
/*
|
||||
if (m_indices.size() == 0) {
|
||||
@ -27,24 +29,22 @@ public class Concave extends Shape {
|
||||
LOGGER.error("wrong number of faces : {} ==> not a multiple of 3", index.size());
|
||||
return;
|
||||
}
|
||||
for (final Integer it : index) {
|
||||
this.indices.add(it);
|
||||
}
|
||||
this.indices.addAll(index);
|
||||
}
|
||||
|
||||
|
||||
public void clear() {
|
||||
this.vertexes.clear();
|
||||
this.indices.clear();
|
||||
}
|
||||
|
||||
|
||||
public List<Integer> getIndices() {
|
||||
return this.indices;
|
||||
}
|
||||
|
||||
|
||||
public List<Vector3f> getVertex() {
|
||||
return this.vertexes;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean parse(final String _line) {
|
||||
/*
|
||||
@ -55,7 +55,7 @@ public class Concave extends Shape {
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void setListOfVertex(final List<Vector3f> vertexes) {
|
||||
this.vertexes = vertexes;
|
||||
}
|
||||
|
@ -5,31 +5,33 @@
|
||||
*/
|
||||
package org.atriasoft.phyligram.shape;
|
||||
|
||||
import org.atriasoft.ege.internal.Log;
|
||||
import org.atriasoft.etk.math.Quaternion;
|
||||
import org.atriasoft.etk.math.Vector3f;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Shape {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(Shape.class);
|
||||
private Quaternion orientation = Quaternion.IDENTITY;
|
||||
private float mass = 1; //!< element mass in "g" then 1000 for 1kg
|
||||
private Vector3f origin = Vector3f.ZERO;
|
||||
|
||||
|
||||
public void display() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public float getMass() {
|
||||
return this.mass;
|
||||
}
|
||||
|
||||
|
||||
public Quaternion getOrientation() {
|
||||
return this.orientation;
|
||||
}
|
||||
|
||||
|
||||
public Vector3f getOrigin() {
|
||||
return this.origin;
|
||||
}
|
||||
|
||||
|
||||
public boolean parse(final String _line) {
|
||||
LOGGER.error("dfgdfg");
|
||||
/*
|
||||
@ -51,15 +53,15 @@ public class Shape {
|
||||
*/
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
public void setMass(final float mass) {
|
||||
this.mass = mass;
|
||||
};
|
||||
|
||||
|
||||
public void setOrientation(final Quaternion orientation) {
|
||||
this.orientation = orientation;
|
||||
};
|
||||
|
||||
|
||||
public void setOrigin(final Vector3f origin) {
|
||||
this.origin = origin;
|
||||
};
|
||||
|
@ -3,11 +3,12 @@ package org.atriasoft.phyligram.tree;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.atriasoft.phyligram.shape.AABB;
|
||||
import org.atriasoft.phyligram.internal.Log;
|
||||
import org.atriasoft.phyligram.math.Ray;
|
||||
import org.atriasoft.etk.math.FMath;
|
||||
import org.atriasoft.etk.math.Vector3f;
|
||||
import org.atriasoft.phyligram.math.Ray;
|
||||
import org.atriasoft.phyligram.shape.AABB;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* It implements a dynamic AABB tree that is used for broad-phase
|
||||
@ -17,20 +18,21 @@ import org.atriasoft.etk.math.Vector3f;
|
||||
* "Introduction to Game Physics with Box2D" by Ian Parberry.
|
||||
*/
|
||||
public class DynamicAABBTree<INTERNAL_DATA_TYPE> {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(DynamicAABBTree.class);
|
||||
private DTree rootNode; //!< Pointer to the memory location of the nodes of the tree
|
||||
|
||||
|
||||
/// Constructor
|
||||
public DynamicAABBTree() {
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
/// Add an object into the tree (where node data is a pointer)
|
||||
public DTree addObject(final AABB aabb, final INTERNAL_DATA_TYPE data) {
|
||||
final DTreeLeafData<INTERNAL_DATA_TYPE> node = new DTreeLeafData<INTERNAL_DATA_TYPE>(data);
|
||||
final DTreeLeafData<INTERNAL_DATA_TYPE> node = new DTreeLeafData<>(data);
|
||||
addObjectInternal(aabb, node);
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
/// Internally add an object into the tree
|
||||
private void addObjectInternal(final AABB aabb, final DTree leafNode) {
|
||||
// Create the fat aabb to use in the tree
|
||||
@ -41,7 +43,7 @@ public class DynamicAABBTree<INTERNAL_DATA_TYPE> {
|
||||
insertLeafNode(leafNode);
|
||||
assert (leafNode.isLeaf());
|
||||
}
|
||||
|
||||
|
||||
/// Balance the sub-tree of a given node using left or right rotations.
|
||||
private DTree balanceSubTreeAtNode(final DTree node) {
|
||||
assert (node != null);
|
||||
@ -163,12 +165,12 @@ public class DynamicAABBTree<INTERNAL_DATA_TYPE> {
|
||||
// If the sub-tree is balanced, return the current root node
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
/// Compute the height of the tree
|
||||
public int computeHeight() {
|
||||
return computeHeight(this.rootNode);
|
||||
}
|
||||
|
||||
|
||||
/// Compute the height of a given node in the tree
|
||||
private int computeHeight(final DTree node) {
|
||||
// If the node is a leaf, its height is zero
|
||||
@ -176,45 +178,45 @@ public class DynamicAABBTree<INTERNAL_DATA_TYPE> {
|
||||
return 0;
|
||||
}
|
||||
final DTreeNode nodeTree = (DTreeNode) node;
|
||||
|
||||
|
||||
// Compute the height of the left and right sub-tree
|
||||
final int leftHeight = computeHeight(nodeTree.childrenleft);
|
||||
final int rightHeight = computeHeight(nodeTree.childrenright);
|
||||
// Return the height of the node
|
||||
return 1 + Math.max(leftHeight, rightHeight);
|
||||
}
|
||||
|
||||
|
||||
/// Return the fat AABB corresponding to a given node ID
|
||||
public AABB getFatAABB(final DTree node) {
|
||||
return node.aabb;
|
||||
}
|
||||
|
||||
|
||||
public int getNodeDataInt0(final DTree node) {
|
||||
assert (node.isLeaf());
|
||||
return ((DTreeLeafInt) node).dataInt0;
|
||||
}
|
||||
|
||||
|
||||
public int getNodeDataInt1(final DTree node) {
|
||||
assert (node.isLeaf());
|
||||
return ((DTreeLeafInt) node).dataInt1;
|
||||
}
|
||||
|
||||
|
||||
/// Return the data pointer of a given leaf node of the tree
|
||||
public Object getNodeDataPointer(final DTree node) {
|
||||
assert (node.isLeaf());
|
||||
return ((DTreeLeafData) node).dataPointer;
|
||||
}
|
||||
|
||||
|
||||
/// Return the root AABB of the tree
|
||||
public AABB getRootAABB() {
|
||||
return getFatAABB(this.rootNode);
|
||||
}
|
||||
|
||||
|
||||
/// Initialize the tree
|
||||
private void init() {
|
||||
this.rootNode = null;
|
||||
}
|
||||
|
||||
|
||||
/// Insert a leaf node in the tree
|
||||
private void insertLeafNode(final DTree inNode) {
|
||||
// If the tree is empty
|
||||
@ -294,7 +296,7 @@ public class DynamicAABBTree<INTERNAL_DATA_TYPE> {
|
||||
newParentNode.childrenright = inNode;
|
||||
siblingNode.parent = new WeakReference<>(newParentNode);
|
||||
inNode.parent = new WeakReference<>(newParentNode);
|
||||
|
||||
|
||||
// Move up in the tree to change the AABBs that have changed
|
||||
currentNode = newParentNode;
|
||||
assert (!currentNode.isLeaf());
|
||||
@ -321,7 +323,7 @@ public class DynamicAABBTree<INTERNAL_DATA_TYPE> {
|
||||
}
|
||||
assert (inNode.isLeaf());
|
||||
}
|
||||
|
||||
|
||||
/// Ray casting method
|
||||
public void raycast(final Ray ray, final CallbackRaycast callback) {
|
||||
if (callback == null) {
|
||||
@ -372,14 +374,14 @@ public class DynamicAABBTree<INTERNAL_DATA_TYPE> {
|
||||
stack.push(tmpNode.childrenright);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// Release a node
|
||||
private void releaseNode(final DTree node) {
|
||||
//this.numberNodes--;
|
||||
}
|
||||
|
||||
|
||||
/// Remove a leaf node from the tree
|
||||
private void removeLeafNode(final DTree node) {
|
||||
assert (node.isLeaf());
|
||||
@ -437,7 +439,7 @@ public class DynamicAABBTree<INTERNAL_DATA_TYPE> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Remove an object from the tree
|
||||
public void removeObject(final DTree node) {
|
||||
assert (node.isLeaf());
|
||||
@ -445,7 +447,7 @@ public class DynamicAABBTree<INTERNAL_DATA_TYPE> {
|
||||
removeLeafNode(node);
|
||||
releaseNode(node);
|
||||
}
|
||||
|
||||
|
||||
/// Report all shapes overlapping with the AABB given in parameter.
|
||||
public void reportAllShapesOverlappingWithAABB(final AABB aabb, final CallbackOverlapping callback) {
|
||||
if (callback == null) {
|
||||
@ -492,13 +494,13 @@ public class DynamicAABBTree<INTERNAL_DATA_TYPE> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Clear all the nodes and reset the tree
|
||||
public void reset() {
|
||||
// Initialize the tree
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
/// Update the dynamic tree after an object has moved.
|
||||
/// If the new AABB of the object that has moved is still inside its fat AABB, then
|
||||
/// nothing is done. Otherwise, the corresponding node is removed and reinserted into the tree.
|
||||
@ -509,8 +511,12 @@ public class DynamicAABBTree<INTERNAL_DATA_TYPE> {
|
||||
public boolean updateObject(final DTree node, final AABB newAABB, final Vector3f displacement) {
|
||||
return updateObject(node, newAABB, displacement, false);
|
||||
}
|
||||
|
||||
public boolean updateObject(final DTree node, final AABB newAABB, final Vector3f displacement, final boolean forceReinsert) {
|
||||
|
||||
public boolean updateObject(
|
||||
final DTree node,
|
||||
final AABB newAABB,
|
||||
final Vector3f displacement,
|
||||
final boolean forceReinsert) {
|
||||
assert (node.isLeaf());
|
||||
assert (node.height >= 0);
|
||||
//LOGGER.trace(" compare : {} {}", node.aabb.getMin(), node.aabb.getMax());
|
||||
@ -556,5 +562,5 @@ public class DynamicAABBTree<INTERNAL_DATA_TYPE> {
|
||||
insertLeafNode(node);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,59 +0,0 @@
|
||||
package test.atriasoft.ege;
|
||||
|
||||
import org.atriasoft.reggol.LogLevel;
|
||||
import org.atriasoft.reggol.Logger;
|
||||
|
||||
public class Log {
|
||||
private static final String LIB_NAME = "ege-test";
|
||||
private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME);
|
||||
private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(LIB_NAME, LogLevel.CRITICAL);
|
||||
private static final boolean PRINT_ERROR = Logger.getNeedPrint(LIB_NAME, LogLevel.ERROR);
|
||||
private static final boolean PRINT_WARNING = Logger.getNeedPrint(LIB_NAME, LogLevel.WARNING);
|
||||
private static final boolean PRINT_INFO = Logger.getNeedPrint(LIB_NAME, LogLevel.INFO);
|
||||
private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG);
|
||||
private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(LIB_NAME, LogLevel.VERBOSE);
|
||||
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
|
||||
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
|
||||
|
||||
private Log() {}
|
||||
|
||||
public static void print(String data) {
|
||||
if (PRINT_PRINT)
|
||||
Logger.print(LIB_NAME_DRAW, data);
|
||||
}
|
||||
|
||||
public static void critical(String data) {
|
||||
if (PRINT_CRITICAL)
|
||||
Logger.critical(LIB_NAME_DRAW, data);
|
||||
}
|
||||
|
||||
public static void error(String data) {
|
||||
if (PRINT_ERROR)
|
||||
Logger.error(LIB_NAME_DRAW, data);
|
||||
}
|
||||
|
||||
public static void warning(String data) {
|
||||
if (PRINT_WARNING)
|
||||
Logger.warning(LIB_NAME_DRAW, data);
|
||||
}
|
||||
|
||||
public static void info(String data) {
|
||||
if (PRINT_INFO)
|
||||
Logger.info(LIB_NAME_DRAW, data);
|
||||
}
|
||||
|
||||
public static void debug(String data) {
|
||||
if (PRINT_DEBUG)
|
||||
Logger.debug(LIB_NAME_DRAW, data);
|
||||
}
|
||||
|
||||
public static void verbose(String data) {
|
||||
if (PRINT_VERBOSE)
|
||||
Logger.verbose(LIB_NAME_DRAW, data);
|
||||
}
|
||||
|
||||
public static void todo(String data) {
|
||||
if (PRINT_TODO)
|
||||
Logger.todo(LIB_NAME_DRAW, data);
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package test.atriasoft.ege;
|
||||
|
||||
import org.atriasoft.reggol.LogLevel;
|
||||
import org.atriasoft.reggol.Logger;
|
||||
|
||||
public class Log2 {
|
||||
private static final String LIB_NAME = "ege-test-2";
|
||||
private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME);
|
||||
private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG);
|
||||
|
||||
private Log2() {}
|
||||
|
||||
public static void debug(String data) {
|
||||
if (PRINT_DEBUG)
|
||||
Logger.debug(LIB_NAME_DRAW, data);
|
||||
}
|
||||
|
||||
}
|
@ -1,103 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* Contributors:
|
||||
* Revilloud Marc - initial API and implementation
|
||||
******************************************************************************/
|
||||
package test.atriasoft.ege;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.atriasoft.reggol.Logger;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||
import org.junit.jupiter.api.Order;
|
||||
//import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
@TestMethodOrder(OrderAnnotation.class)
|
||||
public class TestBasicLog {
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
public void aaFirstInitialisation() {
|
||||
List<String> args = new ArrayList<>();
|
||||
args.add("--log-level=999");
|
||||
args.add("--log-level=1");
|
||||
args.add("--log-no-color");
|
||||
args.add("--log-color");
|
||||
args.add("--log-lib=sc-log-test+6");
|
||||
args.add("--log-lib=sc-log-test/6");
|
||||
args.add("--log-lib=sc-log-test:6");
|
||||
args.add("--log-lib=sc-log-test:verbose");
|
||||
args.add("--log-lib=sc-log-test2+3");
|
||||
args.add("--log-lib=sc-log-test");
|
||||
args.add("--log-with-stupid-parameter=sdkfjsqdlkf");
|
||||
args.add("--help");
|
||||
Logger.init(args);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
public void bbSecondInitialisation() {
|
||||
List<String> args = new ArrayList<>();
|
||||
Logger.init(args);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
public void ccBasicLogCall() {
|
||||
LOGGER.print("Simple print");
|
||||
LOGGER.info("[TODO] Simple todo");
|
||||
LOGGER.error("Simple error");
|
||||
LOGGER.warn("Simple warning");
|
||||
LOGGER.info("Simple info");
|
||||
LOGGER.debug("Simple debug");
|
||||
LOGGER.trace("Simple verbose");
|
||||
}
|
||||
|
||||
// TODO REFACTO REMOVE this and set it in the Test of the logger.
|
||||
public static String getAAAAAAA(int dfsdf) {
|
||||
int hhh = 0;
|
||||
for (int kkk = 0; kkk < dfsdf; kkk++)
|
||||
for (int iii = 0; iii < 10000; iii++)
|
||||
for (int jjj = 0; jjj < 100000; jjj++)
|
||||
for (int lll = 0; lll < 100000; lll++)
|
||||
hhh++;
|
||||
return "kkk" + hhh;
|
||||
}
|
||||
|
||||
public static void testLog() {
|
||||
LOGGER.print("test direct [START]");
|
||||
// test de 10 secondes contre 0.0?? second quand le niveau n'est pas assez grand ...
|
||||
long timeStart = System.currentTimeMillis();
|
||||
for (int iii = 0; iii < 100000000; iii++)
|
||||
Log2.debug("test direct");
|
||||
long timeStop = System.currentTimeMillis();
|
||||
LOGGER.print("test direct [END]: {} to {} ==> delta={}", timeStart, timeStop, (timeStop - timeStart));
|
||||
LOGGER.print("test concat [START]");
|
||||
// C'est très long dans les 2 cas ...
|
||||
timeStart = System.currentTimeMillis();
|
||||
for (int iii = 0; iii < 6; iii++)
|
||||
Log2.debug("test concat: non fonctionnel, il applelle le get a chaque log ... " + getAAAAAAA(iii));
|
||||
timeStop = System.currentTimeMillis();
|
||||
LOGGER.print("test concat [END]: {} to {} ==> delta={}\", timeStart, timeStop, (timeStop - timeStart));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
public void ddTestSimpleLog() {
|
||||
testLog();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
public void eeUsage() {
|
||||
Logger.usage();
|
||||
}
|
||||
|
||||
}
|
@ -8,7 +8,7 @@ import org.atriasoft.ege.geometry.Sphere;
|
||||
import org.atriasoft.ege.geometry.Triangle;
|
||||
import org.atriasoft.etk.math.Matrix3f;
|
||||
import org.atriasoft.etk.math.Vector3f;
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TestTransformation3D {
|
||||
@ -16,25 +16,25 @@ public class TestTransformation3D {
|
||||
@Test
|
||||
void testPointInAABB() {
|
||||
final AABB shape = new AABB(new Vector3f(4, 4, 4), new Vector3f(1, 2, 3));
|
||||
Assert.assertFalse(Geometry3D.pointInAABB(new Vector3f(0, 0, 0), shape));
|
||||
Assert.assertFalse(Geometry3D.pointInAABB(new Vector3f(6, 6, 6), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInAABB(new Vector3f(3, 3, 3), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInAABB(new Vector3f(4, 4, 4), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInAABB(new Vector3f(4, 4, 1.0001f), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInAABB(new Vector3f(4, 2.0001f, 4), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInAABB(new Vector3f(3.0001f, 4, 4), shape));
|
||||
Assertions.assertFalse(Geometry3D.pointInAABB(new Vector3f(0, 0, 0), shape));
|
||||
Assertions.assertFalse(Geometry3D.pointInAABB(new Vector3f(6, 6, 6), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInAABB(new Vector3f(3, 3, 3), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInAABB(new Vector3f(4, 4, 4), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInAABB(new Vector3f(4, 4, 1.0001f), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInAABB(new Vector3f(4, 2.0001f, 4), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInAABB(new Vector3f(3.0001f, 4, 4), shape));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPointInLine() {
|
||||
final Sphere shape = new Sphere(new Vector3f(4, 4, 4), 2);
|
||||
Assert.assertFalse(Geometry3D.pointInSphere(new Vector3f(0, 0, 0), shape));
|
||||
Assert.assertFalse(Geometry3D.pointInSphere(new Vector3f(6, 6, 6), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInSphere(new Vector3f(3, 3, 3), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInSphere(new Vector3f(4, 4, 4), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInSphere(new Vector3f(4, 4, 2.0001f), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInSphere(new Vector3f(4, 2.0001f, 4), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInSphere(new Vector3f(2.0001f, 4, 4), shape));
|
||||
Assertions.assertFalse(Geometry3D.pointInSphere(new Vector3f(0, 0, 0), shape));
|
||||
Assertions.assertFalse(Geometry3D.pointInSphere(new Vector3f(6, 6, 6), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInSphere(new Vector3f(3, 3, 3), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInSphere(new Vector3f(4, 4, 4), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInSphere(new Vector3f(4, 4, 2.0001f), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInSphere(new Vector3f(4, 2.0001f, 4), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInSphere(new Vector3f(2.0001f, 4, 4), shape));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -42,25 +42,25 @@ public class TestTransformation3D {
|
||||
final Matrix3f orientation = Matrix3f.IDENTITY;
|
||||
orientation.multiply(Matrix3f.createMatrixRotate(new Vector3f(0, 0, 1), (float) Math.toRadians(45)));
|
||||
final OBB shape = new OBB(new Vector3f(4, 4, 4), new Vector3f(1, 2, 3), orientation);
|
||||
Assert.assertFalse(Geometry3D.pointInOBB(new Vector3f(0, 0, 0), shape));
|
||||
Assert.assertFalse(Geometry3D.pointInOBB(new Vector3f(6, 6, 6), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInOBB(new Vector3f(3, 3, 3), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInOBB(new Vector3f(4, 4, 4), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInOBB(new Vector3f(4, 4, 1.0001f), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInOBB(new Vector3f(4, 2.0001f, 4), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInOBB(new Vector3f(3.0001f, 4, 4), shape));
|
||||
Assertions.assertFalse(Geometry3D.pointInOBB(new Vector3f(0, 0, 0), shape));
|
||||
Assertions.assertFalse(Geometry3D.pointInOBB(new Vector3f(6, 6, 6), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInOBB(new Vector3f(3, 3, 3), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInOBB(new Vector3f(4, 4, 4), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInOBB(new Vector3f(4, 4, 1.0001f), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInOBB(new Vector3f(4, 2.0001f, 4), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInOBB(new Vector3f(3.0001f, 4, 4), shape));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPointInPlane() {
|
||||
final Plane____ shape = new Plane____((new Vector3f(4, 4, 4)).normalize(), (float) Math.sqrt(1 * 1 + 1 * 1));
|
||||
Assert.assertFalse(Geometry3D.pointInPlane(new Vector3f(0, 0, 0), shape));
|
||||
Assert.assertFalse(Geometry3D.pointInPlane(new Vector3f(6, 6, 6), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInPlane(new Vector3f(3, 3, 3), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInPlane(new Vector3f(4, 4, 4), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInPlane(new Vector3f(4, 4, 1.0001f), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInPlane(new Vector3f(4, 2.0001f, 4), shape));
|
||||
Assert.assertTrue(Geometry3D.pointInPlane(new Vector3f(3.0001f, 4, 4), shape));
|
||||
Assertions.assertFalse(Geometry3D.pointInPlane(new Vector3f(0, 0, 0), shape));
|
||||
Assertions.assertFalse(Geometry3D.pointInPlane(new Vector3f(6, 6, 6), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInPlane(new Vector3f(3, 3, 3), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInPlane(new Vector3f(4, 4, 4), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInPlane(new Vector3f(4, 4, 1.0001f), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInPlane(new Vector3f(4, 2.0001f, 4), shape));
|
||||
Assertions.assertTrue(Geometry3D.pointInPlane(new Vector3f(3.0001f, 4, 4), shape));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -71,7 +71,7 @@ public class TestTransformation3D {
|
||||
// assertTrue(Geometry3D.pointInTriangle(new Vector3f(0,0,1), shape));
|
||||
// assertFalse(Geometry3D.pointInTriangle(new Vector3f(5252,25252521,41458), shape));
|
||||
// assertFalse(Geometry3D.pointInTriangle(new Vector3f(1,1,1), shape));
|
||||
Assert.assertFalse(Geometry3D.pointInTriangle(new Vector3f(0.1f, 0.1f, 0.1f), shape));
|
||||
Assert.assertFalse(Geometry3D.pointInTriangle(new Vector3f(0, 0, 0), shape));
|
||||
Assertions.assertFalse(Geometry3D.pointInTriangle(new Vector3f(0.1f, 0.1f, 0.1f), shape));
|
||||
Assertions.assertFalse(Geometry3D.pointInTriangle(new Vector3f(0, 0, 0), shape));
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,10 @@ import org.atriasoft.etk.math.Transform3D;
|
||||
import org.atriasoft.etk.math.Vector3f;
|
||||
import org.atriasoft.phyligram.PhysicSphere;
|
||||
import org.atriasoft.phyligram.PhysicTriangle;
|
||||
import org.atriasoft.phyligram.ToolCollisionSphereWithTriangle;
|
||||
import org.atriasoft.phyligram.math.ToolCollisionSphereWithTriangle;
|
||||
import org.atriasoft.phyligram.shape.AABB;
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
public class TestCollisionSphereTriangle {
|
||||
|
||||
@ -39,39 +36,41 @@ public class TestCollisionSphereTriangle {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("generateData")
|
||||
void testsphereOut(int testId, Vector3f position, boolean resultTheoricValue) {
|
||||
void testsphereOut(final int testId, final Vector3f position, final boolean resultTheoricValue) {
|
||||
System.out.println("AAAAA ");
|
||||
float testCoefficient = 1.0f;
|
||||
PhysicSphere sphere = new PhysicSphere();
|
||||
final float testCoefficient = 1.0f;
|
||||
final PhysicSphere sphere = new PhysicSphere();
|
||||
sphere.setSize(testCoefficient);
|
||||
PhysicTriangle triangle = new PhysicTriangle();
|
||||
triangle.setPoints(new Vector3f(testCoefficient, testCoefficient, 0.0f), new Vector3f(testCoefficient, -testCoefficient, 0.0f), new Vector3f(-testCoefficient, 0.0f, 0.0f));
|
||||
Transform3D transformGlobalTriangle = Transform3D.IDENTITY;
|
||||
Transform3D transformGlobalsphere = new Transform3D(position.multiply(testCoefficient));
|
||||
AABB aabb = new AABB();
|
||||
final PhysicTriangle triangle = new PhysicTriangle();
|
||||
triangle.setPoints(new Vector3f(testCoefficient, testCoefficient, 0.0f),
|
||||
new Vector3f(testCoefficient, -testCoefficient, 0.0f), new Vector3f(-testCoefficient, 0.0f, 0.0f));
|
||||
final Transform3D transformGlobalTriangle = Transform3D.IDENTITY;
|
||||
final Transform3D transformGlobalsphere = new Transform3D(position.multiply(testCoefficient));
|
||||
final AABB aabb = new AABB();
|
||||
sphere.updateAABB(transformGlobalsphere, aabb);
|
||||
sphere.updateForNarrowCollision(transformGlobalsphere);
|
||||
triangle.updateAABB(transformGlobalTriangle, aabb);
|
||||
triangle.updateForNarrowCollision(transformGlobalTriangle);
|
||||
boolean result = ToolCollisionSphereWithTriangle.testCollide(sphere, triangle);
|
||||
Assert.assertEquals(resultTheoricValue, result);
|
||||
final boolean result = ToolCollisionSphereWithTriangle.testCollide(sphere, triangle);
|
||||
Assertions.assertEquals(resultTheoricValue, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testsphereOutTop() {
|
||||
float testCoefficient = 2.0f;
|
||||
PhysicSphere sphere = new PhysicSphere();
|
||||
final float testCoefficient = 2.0f;
|
||||
final PhysicSphere sphere = new PhysicSphere();
|
||||
sphere.setSize(testCoefficient);
|
||||
PhysicTriangle triangle = new PhysicTriangle();
|
||||
triangle.setPoints(new Vector3f(testCoefficient, testCoefficient, 0.0f), new Vector3f(testCoefficient, -testCoefficient, 0.0f), new Vector3f(-testCoefficient, 0.0f, 0.0f));
|
||||
Transform3D transformGlobalTriangle = Transform3D.IDENTITY;
|
||||
Transform3D transformGlobalsphere = new Transform3D(new Vector3f(0.0f, 0.0f, testCoefficient + 0.001f));
|
||||
AABB aabb = new AABB();
|
||||
final PhysicTriangle triangle = new PhysicTriangle();
|
||||
triangle.setPoints(new Vector3f(testCoefficient, testCoefficient, 0.0f),
|
||||
new Vector3f(testCoefficient, -testCoefficient, 0.0f), new Vector3f(-testCoefficient, 0.0f, 0.0f));
|
||||
final Transform3D transformGlobalTriangle = Transform3D.IDENTITY;
|
||||
final Transform3D transformGlobalsphere = new Transform3D(new Vector3f(0.0f, 0.0f, testCoefficient + 0.001f));
|
||||
final AABB aabb = new AABB();
|
||||
sphere.updateAABB(transformGlobalsphere, aabb);
|
||||
sphere.updateForNarrowCollision(transformGlobalsphere);
|
||||
triangle.updateAABB(transformGlobalTriangle, aabb);
|
||||
triangle.updateForNarrowCollision(transformGlobalTriangle);
|
||||
boolean result = ToolCollisionSphereWithTriangle.testCollide(sphere, triangle);
|
||||
Assert.assertFalse(result);
|
||||
final boolean result = ToolCollisionSphereWithTriangle.testCollide(sphere, triangle);
|
||||
Assertions.assertFalse(result);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user