[DEV] change the Up axis as Z UP ==> spirit understanding better
This commit is contained in:
parent
811f2fc2b1
commit
1df51c29bd
@ -150,7 +150,7 @@ class ExportEMF(bpy.types.Operator, ExportHelper):
|
||||
('-Y', "-Y Forward", ""),
|
||||
('-Z', "-Z Forward", ""),
|
||||
),
|
||||
default='-Z',
|
||||
default='-Y',
|
||||
)
|
||||
|
||||
axis_up = EnumProperty(
|
||||
@ -162,7 +162,7 @@ class ExportEMF(bpy.types.Operator, ExportHelper):
|
||||
('-Y', "-Y Up", ""),
|
||||
('-Z', "-Z Up", ""),
|
||||
),
|
||||
default='Y',
|
||||
default='Z',
|
||||
)
|
||||
|
||||
path_mode = path_reference_mode
|
||||
|
@ -49,57 +49,62 @@ To create a compound physics collision shape for a mesh in blender:
|
||||
default=True)
|
||||
"""
|
||||
|
||||
def out_point3( v ):
|
||||
# Methods for writing point, scale, and quaternion types to a YAML file.
|
||||
# This particular implementation converts values to a Y-up coordinate system.
|
||||
def out_point3_y_up( v ):
|
||||
return "%g %g %g" % ( v.x, v.z, -v.y )
|
||||
def out_scale3_y_up( s ):
|
||||
return "%g %g %g" % ( s.x, s.z, s.y )
|
||||
def out_quaternion_y_up( q ):
|
||||
return "%g %g %g %g" % ( q.w, q.x, q.z, -q.y )
|
||||
# This implementation maintains blender's Z-up coordinate system.
|
||||
def out_point3_z_up( v ):
|
||||
return "%g %g %g" % ( v.x, v.y, v.z )
|
||||
def out_scale3( s ):
|
||||
def out_scale3_z_up( s ):
|
||||
return "%g %g %g" % ( s.x, s.y, s.z )
|
||||
def out_quaternion( q ):
|
||||
return "%g %g %g %g" % ( q.x, q.y, q.z, q.w )
|
||||
def out_quaternion_z_up( q ):
|
||||
return "%g %g %g %g" % ( q.w, q.x, q.y, q.z )
|
||||
|
||||
|
||||
def get_physics_shape(obj, mainObjScale, _matrix):
|
||||
def get_physics_shape(obj, mainObjScale, use_y_up=False):
|
||||
shape = ""
|
||||
props = { }
|
||||
name = obj.name.lower()
|
||||
scale = Vector(( abs(obj.scale.x), abs(obj.scale.y), abs(obj.scale.z) ))
|
||||
print("object * name : " + obj.name)
|
||||
print(" * scale : (" + str(obj.scale.x) + "," + str(obj.scale.y) + "," + str(obj.scale.z) + ")")
|
||||
print(" * location : (" + str(obj.location.x) + "," + str(obj.location.y) + "," + str(obj.location.z) + ")")
|
||||
if obj.rotation_mode == 'QUATERNION':
|
||||
qrot = obj.rotation_quaternion
|
||||
qrot2 = _matrix.to_quaternion() * obj.rotation_quaternion
|
||||
|
||||
if use_y_up:
|
||||
out_point3 = out_point3_y_up
|
||||
out_scale3 = out_scale3_y_up
|
||||
out_quaternion = out_quaternion_y_up
|
||||
else:
|
||||
qrot = obj.matrix_local.to_quaternion()
|
||||
qrot2 = _matrix.to_quaternion() * obj.matrix_local.to_quaternion()
|
||||
if qrot == qrot2:
|
||||
print(" * quaternion : (" + str(qrot.x) + "," + str(qrot.y) + "," + str(qrot.z) + "," + str(qrot.w) + ")")
|
||||
else:
|
||||
print(" * quaternion : (" + str(qrot.x) + "," + str(qrot.y) + "," + str(qrot.z) + "," + str(qrot.w) + ") ==> (" + str(qrot2.x) + "," + str(qrot2.y) + "," + str(qrot2.z) + "," + str(qrot2.w) + ")")
|
||||
out_point3 = out_point3_z_up
|
||||
out_scale3 = out_scale3_z_up
|
||||
out_quaternion = out_quaternion_z_up
|
||||
|
||||
# BOX
|
||||
if name.startswith('box') \
|
||||
or name.startswith('cube'):
|
||||
shape = "Box"
|
||||
props["half-extents"] = out_scale3( Vector((scale.x * mainObjScale.x, scale.y * mainObjScale.y, scale.z * mainObjScale.z )) )
|
||||
props["half-extents"] = out_scale3( scale )
|
||||
# SPHERE
|
||||
elif name.startswith('sph'):
|
||||
shape = "Sphere"
|
||||
props["radius"] = (scale.x * mainObjScale.x + scale.y * mainObjScale.y + scale.z * mainObjScale.z ) / 3.0
|
||||
props["radius"] = obj.scale.x * mainObjScale.x
|
||||
# CONE
|
||||
elif name.startswith('cone'):
|
||||
shape = "Cone"
|
||||
props["radius"] = (scale.x * mainObjScale.x + scale.y * mainObjScale.y ) / 2.0
|
||||
props["size"] = obj.scale.z * mainObjScale.z * 2.0
|
||||
props["radius"] = obj.scale.x
|
||||
props["height"] = obj.scale.z * 2.0
|
||||
# CYLINDER
|
||||
elif name.startswith('cyl'):
|
||||
shape = "Cylinder"
|
||||
props["radius"] = (scale.x * mainObjScale.x + scale.y * mainObjScale.y ) / 2.0
|
||||
props["size"] = obj.scale.z * mainObjScale.z
|
||||
props["radius"] = (obj.scale.x+ obj.scale.y)*0.5
|
||||
props["height"] = obj.scale.z
|
||||
# CAPSULE
|
||||
elif name.startswith('cap'):
|
||||
shape = "Capsule"
|
||||
props["radius"] = (scale.x * mainObjScale.x + scale.y * mainObjScale.y ) / 2.0
|
||||
props["size"] = obj.scale.z * mainObjScale.z
|
||||
props["radius"] = obj.scale.x
|
||||
props["height"] = obj.scale.z
|
||||
# CONVEX-HULL
|
||||
elif name.startswith('convex'):
|
||||
shape = "ConvexHull"
|
||||
@ -115,14 +120,8 @@ def get_physics_shape(obj, mainObjScale, _matrix):
|
||||
print(" shape type: '" + str(shape) + "' from element name:'" + str(obj.name) + "'")
|
||||
|
||||
if obj.location != Vector((0,0,0)):
|
||||
location_tmp = _matrix * Vector((obj.location.x * mainObjScale.x, obj.location.y * mainObjScale.y, obj.location.z * mainObjScale.z ))
|
||||
location_tmp = Vector((obj.location.x * mainObjScale.x, obj.location.y * mainObjScale.y, obj.location.z * mainObjScale.z ))
|
||||
props["origin"] = out_point3(location_tmp)
|
||||
props["origin"] = out_point3(obj.location)
|
||||
|
||||
if obj.rotation_mode == 'QUATERNION':
|
||||
qrot = _matrix.to_quaternion() * obj.rotation_quaternion
|
||||
else:
|
||||
qrot = _matrix.to_quaternion() * obj.matrix_local.to_quaternion()
|
||||
if obj.rotation_mode == 'QUATERNION':
|
||||
qrot = obj.rotation_quaternion
|
||||
else:
|
||||
@ -134,7 +133,7 @@ def get_physics_shape(obj, mainObjScale, _matrix):
|
||||
return (shape, props)
|
||||
|
||||
|
||||
def write_collision_shape(object, file, mainObjScale, offset, EXPORT_GLOBAL_MATRIX):
|
||||
def write_collision_shape(object, file, mainObjScale, offset):
|
||||
if len(getChildren(object))==0:
|
||||
# no phisical shape ...
|
||||
return
|
||||
@ -147,7 +146,7 @@ def write_collision_shape(object, file, mainObjScale, offset, EXPORT_GLOBAL_MATR
|
||||
if subObj.type != 'MESH' \
|
||||
and subObj.type != 'EMPTY':
|
||||
continue
|
||||
(shape, props) = get_physics_shape(subObj, mainObjScale, EXPORT_GLOBAL_MATRIX)
|
||||
(shape, props) = get_physics_shape(subObj, mainObjScale)
|
||||
if shape=="":
|
||||
print("error of shape detection type ...");
|
||||
continue
|
||||
@ -550,7 +549,7 @@ def write_mesh(scene, file, object, EXPORT_GLOBAL_MATRIX, mtl_dict):
|
||||
print(" child:'%s'" % (subObj.name))
|
||||
if subObj.name.lower().startswith(EXPORT_COLLISION_NAME):
|
||||
print(" find physics:'%s'" % (subObj.name))
|
||||
write_collision_shape(subObj, file, object.scale, 1, EXPORT_GLOBAL_MATRIX)
|
||||
write_collision_shape(subObj, file, object.scale, 1)
|
||||
|
||||
|
||||
|
||||
@ -623,7 +622,7 @@ def write_file(filepath,
|
||||
#####################################################################
|
||||
## Save collision shapes (for one all):
|
||||
#####################################################################
|
||||
write_collision_shape(sub_obj, file, sub_obj.scale, 0, EXPORT_GLOBAL_MATRIX)
|
||||
write_collision_shape(sub_obj, file, sub_obj.scale, 0)
|
||||
else:
|
||||
print(" child:'" + str(sub_obj.name) + "' type=" + sub_obj.type + " not parsed ...")
|
||||
|
||||
|
@ -79,15 +79,15 @@ vec2 ege::Camera::tansformPositionToAngle(vec3 _vect) {
|
||||
if (distance == 0.0f) {
|
||||
return out;
|
||||
}
|
||||
out.setY(std::asin(_vect.y()/distance));
|
||||
_vect.setY(0.0f);
|
||||
if (_vect.x() == 0 && _vect.z() == 0) {
|
||||
out.setY(std::asin(_vect.z()/distance));
|
||||
_vect.setZ(0.0f);
|
||||
if (_vect.x() == 0 && _vect.y() == 0) {
|
||||
return out;
|
||||
}
|
||||
_vect.normalize();
|
||||
out.setX(std::asin(_vect.z()));
|
||||
out.setX(std::asin(_vect.y()));
|
||||
if (_vect.x() < 0) {
|
||||
out.setX(out.x()*-1 - M_PI);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ void ege::camera::ControlBase::setCamera(const ememory::SharedPtr<ege::camera::V
|
||||
}
|
||||
m_camera = _camera;
|
||||
m_camera->setTarget(vec3(0,0,0));
|
||||
m_camera->setEye(vec3(100*std::sin(m_angleTetha),80*std::cos(m_anglePsy),100*std::cos(m_angleTetha))*m_distance);
|
||||
m_camera->setEye(vec3(100*std::sin(m_angleTetha),100*std::cos(m_angleTetha),80*std::cos(m_anglePsy))*m_distance);
|
||||
m_PCH = ewol::Object::getObjectManager().periodicCall.connect(this, &ege::camera::ControlBase::periodicCall);
|
||||
}
|
||||
|
||||
@ -52,33 +52,33 @@ bool ege::camera::ControlBase::onEventEntry(const ewol::event::Entry& _event) {
|
||||
}
|
||||
if (_event.getType() == gale::key::keyboard::up) {
|
||||
if (_event.getStatus() == gale::key::status::down) {
|
||||
m_destinationCameraOffset += vec3(0,0,1);
|
||||
m_destinationCameraOffset += vec3(0,1,0);
|
||||
} else if (_event.getStatus() == gale::key::status::up) {
|
||||
m_destinationCameraOffset -= vec3(0,0,1);
|
||||
m_destinationCameraOffset -= vec3(0,1,0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (_event.getType() == gale::key::keyboard::down) {
|
||||
if (_event.getStatus() == gale::key::status::down) {
|
||||
m_destinationCameraOffset -= vec3(0,0,1);
|
||||
m_destinationCameraOffset -= vec3(0,1,0);
|
||||
} else if (_event.getStatus() == gale::key::status::up) {
|
||||
m_destinationCameraOffset += vec3(0,0,1);
|
||||
m_destinationCameraOffset += vec3(0,1,0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (_event.getType() == gale::key::keyboard::pageUp) {
|
||||
if (_event.getStatus() == gale::key::status::down) {
|
||||
m_destinationCameraOffset += vec3(0,1,0);
|
||||
m_destinationCameraOffset += vec3(0,0,1);
|
||||
} else if (_event.getStatus() == gale::key::status::up) {
|
||||
m_destinationCameraOffset -= vec3(0,1,0);
|
||||
m_destinationCameraOffset -= vec3(0,0,1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (_event.getType() == gale::key::keyboard::pageDown) {
|
||||
if (_event.getStatus() == gale::key::status::down) {
|
||||
m_destinationCameraOffset -= vec3(0,1,0);
|
||||
m_destinationCameraOffset -= vec3(0,0,1);
|
||||
} else if (_event.getStatus() == gale::key::status::up) {
|
||||
m_destinationCameraOffset += vec3(0,1,0);
|
||||
m_destinationCameraOffset += vec3(0,0,1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -117,7 +117,7 @@ bool ege::camera::ControlBase::onEventInput(const ewol::event::Input& _event, co
|
||||
if (_event.getId() == 4) {
|
||||
// scrool button ==> zoom in
|
||||
m_distance += 0.01f;
|
||||
m_camera->setEye(vec3(100*std::sin(m_angleTetha),80*std::cos(m_anglePsy),100*std::cos(m_angleTetha))*m_distance);
|
||||
m_camera->setEye(vec3(100*std::sin(m_angleTetha),100*std::cos(m_angleTetha),80*std::cos(m_anglePsy))*m_distance);
|
||||
return true;
|
||||
} else if (_event.getId() == 5) {
|
||||
// scrool button ==> zoom OUT
|
||||
@ -125,7 +125,7 @@ bool ege::camera::ControlBase::onEventInput(const ewol::event::Input& _event, co
|
||||
if (m_distance <= 0.05f) {
|
||||
m_distance = 0.05f;
|
||||
}
|
||||
m_camera->setEye(vec3(100*std::sin(m_angleTetha),80*std::cos(m_anglePsy),100*std::cos(m_angleTetha))*m_distance);
|
||||
m_camera->setEye(vec3(100*std::sin(m_angleTetha),100*std::cos(m_angleTetha),80*std::cos(m_anglePsy))*m_distance);
|
||||
return true;
|
||||
} else if (_event.getId() == 3) {
|
||||
// Middle button ==> move around the target position
|
||||
@ -135,7 +135,7 @@ bool ege::camera::ControlBase::onEventInput(const ewol::event::Input& _event, co
|
||||
vec2 pos = _relativePosition;
|
||||
m_angleTetha += (m_oldScreenPos.x()-pos.x())*0.02f;
|
||||
m_anglePsy += (m_oldScreenPos.y()-pos.y())*0.01f;
|
||||
m_camera->setEye(m_camera->getTarget() + vec3(100*std::sin(m_angleTetha),80*std::cos(m_anglePsy),100*std::cos(m_angleTetha))*m_distance);
|
||||
m_camera->setEye(m_camera->getTarget() + vec3(100*std::sin(m_angleTetha),100*std::cos(m_angleTetha),80*std::cos(m_anglePsy))*m_distance);
|
||||
m_oldScreenPos = _relativePosition;
|
||||
}
|
||||
return true;
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
void ege::camera::View::update() {
|
||||
/*
|
||||
vec3 m_up(0,1,0);
|
||||
vec3 m_up(0,0,1);
|
||||
m_matrix = etk::matLookAt(m_eye, m_target, m_up);
|
||||
//m_matrix.transpose();
|
||||
//m_matrix.translate(m_eye);
|
||||
@ -27,8 +27,8 @@ void ege::camera::View::update() {
|
||||
float distance = pos.length();
|
||||
|
||||
m_matrix.translate(vec3(0,0,-distance));
|
||||
m_matrix.rotate(vec3(1,0,0), angles.y());
|
||||
m_matrix.rotate(vec3(0,1,0), angles.x()-M_PI/2.0f);
|
||||
m_matrix.rotate(vec3(1,0,0), -M_PI*0.5f + angles.y());
|
||||
m_matrix.rotate(vec3(0,0,1), -angles.x()-M_PI/2.0f);
|
||||
m_matrix.translate(-m_target);
|
||||
EGE_DEBUG("Camera properties : distance=" << distance );
|
||||
EGE_DEBUG(" psy=" << angles.y());
|
||||
@ -75,11 +75,11 @@ ege::Ray ege::camera::View::getRayFromScreen(const vec2& _offset) {
|
||||
#if 1
|
||||
// It is not the best way to create the ray but it work . (My knowlege is not enought now ...)
|
||||
vec3 screenOffset(0,0,-1);
|
||||
screenOffset = screenOffset.rotate(vec3(0,1,0), -cameraAngleOffset.x());
|
||||
screenOffset = screenOffset.rotate(vec3(1,0,0), cameraAngleOffset.y());
|
||||
vec2 angles = tansformPositionToAngle(getViewVector());
|
||||
screenOffset = screenOffset.rotate(vec3(1,0,0), angles.y());
|
||||
screenOffset = screenOffset.rotate(vec3(0,1,0), -angles.x() - M_PI/2.0f);
|
||||
screenOffset = screenOffset.rotate(vec3(0,1,0), cameraAngleOffset.x());
|
||||
screenOffset = screenOffset.rotate(vec3(1,0,0), -cameraAngleOffset.y());
|
||||
vec2 angles = tansformPositionToAngle(-getViewVector());
|
||||
screenOffset = screenOffset.rotate(vec3(1,0,0), -M_PI*0.5f + angles.y());
|
||||
screenOffset = screenOffset.rotate(vec3(0,0,1), angles.x() - M_PI/2.0f);
|
||||
vec3 direction = screenOffset;
|
||||
#else
|
||||
// lA PROJECTION TOURNE EN FONCTION DE L'ANGLE
|
||||
|
@ -26,67 +26,67 @@ ememory::SharedPtr<ege::resource::Mesh> ege::resource::Mesh::createGrid(int32_t
|
||||
if (iii==0) {
|
||||
out->addLine(_materialName, _position+vec3(-_lineCount,0,0)*_size, _position+vec3(_lineCount+1,0,0)*_size, etk::color::red);
|
||||
// arrow
|
||||
out->addLine(_materialName, _position+vec3(_lineCount+1.0f,0,0)*_size, _position+vec3(_lineCount+0.5f,0,0.5f)*_size, etk::color::red);
|
||||
out->addLine(_materialName, _position+vec3(_lineCount+1.0f,0,0)*_size, _position+vec3(_lineCount+0.5f,0,-0.5f)*_size, etk::color::red);
|
||||
out->addLine(_materialName, _position+vec3(_lineCount+1.0f,0,0)*_size, _position+vec3(_lineCount+0.5f,0.5f,0)*_size, etk::color::red);
|
||||
out->addLine(_materialName, _position+vec3(_lineCount+1.0f,0,0)*_size, _position+vec3(_lineCount+0.5f,-0.5f,0)*_size, etk::color::red);
|
||||
out->addLine(_materialName, _position+vec3(_lineCount+1.0f,0,0)*_size, _position+vec3(_lineCount+0.5f,0,0.5f)*_size, etk::color::red);
|
||||
out->addLine(_materialName, _position+vec3(_lineCount+1.0f,0,0)*_size, _position+vec3(_lineCount+0.5f,0,-0.5f)*_size, etk::color::red);
|
||||
// X letter
|
||||
out->addLine(_materialName, _position+vec3(_lineCount+2.0f,-1.0f,1.0f)*_size, _position+vec3(_lineCount+2.0f,1.0f,-1.0f)*_size, etk::color::red);
|
||||
out->addLine(_materialName, _position+vec3(_lineCount+2.0f,1.0f,-1.0f)*_size, _position+vec3(_lineCount+2.0f,-1.0f,1.0f)*_size, etk::color::red);
|
||||
out->addLine(_materialName, _position+vec3(_lineCount+2.0f,-1.0f,-1.0f)*_size, _position+vec3(_lineCount+2.0f,1.0f,1.0f)*_size, etk::color::red);
|
||||
} else {
|
||||
out->addLine(_materialName, _position+vec3(-_lineCount,0,iii)*_size, _position+vec3(_lineCount,0,iii)*_size, etk::color::gray);
|
||||
out->addLine(_materialName, _position+vec3(-_lineCount,iii,0)*_size, _position+vec3(_lineCount,iii,0)*_size, etk::color::gray);
|
||||
}
|
||||
//out->addPoint(_materialName, vec3(-_lineCount,iii,0), etk::color::white);
|
||||
//out->addPoint(_materialName, vec3(_lineCount,iii,0), etk::color::white);
|
||||
}
|
||||
// create Z lines
|
||||
for (int32_t iii=-_lineCount; iii<=_lineCount; ++iii) {
|
||||
if (iii==0) {
|
||||
out->addLine(_materialName, _position+vec3(0,0,-_lineCount)*_size, _position+vec3(0,0,_lineCount+1)*_size, etk::color::green);
|
||||
// arrow
|
||||
out->addLine(_materialName, _position+vec3(0,0,_lineCount+1.0f)*_size, _position+vec3(0.5f,0,_lineCount+0.5f)*_size, etk::color::green);
|
||||
out->addLine(_materialName, _position+vec3(0,0,_lineCount+1.0f)*_size, _position+vec3(-0.5f,0,_lineCount+0.5f)*_size, etk::color::green);
|
||||
out->addLine(_materialName, _position+vec3(0,0,_lineCount+1.0f)*_size, _position+vec3(0,0.5f,_lineCount+0.5f)*_size, etk::color::green);
|
||||
out->addLine(_materialName, _position+vec3(0,0,_lineCount+1.0f)*_size, _position+vec3(0,-0.5f,_lineCount+0.5f)*_size, etk::color::green);
|
||||
// Z letter
|
||||
out->addLine(_materialName, _position+vec3(1,-1,_lineCount+2.0f)*_size, _position+vec3(1,1,_lineCount+2.0f)*_size, etk::color::green);
|
||||
out->addLine(_materialName, _position+vec3(1,1,_lineCount+2.0f)*_size, _position+vec3(-1,-1,_lineCount+2.0f)*_size, etk::color::green);
|
||||
out->addLine(_materialName, _position+vec3(-1,-1,_lineCount+2.0f)*_size, _position+vec3(-1,1,_lineCount+2.0f)*_size, etk::color::green);
|
||||
} else {
|
||||
out->addLine(_materialName, _position+vec3(iii,0,-_lineCount)*_size, _position+vec3(iii,0,_lineCount)*_size, etk::color::gray);
|
||||
}
|
||||
//out->addPoint(_materialName, vec3(iii,0,-_lineCount), etk::color::white);
|
||||
//out->addPoint(_materialName, vec3(iii,0,_lineCount), etk::color::white);
|
||||
}
|
||||
// create Y lines
|
||||
for (int32_t iii=-_lineCount; iii<=_lineCount; ++iii) {
|
||||
if (iii==0) {
|
||||
out->addLine(_materialName, _position+vec3(0,-_lineCount,0)*_size, _position+vec3(0,_lineCount+1,0)*_size, etk::color::blue);
|
||||
out->addLine(_materialName, _position+vec3(0,-_lineCount,0)*_size, _position+vec3(0,_lineCount+1,0)*_size, etk::color::green);
|
||||
// arrow
|
||||
out->addLine(_materialName, _position+vec3(0,_lineCount+1,0)*_size, _position+vec3(0.5f,_lineCount+0.5f,0)*_size, etk::color::blue);
|
||||
out->addLine(_materialName, _position+vec3(0,_lineCount+1,0)*_size, _position+vec3(-0.5f,_lineCount+0.5f,0)*_size, etk::color::blue);
|
||||
out->addLine(_materialName, _position+vec3(0,_lineCount+1,0)*_size, _position+vec3(0,_lineCount+0.5f,0.5f)*_size, etk::color::blue);
|
||||
out->addLine(_materialName, _position+vec3(0,_lineCount+1,0)*_size, _position+vec3(0,_lineCount+0.5f,-0.5f)*_size, etk::color::blue);
|
||||
out->addLine(_materialName, _position+vec3(0,_lineCount+1.0f,0)*_size, _position+vec3(0.5f,_lineCount+0.5f,0)*_size, etk::color::green);
|
||||
out->addLine(_materialName, _position+vec3(0,_lineCount+1.0f,0)*_size, _position+vec3(-0.5f,_lineCount+0.5f,0)*_size, etk::color::green);
|
||||
out->addLine(_materialName, _position+vec3(0,_lineCount+1.0f,0)*_size, _position+vec3(0,_lineCount+0.5f,0.5f)*_size, etk::color::green);
|
||||
out->addLine(_materialName, _position+vec3(0,_lineCount+1.0f,0)*_size, _position+vec3(0,_lineCount+0.5f,-0.5f)*_size, etk::color::green);
|
||||
// Y letter
|
||||
out->addLine(_materialName, _position+vec3(0,_lineCount+2,0)*_size, _position+vec3(0.7f,_lineCount+2.0f,1.0f)*_size, etk::color::blue);
|
||||
out->addLine(_materialName, _position+vec3(0,_lineCount+2,0)*_size, _position+vec3(-0.7f,_lineCount+2.0f,1.0f)*_size, etk::color::blue);
|
||||
out->addLine(_materialName, _position+vec3(0,_lineCount+2,0)*_size, _position+vec3(0,_lineCount+2.0f,-1.0f)*_size, etk::color::blue);
|
||||
out->addLine(_materialName, _position+vec3(0,_lineCount+2.0f,0)*_size, _position+vec3(0.7f,_lineCount+2.0f,1.0f)*_size, etk::color::blue);
|
||||
out->addLine(_materialName, _position+vec3(0,_lineCount+2.0f,0)*_size, _position+vec3(-0.7f,_lineCount+2.0f,1.0f)*_size, etk::color::blue);
|
||||
out->addLine(_materialName, _position+vec3(0,_lineCount+2.0f,0)*_size, _position+vec3(0,_lineCount+2.0f,-1.0f)*_size, etk::color::blue);
|
||||
} else {
|
||||
out->addLine(_materialName, _position+vec3(iii,-_lineCount,0)*_size, _position+vec3(iii,_lineCount,0)*_size, etk::color::gray);
|
||||
}
|
||||
//out->addPoint(_materialName, vec3(iii,-_lineCount,0), etk::color::white);
|
||||
//out->addPoint(_materialName, vec3(iii,_lineCount,0), etk::color::white);
|
||||
}
|
||||
// create Z lines
|
||||
for (int32_t iii=-_lineCount; iii<=_lineCount; ++iii) {
|
||||
if (iii==0) {
|
||||
out->addLine(_materialName, _position+vec3(0,0,-_lineCount)*_size, _position+vec3(0,0,_lineCount+1)*_size, etk::color::blue);
|
||||
// arrow
|
||||
out->addLine(_materialName, _position+vec3(0,0,_lineCount+1)*_size, _position+vec3(0.5f,0,_lineCount+0.5f)*_size, etk::color::blue);
|
||||
out->addLine(_materialName, _position+vec3(0,0,_lineCount+1)*_size, _position+vec3(-0.5f,0,_lineCount+0.5f)*_size, etk::color::blue);
|
||||
out->addLine(_materialName, _position+vec3(0,0,_lineCount+1)*_size, _position+vec3(0,0.5f,_lineCount+0.5f)*_size, etk::color::blue);
|
||||
out->addLine(_materialName, _position+vec3(0,0,_lineCount+1)*_size, _position+vec3(0,-0.5f,_lineCount+0.5f)*_size, etk::color::blue);
|
||||
// Z letter
|
||||
out->addLine(_materialName, _position+vec3( 1,-1,_lineCount+2.0f)*_size, _position+vec3( 1, 1,_lineCount+2.0f)*_size, etk::color::green);
|
||||
out->addLine(_materialName, _position+vec3( 1, 1,_lineCount+2.0f)*_size, _position+vec3(-1,-1,_lineCount+2.0f)*_size, etk::color::green);
|
||||
out->addLine(_materialName, _position+vec3(-1,-1,_lineCount+2.0f)*_size, _position+vec3(-1, 1,_lineCount+2.0f)*_size, etk::color::green);
|
||||
|
||||
} else {
|
||||
std::vector<vec3> list;
|
||||
list.push_back(_position+vec3(-1,iii,-1)*_size);
|
||||
list.push_back(_position+vec3(1,iii,-1)*_size);
|
||||
list.push_back(_position+vec3(1,iii,1)*_size);
|
||||
list.push_back(_position+vec3(-1,iii,1)*_size);
|
||||
list.push_back(_position+vec3(-1,iii,-1)*_size);
|
||||
list.push_back(_position+vec3(-1,-1,iii)*_size);
|
||||
list.push_back(_position+vec3(1,-1,iii)*_size);
|
||||
list.push_back(_position+vec3(1,1,iii)*_size);
|
||||
list.push_back(_position+vec3(-1,1,iii)*_size);
|
||||
list.push_back(_position+vec3(-1,-1,iii)*_size);
|
||||
out->addLines(_materialName, list, etk::color::gray);
|
||||
}
|
||||
//out->addPoint(_materialName, vec3(iii,0,-_lineCount), etk::color::white);
|
||||
//out->addPoint(_materialName, vec3(iii,0,_lineCount), etk::color::white);
|
||||
//out->addPoint(_materialName, vec3(iii,-_lineCount,0), etk::color::white);
|
||||
//out->addPoint(_materialName, vec3(iii,_lineCount,0), etk::color::white);
|
||||
}
|
||||
|
||||
// generate the VBO
|
||||
out->generateVBO();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ void appl::Windows::init() {
|
||||
|
||||
m_env = ege::Environement::create();
|
||||
// Create basic Camera
|
||||
m_camera = ememory::makeShared<ege::camera::View>(vec3(30,-100,30), vec3(0,0,0));
|
||||
m_camera = ememory::makeShared<ege::camera::View>(vec3(30,30,-100), vec3(0,0,0));
|
||||
m_env->addCamera("basic", m_camera);
|
||||
|
||||
ememory::SharedPtr<ege::widget::Scene> tmpWidget = ege::widget::Scene::create();
|
||||
@ -127,7 +127,7 @@ void appl::Windows::onCallbackPeriodicUpdateCamera(const ewol::event::Time& _eve
|
||||
offset += 0.01;
|
||||
static float offset2 = 0;
|
||||
offset2 += 0.003;
|
||||
m_camera->setEye(vec3(100*std::sin(offset),40*std::cos(offset2),100*std::cos(offset)));
|
||||
m_camera->setEye(vec3(100*std::sin(offset),100*std::cos(offset),40*std::cos(offset2)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -82,10 +82,10 @@ void appl::Windows::init() {
|
||||
ememory::SharedPtr<ege::camera::View> camera2 = ememory::makeShared<ege::camera::View>(vec3(100,0,0), vec3(0,0,0));
|
||||
m_env->addCamera("front", camera2);
|
||||
// Create basic Camera
|
||||
ememory::SharedPtr<ege::camera::View> camera3 = ememory::makeShared<ege::camera::View>(vec3(20,20,100), vec3(0,0,0));
|
||||
ememory::SharedPtr<ege::camera::View> camera3 = ememory::makeShared<ege::camera::View>(vec3(20,100,20), vec3(0,0,0));
|
||||
m_env->addCamera("top", camera3);
|
||||
// Create basic Camera
|
||||
ememory::SharedPtr<ege::camera::View> camera4 = ememory::makeShared<ege::camera::View>(vec3(0,100,0), vec3(0,0,0));
|
||||
ememory::SharedPtr<ege::camera::View> camera4 = ememory::makeShared<ege::camera::View>(vec3(0,0,100), vec3(0,0,0));
|
||||
m_env->addCamera("left", camera4);
|
||||
|
||||
ememory::SharedPtr<ewol::widget::Sizer> tmpSizerVert = ewol::widget::Sizer::create();
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <ege/position/Component.hpp>
|
||||
#include <ege/render/Component.hpp>
|
||||
#include <ege/physics/Component.hpp>
|
||||
#include <ege/Ray.hpp>
|
||||
|
||||
appl::Windows::Windows() {
|
||||
addObjectType("appl::Windows");
|
||||
@ -84,12 +85,13 @@ static ememory::SharedPtr<ege::resource::Mesh> createMars() {
|
||||
void appl::Windows::init() {
|
||||
ewol::widget::Windows::init();
|
||||
|
||||
getObjectManager().periodicCall.connect(sharedFromThis(), &appl::Windows::onCallbackPeriodicUpdateCamera);
|
||||
//getObjectManager().periodicCall.connect(sharedFromThis(), &appl::Windows::onCallbackPeriodicUpdateCamera);
|
||||
|
||||
m_env = ege::Environement::create();
|
||||
// Create basic Camera
|
||||
m_camera = ememory::makeShared<ege::camera::View>(vec3(30,-100,30), vec3(50,0,0));
|
||||
m_camera = ememory::makeShared<ege::camera::View>();
|
||||
m_env->addCamera("basic", m_camera);
|
||||
m_cameraControler.setCamera(m_camera);
|
||||
|
||||
ememory::SharedPtr<ege::widget::Scene> tmpWidget = ege::widget::Scene::create();
|
||||
if (tmpWidget == nullptr) {
|
||||
@ -130,7 +132,7 @@ void appl::Windows::init() {
|
||||
// add it ..
|
||||
m_env->addEntity(entity);
|
||||
}
|
||||
if (true) {
|
||||
if (false) {
|
||||
myMesh = createMars();
|
||||
if (myMesh != nullptr) {
|
||||
ememory::SharedPtr<ege::Entity> entity = ememory::makeShared<ege::Entity>(m_env);
|
||||
@ -148,13 +150,100 @@ void appl::Windows::init() {
|
||||
m_env->propertyStatus.set(ege::gameStart);
|
||||
}
|
||||
|
||||
void appl::Windows::setDebugNormal() {
|
||||
m_env->getEngine("render")->properties.set("debug-normal", "true");
|
||||
}
|
||||
void appl::Windows::setDebugAABB() {
|
||||
m_env->getEngine("physics")->properties.set("debug-AABB", "true");
|
||||
}
|
||||
void appl::Windows::setDebugShape() {
|
||||
m_env->getEngine("physics")->properties.set("debug-shape", "true");
|
||||
}
|
||||
|
||||
void appl::Windows::setMeshName(const std::string& _fileName) {
|
||||
// Create an external box: (no physics)
|
||||
ememory::SharedPtr<ege::resource::Mesh> myMesh = ege::resource::Mesh::create(_fileName);
|
||||
if (myMesh != nullptr) {
|
||||
ememory::SharedPtr<ege::Entity> entity = ememory::makeShared<ege::Entity>(m_env);
|
||||
// 1st Position component:
|
||||
etk::Transform3D transform(vec3(0,0,0), etk::Quaternion::identity());
|
||||
if (myMesh->getPhysicalProperties().size() != 0) {
|
||||
ememory::SharedPtr<ege::physics::Component> componentPhysics = ememory::makeShared<ege::physics::Component>(m_env, transform);
|
||||
componentPhysics->setShape(myMesh->getPhysicalProperties());
|
||||
componentPhysics->generate();
|
||||
entity->addComponent(componentPhysics);
|
||||
} else {
|
||||
ememory::SharedPtr<ege::position::Component> componentPosition = ememory::makeShared<ege::position::Component>(transform);
|
||||
entity->addComponent(componentPosition);
|
||||
}
|
||||
// 2nd something to diplay:
|
||||
ememory::SharedPtr<ege::render::Component> componentRender = ememory::makeShared<ege::render::Component>(myMesh);
|
||||
entity->addComponent(componentRender);
|
||||
// add it ..
|
||||
m_env->addEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void appl::Windows::onCallbackPeriodicUpdateCamera(const ewol::event::Time& _event) {
|
||||
static float offset = 0;
|
||||
offset += 0.01;
|
||||
static float offset2 = 0;
|
||||
offset2 += 0.003;
|
||||
m_camera->setEye(vec3(100*std::sin(offset),40*std::cos(offset2),100*std::cos(offset))+vec3(50,0,0));
|
||||
m_camera->setEye(vec3(100*std::sin(offset),100*std::cos(offset),40*std::cos(offset2))+vec3(50,0,0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool appl::Windows::onEventEntry(const ewol::event::Entry& _event) {
|
||||
if (m_cameraControler.onEventEntry(_event) == true) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool appl::Windows::onEventInput(const ewol::event::Input& _event) {
|
||||
if (m_cameraControler.onEventInput(_event, relativePosition(_event.getPos())) == true) {
|
||||
return true;
|
||||
}
|
||||
if (_event.getId() == 1) {
|
||||
if (_event.getStatus() == gale::key::status::down) {
|
||||
vec2 pos = relativePosition(_event.getPos());
|
||||
ege::Ray ray = m_camera->getRayFromScreenPosition(pos, m_size);
|
||||
|
||||
ememory::SharedPtr<ege::resource::Mesh> myMesh;
|
||||
myMesh = ege::resource::Mesh::createCube(1, "basics", etk::color::orange);
|
||||
if (myMesh != nullptr) {
|
||||
ememory::SharedPtr<ege::Entity> entity = ememory::makeShared<ege::Entity>(m_env);
|
||||
// add all component:
|
||||
// 1st Position component:
|
||||
etk::Transform3D transform(ray.getOrigin(), etk::Quaternion::identity());
|
||||
//ememory::SharedPtr<ege::position::Component> componentPosition = ememory::makeShared<ege::position::Component>(transform);
|
||||
//entity->addComponent(componentPosition);
|
||||
// 2nd something to diplay:
|
||||
ememory::SharedPtr<ege::render::Component> componentRender = ememory::makeShared<ege::render::Component>(myMesh);
|
||||
entity->addComponent(componentRender);
|
||||
// 3rd some physic:
|
||||
ememory::SharedPtr<ege::physics::Component> componentPhysics = ememory::makeShared<ege::physics::Component>(m_env, transform);
|
||||
ememory::SharedPtr<ege::physics::shape::Box> physic = ememory::makeShared<ege::physics::shape::Box>();
|
||||
physic->setSize(vec3(1.01,1.01,1.01));
|
||||
physic->setMass(1000);
|
||||
componentPhysics->setType(ege::physics::Component::type::bodyDynamic);
|
||||
componentPhysics->addShape(physic);
|
||||
componentPhysics->generate();
|
||||
// set has dynamic object (can move)
|
||||
//APPL_CRITICAL("velocity : " << ray.getDirection()*100);
|
||||
componentPhysics->setLinearVelocity(ray.getDirection()*100);
|
||||
entity->addComponent(componentPhysics);
|
||||
// add it ..
|
||||
m_env->addEntity(entity);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -10,12 +10,14 @@
|
||||
#include <ewol/widget/Windows.hpp>
|
||||
#include <ege/Environement.hpp>
|
||||
#include <ege/camera/View.hpp>
|
||||
#include <ege/camera/ControlBase.hpp>
|
||||
|
||||
namespace appl {
|
||||
class Windows : public ewol::widget::Windows {
|
||||
private:
|
||||
ememory::SharedPtr<ege::Environement> m_env;
|
||||
ememory::SharedPtr<ege::camera::View> m_camera;
|
||||
ege::camera::ControlBase m_cameraControler;
|
||||
protected:
|
||||
Windows();
|
||||
void init() override;
|
||||
@ -24,6 +26,13 @@ namespace appl {
|
||||
virtual ~Windows() { };
|
||||
private:
|
||||
void onCallbackPeriodicUpdateCamera(const ewol::event::Time& _event);
|
||||
public:
|
||||
void setMeshName(const std::string& _fileName);
|
||||
void setDebugNormal();
|
||||
void setDebugAABB();
|
||||
void setDebugShape();
|
||||
bool onEventEntry(const ewol::event::Entry& _event) override;
|
||||
bool onEventInput(const ewol::event::Input& _event) override;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -22,14 +22,7 @@ class MainApplication : public ewol::context::Application {
|
||||
public:
|
||||
void onCreate(ewol::Context& _context) override {
|
||||
APPL_INFO(" == > CREATE ... " << PROJECT_NAME << " v" << APPL_VERSION << " (START) [" << gale::getBoardType() << "] (" << gale::getCompilationMode() << ") (BEGIN)");
|
||||
for( int32_t iii=0 ; iii<_context.getCmd().size(); iii++) {
|
||||
std::string tmpppp = _context.getCmd().get(iii);
|
||||
if ( tmpppp == "-h"
|
||||
|| tmpppp == "--help") {
|
||||
APPL_INFO(" -h/--help display this help" );
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO : Remove this : Move if in the windows properties
|
||||
_context.setSize(vec2(800, 600));
|
||||
|
||||
@ -37,7 +30,29 @@ class MainApplication : public ewol::context::Application {
|
||||
_context.getFontDefault().setUseExternal(true);
|
||||
_context.getFontDefault().set("FreeSerif;DejaVuSansMono", 19);
|
||||
|
||||
ememory::SharedPtr<ewol::widget::Windows> basicWindows = appl::Windows::create();
|
||||
ememory::SharedPtr<appl::Windows> basicWindows = appl::Windows::create();
|
||||
|
||||
for( int32_t iii=0 ; iii<_context.getCmd().size(); iii++) {
|
||||
std::string tmpppp = _context.getCmd().get(iii);
|
||||
if ( tmpppp == "-h"
|
||||
|| tmpppp == "--help") {
|
||||
APPL_PRINT(" -h/--help display this help");
|
||||
APPL_PRINT(" --mesh=XXX Load this mesh file");
|
||||
APPL_PRINT(" --debug-normal Display normal");
|
||||
APPL_PRINT(" --debug-AABB Display AABB box");
|
||||
APPL_PRINT(" --debug-shape Display Shape");
|
||||
exit(0);
|
||||
} else if (etk::start_with(tmpppp, "--mesh=") == true) {
|
||||
std::string fileName = &tmpppp[7];
|
||||
basicWindows->setMeshName(fileName);
|
||||
} else if (tmpppp == "--debug-normal") {
|
||||
basicWindows->setDebugNormal();
|
||||
} else if (tmpppp == "--debug-AABB") {
|
||||
basicWindows->setDebugAABB();
|
||||
} else if (tmpppp == "--debug-shape") {
|
||||
basicWindows->setDebugShape();
|
||||
}
|
||||
}
|
||||
// create the specific windows
|
||||
_context.setWindows(basicWindows);
|
||||
APPL_INFO("==> CREATE ... " PROJECT_NAME " (END)");
|
||||
|
Loading…
x
Reference in New Issue
Block a user