Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RoFIbots
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Marek Trtík
RoFIbots
Commits
98ab7cd9
There was an error fetching the commit references. Please try again later.
Commit
98ab7cd9
authored
1 year ago
by
Martin Štourač
Browse files
Options
Downloads
Patches
Plain Diff
visual ray fix, began find_intersection
parent
b91e7ec8
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/gfx/include/gfx/aabb.hpp
+1
-0
1 addition, 0 deletions
src/gfx/include/gfx/aabb.hpp
src/studio/include/studio/simulator.hpp
+2
-1
2 additions, 1 deletion
src/studio/include/studio/simulator.hpp
src/studio/src/simulator.cpp
+49
-32
49 additions, 32 deletions
src/studio/src/simulator.cpp
with
52 additions
and
33 deletions
src/gfx/include/gfx/aabb.hpp
+
1
−
0
View file @
98ab7cd9
...
...
@@ -17,6 +17,7 @@ class AABB
public:
AABB
(
std
::
vector
<
float
>
const
&
_vertices
);
std
::
pair
<
glm
::
vec3
,
glm
::
vec3
>
const
&
getLH
()
const
{
return
LH
;
}
std
::
vector
<
float
>
getVertices
()
const
;
std
::
vector
<
unsigned
int
>
getIndices
()
const
;
};
...
...
This diff is collapsed.
Click to expand it.
src/studio/include/studio/simulator.hpp
+
2
−
1
View file @
98ab7cd9
...
...
@@ -53,7 +53,8 @@ struct Simulator : public osi::Simulator
void
create_scene
();
void
process_input
();
void
add_ray
(
camera_ptr
camera
,
glm
::
vec3
rayDirection
);
void
find_intersection
(
glm
::
vec3
rayPosition
,
glm
::
vec3
rayDirection
);
void
add_ray
(
glm
::
vec3
rayPosition
,
glm
::
vec3
rayDirection
);
void
select_object
();
void
process_mouse
();
...
...
This diff is collapsed.
Click to expand it.
src/studio/src/simulator.cpp
+
49
−
32
View file @
98ab7cd9
...
...
@@ -315,12 +315,32 @@ void Simulator::process_input()
ASSUMPTION
(
glGetError
()
==
GL_NO_ERROR
);
}
void
Simulator
::
add_ray
(
camera_ptr
camera
,
glm
::
vec3
rayDirection
)
void
Simulator
::
find_intersection
(
glm
::
vec3
rayPosition
,
glm
::
vec3
rayDirection
)
{
node_ptr
nearest_node
=
nullptr
;
float
nearest_t
=
0
;
for
(
auto
&
node
:
scene
)
{
for
(
auto
&
object
:
node
->
getObjects
())
{
auto
obj
=
dynamic_pointer_cast
<
Object
>
(
object
);
if
(
!
obj
)
continue
;
auto
LH
=
obj
->
getAABB
().
getLH
();
// float t = intersect(rayPosition, rayDirection, LH);
// if (t < nearest_t)
// nearest_t = t;
}
}
}
void
Simulator
::
add_ray
(
glm
::
vec3
rayPosition
,
glm
::
vec3
rayDirection
)
{
object_ptr
ray
=
std
::
make_shared
<
Object
>
(
Object
{{
0
,
0
,
0
,
rayDirection
.
x
,
rayDirection
.
y
,
rayDirection
.
z
},
{
0
,
1
},
{},
glm
::
vec3
(
0.5
f
,
1
,
0.31
f
),
"basic"
});
ray
->
setDrawMode
(
GL_LINES
);
frame_ptr
ray_frame
=
std
::
make_shared
<
Frame
>
(
camera
->
getFrame
()
->
get
Position
()
);
frame_ptr
ray_frame
=
std
::
make_shared
<
Frame
>
(
ray
Position
);
scene
.
emplace_back
(
std
::
make_shared
<
Node
>
(
ray_frame
));
scene
.
back
()
->
addObject
(
std
::
move
(
ray
));
}
...
...
@@ -330,14 +350,6 @@ void Simulator::select_object()
if
(
!
mouse
().
just_released
().
contains
(
"MouseLeft"
))
return
;
/* ATTEMPT 1 */
// https://antongerdelan.net/opengl/raycasting.html
float
x_
=
mouse
().
pos
().
x
-
(
window
().
size
().
x
/
2
)
-
1.0
f
;
float
y_
=
1.0
f
-
mouse
().
pos
().
y
-
(
window
().
size
().
y
/
2
);
float
z_
=
1.0
f
;
glm
::
vec3
ray_ndc
=
glm
::
vec3
(
x_
,
y_
,
z_
);
glm
::
vec4
ray_clip
=
glm
::
vec4
(
ray_ndc
.
x
,
ray_ndc
.
y
,
-
1.0
f
,
1.0
f
);
camera_ptr
camera
=
active_cameras
[
0
];
glm
::
mat4
view
;
...
...
@@ -350,24 +362,32 @@ void Simulator::select_object()
0.1
f
,
100.0
f
);
glm
::
vec4
ray_eye
=
glm
::
inverse
(
projection
)
*
ray_clip
;
ray_eye
.
z
=
-
1.0
f
;
ray_eye
.
w
=
0.0
f
;
glm
::
vec3
ray_wor
=
(
glm
::
inverse
(
view
)
*
ray_eye
);
ray_wor
=
glm
::
normalize
(
ray_wor
);
/* ATTEMPT 2 */
// WHITEBOARD
float
u
=
static_cast
<
float
>
(
mouse
().
pos
().
x
-
(
window
().
size
().
x
/
2.0
f
));
float
v
=
static_cast
<
float
>
((
window
().
size
().
y
-
mouse
().
pos
().
y
)
-
(
window
().
size
().
y
/
2.0
f
));
glm
::
vec2
uv
=
glm
::
normalize
(
glm
::
vec2
(
u
,
v
));
glm
::
vec3
camPos
=
camera
->
getFrame
()
->
getPosition
();
glm
::
vec3
P
=
camPos
+
0.1
f
*
-
camera
->
getFrame
()
->
getRotationAxisZ
()
+
uv
.
x
*
camera
->
getFrame
()
->
getRotationAxisX
()
+
uv
.
y
*
camera
->
getFrame
()
->
getRotationAxisY
();
glm
::
vec3
w
=
P
-
camPos
;
w
=
glm
::
normalize
(
w
);
w
.
z
=
1.0
f
;
/* ATTEMPT 1 */
// https://antongerdelan.net/opengl/raycasting.html
// float x_ = mouse().pos().x - (window().size().x / 2) - 1.0f;
// float y_ = 1.0f - mouse().pos().y - (window().size().y / 2);
// float z_ = 1.0f;
// glm::vec3 ray_ndc = glm::vec3(x_, y_, z_);
// glm::vec4 ray_clip = glm::vec4(ray_ndc.x, ray_ndc.y, -1.0f, 1.0f);
// glm::vec4 ray_eye = glm::inverse(projection) * ray_clip;
// ray_eye.z = -1.0f;
// ray_eye.w = 0.0f;
// glm::vec3 ray_wor = (glm::inverse(view) * ray_eye);
// ray_wor = glm::normalize(ray_wor);
// /* ATTEMPT 2 */
// // WHITEBOARD
// float u = static_cast<float>(mouse().pos().x - (window().size().x / 2.0f));
// float v = static_cast<float>((window().size().y - mouse().pos().y) - (window().size().y / 2.0f));
// glm::vec2 uv = glm::normalize(glm::vec2(u, v));
// glm::vec3 camPos = camera->getFrame()->getPosition();
// glm::vec3 P = camPos + 0.1f * -camera->getFrame()->getRotationAxisZ() + uv.x * camera->getFrame()->getRotationAxisX() + uv.y * camera->getFrame()->getRotationAxisY();
// glm::vec3 w = P - camPos;
// w = glm::normalize(w);
// w.z = 1.0f;
// std::cout << "P point is: " << P.x << ", " << P.y << ", " << P.z << std::endl;
// std::cout << "camPos is: " << camPos.x << ", " << camPos.y << ", " << camPos.z << std::endl;
...
...
@@ -392,7 +412,6 @@ void Simulator::select_object()
glm
::
vec4
cameraSpaceNear
=
glm
::
vec4
(
screenSpaceX
*
nearPlane
,
screenSpaceY
*
nearPlane
,
-
nearPlane
,
1
);
glm
::
vec4
cameraSpaceFar
=
glm
::
vec4
(
screenSpaceX
*
farPlane
,
screenSpaceY
*
farPlane
,
-
farPlane
,
1
);
//Unproject the 2D window into 3D to see where in 3D we're actually clicking
glm
::
mat4
tmpView
=
glm
::
mat4
(
view
);
glm
::
mat4
invView
=
glm
::
inverse
(
tmpView
);
...
...
@@ -407,12 +426,10 @@ void Simulator::select_object()
rayDirection
=
camera
->
getFrame
()
->
getRotation
()
*
rayDirection
;
add_ray
(
camera
,
rayDirection
);
add_ray
(
rayPosition
,
rayDirection
);
rayDirection
=
glm
::
normalize
(
rayDirection
);
std
::
cout
<<
"rayDirection vector is: "
<<
rayDirection
.
x
<<
", "
<<
rayDirection
.
y
<<
", "
<<
rayDirection
.
z
<<
std
::
endl
<<
std
::
endl
;
}
void
Simulator
::
process_mouse
()
...
...
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