Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
X
XMLSchemaCompiler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anders Nilsson
XMLSchemaCompiler
Commits
a084ba5b
Commit
a084ba5b
authored
17 years ago
by
Anders Nilsson
Browse files
Options
Downloads
Patches
Plain Diff
Can compute OBB for simple x3d example. No idea if it's correct though.
parent
197b3473
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
x3d/BoundingBox.jrag
+67
-0
67 additions, 0 deletions
x3d/BoundingBox.jrag
x3d/OBB.java
+13
-0
13 additions, 0 deletions
x3d/OBB.java
with
80 additions
and
0 deletions
x3d/BoundingBox.jrag
0 → 100644
+
67
−
0
View file @
a084ba5b
/* -*-Java-*- */
/*
* Copyright (C) 2007 Anders Nilsson <anders.nilsson@cs.lth.se>
*
* This file is part of XmlSchemaCompiler.
*/
import com.jme.bounding.*;
import com.jme.util.geom.BufferUtils;
aspect BoundingBox {
syn OrientedBoundingBox ASTNode.obb() = new OrientedBoundingBox();
eq Start.obb() = getSpecification().obb();
eq Specification.obb() = getElement(0).obb();
eq ComplexElement.obb() = getNumElement()>0 ? getElement(0).obb() : null;
eq X3D.obb() {
for (int i=0; i<getNumElement(); i++) {
ComplexElement e = (ComplexElement) getElement(i);
if (e instanceof Scene) {
return e.obb();
}
}
// Fallback, didn't suceed in finding a bounding box
return null;
}
eq Scene.obb() {
OrientedBoundingBox obb = new OrientedBoundingBox();
StringBuffer sb = getCoordinates();
String s = sb.toString().replace('\"',' ').replace(',',' ');
// String s = sb.toString().replace('\"',' ').replace(',',' ').replace(" "," ");
String[] sa = s.split(" ",0);
float[] fa = new float[sa.length];
for (int i=0,j=0; i<sa.length; i++) {
if (!sa[i].equals("")) {
fa[j++] = Float.parseFloat(sa[i]);
}
}
obb.computeFromPoints(BufferUtils.createFloatBuffer(fa));
obb.computeCorners();
System.out.println("Center: "+obb.getCenter());
System.out.println("Extent: "+obb.getExtent());
System.out.println("Volume: "+obb.getVolume());
return obb;
}
}
aspect Coordinates {
syn StringBuffer Element.getCoordinates() = new StringBuffer();
eq ComplexElement.getCoordinates() {
StringBuffer sb = new StringBuffer();
for (int i=0; i<getNumElement(); i++) {
sb.append(getElement(i).getCoordinates());
}
return sb;
}
eq Coordinate.getCoordinates() {
StringBuffer sb = new StringBuffer();
for (int i=0; i<getNumAttribute(); i++) {
sb.append(getAttribute(i).getCoordinates());
}
return sb;
}
syn String Attribute.getCoordinates() = null;
eq point.getCoordinates() = getAttrValue().getSTRING_LITERAL();
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
x3d/OBB.java
0 → 100644
+
13
−
0
View file @
a084ba5b
import
AST.Start
;
import
com.jme.bounding.*
;
public
class
OBB
extends
Parser
{
public
static
void
main
(
String
args
[])
{
Start
ast
=
parse
(
args
);
OrientedBoundingBox
obb
=
ast
.
obb
();
System
.
out
.
println
(
"X axis: "
+
obb
.
getXAxis
());
System
.
out
.
println
(
"Y axis: "
+
obb
.
getYAxis
());
System
.
out
.
println
(
"Z axis: "
+
obb
.
getZAxis
());
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment