collada: mouse view control
This commit is contained in:
parent
dbd36f2d2c
commit
65455ad471
File diff suppressed because one or more lines are too long
@ -14,6 +14,14 @@ camera const camera_camera001_camera = {
|
|||||||
.aspect_ratio = 0.0f,
|
.aspect_ratio = 0.0f,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
camera const camera_camera002_camera = {
|
||||||
|
.xfov = 22.14429f,
|
||||||
|
.yfov = 0.0f,
|
||||||
|
.znear = 1.0f,
|
||||||
|
.zfar = 1000.0f,
|
||||||
|
.aspect_ratio = 0.0f,
|
||||||
|
};
|
||||||
|
|
||||||
light const light_environmentambientlight = {
|
light const light_environmentambientlight = {
|
||||||
.type = light_type::AMBIENT,
|
.type = light_type::AMBIENT,
|
||||||
.color = {0.0f, 0.0f, 0.0f},
|
.color = {0.0f, 0.0f, 0.0f},
|
||||||
@ -7753,7 +7761,7 @@ geometry const geometry_geom_torso = {
|
|||||||
.triangles_count = 2,
|
.triangles_count = 2,
|
||||||
|
|
||||||
.vertex_buffer_offset = 35712,
|
.vertex_buffer_offset = 35712,
|
||||||
.vertex_buffer_size = 111888,
|
.vertex_buffer_size = 108792,
|
||||||
|
|
||||||
.index_buffer_offset = 8928,
|
.index_buffer_offset = 8928,
|
||||||
.index_buffer_size = 48600,
|
.index_buffer_size = 48600,
|
||||||
@ -8208,7 +8216,7 @@ controller const controller_geom_torso_skin1 = {
|
|||||||
.inverse_bind_matrices = inverse_bind_matrices_geom_torso_skin1,
|
.inverse_bind_matrices = inverse_bind_matrices_geom_torso_skin1,
|
||||||
|
|
||||||
.vertex_buffer_offset = 0,
|
.vertex_buffer_offset = 0,
|
||||||
.vertex_buffer_size = 99456,
|
.vertex_buffer_size = 96704,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -12451,7 +12459,7 @@ node const node_node_camera001_target = {
|
|||||||
transform const transforms_node_omni001[] = {
|
transform const transforms_node_omni001[] = {
|
||||||
{
|
{
|
||||||
.type = transform_type::TRANSLATE,
|
.type = transform_type::TRANSLATE,
|
||||||
.translate = {-31.4336f, -117.9301f, 123.8172f},
|
.translate = {-20.38351f, -44.62419f, 39.48177f},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -12493,6 +12501,94 @@ node const node_node_omni001 = {
|
|||||||
.channels_count = 0,
|
.channels_count = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
transform const transforms_node_camera002[] = {
|
||||||
|
{
|
||||||
|
.type = transform_type::MATRIX,
|
||||||
|
.matrix = {0.9652951f, -0.2230207f, -0.1358941f, -11.32668f, -0.2611617f, -0.8243198f, -0.5022863f, -50.42014f, -1.62981e-09f, 0.5203449f, -0.8539562f, 18.52396f, 0.0f, 0.0f, 0.0f, 1.0f},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
instance_geometry const instance_geometries_node_camera002[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
instance_controller const instance_controllers_node_camera002[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
instance_light const instance_lights_node_camera002[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
channel const * const node_channels_node_camera002[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
node const node_node_camera002 = {
|
||||||
|
.name = "Camera002",
|
||||||
|
|
||||||
|
.parent_index = -1,
|
||||||
|
|
||||||
|
.type = node_type::NODE,
|
||||||
|
|
||||||
|
.transforms = transforms_node_camera002,
|
||||||
|
.transforms_count = 1,
|
||||||
|
|
||||||
|
.instance_geometries = instance_geometries_node_camera002,
|
||||||
|
.instance_geometries_count = 0,
|
||||||
|
|
||||||
|
.instance_controllers = instance_controllers_node_camera002,
|
||||||
|
.instance_controllers_count = 0,
|
||||||
|
|
||||||
|
.instance_lights = instance_lights_node_camera002,
|
||||||
|
.instance_lights_count = 0,
|
||||||
|
|
||||||
|
.channels = node_channels_node_camera002,
|
||||||
|
.channels_count = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
transform const transforms_node_camera002_target[] = {
|
||||||
|
{
|
||||||
|
.type = transform_type::TRANSLATE,
|
||||||
|
.translate = {-10.85921f, -48.69228f, 21.46156f},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.type = transform_type::ROTATE,
|
||||||
|
.rotate = {0.990609f, -0.1316388f, -0.03694672f, -211.0752f},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
instance_geometry const instance_geometries_node_camera002_target[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
instance_controller const instance_controllers_node_camera002_target[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
instance_light const instance_lights_node_camera002_target[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
channel const * const node_channels_node_camera002_target[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
node const node_node_camera002_target = {
|
||||||
|
.name = "Camera002.Target",
|
||||||
|
|
||||||
|
.parent_index = -1,
|
||||||
|
|
||||||
|
.type = node_type::NODE,
|
||||||
|
|
||||||
|
.transforms = transforms_node_camera002_target,
|
||||||
|
.transforms_count = 2,
|
||||||
|
|
||||||
|
.instance_geometries = instance_geometries_node_camera002_target,
|
||||||
|
.instance_geometries_count = 0,
|
||||||
|
|
||||||
|
.instance_controllers = instance_controllers_node_camera002_target,
|
||||||
|
.instance_controllers_count = 0,
|
||||||
|
|
||||||
|
.instance_lights = instance_lights_node_camera002_target,
|
||||||
|
.instance_lights_count = 0,
|
||||||
|
|
||||||
|
.channels = node_channels_node_camera002_target,
|
||||||
|
.channels_count = 0,
|
||||||
|
};
|
||||||
|
|
||||||
node const * const nodes[] = {
|
node const * const nodes[] = {
|
||||||
&node_node_environmentambientlight, // 0
|
&node_node_environmentambientlight, // 0
|
||||||
&node_node_eidelwindrigpelvis, // 1
|
&node_node_eidelwindrigpelvis, // 1
|
||||||
@ -12566,6 +12662,8 @@ node const * const nodes[] = {
|
|||||||
&node_node_camera001, // 69
|
&node_node_camera001, // 69
|
||||||
&node_node_camera001_target, // 70
|
&node_node_camera001_target, // 70
|
||||||
&node_node_omni001, // 71
|
&node_node_omni001, // 71
|
||||||
|
&node_node_camera002, // 72
|
||||||
|
&node_node_camera002_target, // 73
|
||||||
};
|
};
|
||||||
|
|
||||||
inputs const inputs_list[] = {
|
inputs const inputs_list[] = {
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -28,5 +28,6 @@ namespace collada::instance_types {
|
|||||||
// mutable state
|
// mutable state
|
||||||
transform * transforms;
|
transform * transforms;
|
||||||
XMMATRIX world;
|
XMMATRIX world;
|
||||||
|
bool externalTransform;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,5 +22,7 @@ namespace collada::scene {
|
|||||||
void update(float t);
|
void update(float t);
|
||||||
|
|
||||||
void unload_scene();
|
void unload_scene();
|
||||||
|
|
||||||
|
void mouse_motion(int eyeIndex, int targetIndex, float xrel, float yrel, int mode);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -125,11 +125,12 @@ VSOutput VSMain(VSSkinnedInput input)
|
|||||||
float4 shadowPosition = getProjection(Scene.ShadowProjection, getView(Scene.ShadowView, worldPosition));
|
float4 shadowPosition = getProjection(Scene.ShadowProjection, getView(Scene.ShadowView, worldPosition));
|
||||||
|
|
||||||
VSOutput output = (VSOutput)0;
|
VSOutput output = (VSOutput)0;
|
||||||
//output.Position = getProjection(Scene.ShadowProjection, viewPosition);
|
//output.Position = shadowPosition;
|
||||||
output.Position = getProjection(Scene.Projection, viewPosition);
|
output.Position = getProjection(Scene.Projection, viewPosition);
|
||||||
|
|
||||||
output.ShadowPosition = shadowPosition * float4(0.5, 0.5, 1.0, 1.0) + float4(0.5, 0.5, 0.0, 0.0);
|
output.ShadowPosition = shadowPosition * float4(0.5, 0.5, 1.0, 1.0) + float4(0.5, 0.5, 0.0, 0.0);
|
||||||
output.Normal = mul((float3x3)Scene.View, mul((float3x3)Nodes[constants.NodeIndex].World, input.Normal));
|
//output.Normal = mul((float3x3)Scene.View, mul((float3x3)Nodes[constants.NodeIndex].World, input.Normal));
|
||||||
|
output.Normal = mul((float3x3)Scene.View, mul((float3x3)world, input.Normal));
|
||||||
output.Texture = yf(input.Texture.xy);
|
output.Texture = yf(input.Texture.xy);
|
||||||
|
|
||||||
output.LightDirection = (Scene.LightPosition - viewPosition).xyz;
|
output.LightDirection = (Scene.LightPosition - viewPosition).xyz;
|
||||||
@ -200,7 +201,7 @@ float4 PSMain(VSOutput input) : SV_TARGET
|
|||||||
float3 diffuseSpecular = diffuse * diffuseColor.xyz + specular * specularColor.xyz;
|
float3 diffuseSpecular = diffuse * diffuseColor.xyz + specular * specularColor.xyz;
|
||||||
|
|
||||||
float3 shadowPosition = input.ShadowPosition.xyz / input.ShadowPosition.w;
|
float3 shadowPosition = input.ShadowPosition.xyz / input.ShadowPosition.w;
|
||||||
float shadowBias = max(0.01 * (1.0 - dot(N, L)), 0.002);
|
float shadowBias = max(0.001 * (1.0 - dot(N, L)), 0.0002);
|
||||||
|
|
||||||
//float shadowIntensity = Shadow(shadowPosition, shadowBias);
|
//float shadowIntensity = Shadow(shadowPosition, shadowBias);
|
||||||
float shadowIntensity = ShadowPCF(shadowPosition, shadowBias);
|
float shadowIntensity = ShadowPCF(shadowPosition, shadowBias);
|
||||||
|
|||||||
@ -51,6 +51,7 @@ namespace collada::node_state {
|
|||||||
{
|
{
|
||||||
node_instance.node = node;
|
node_instance.node = node;
|
||||||
node_instance.transforms = NewM<instance_types::transform>(node->transforms_count);
|
node_instance.transforms = NewM<instance_types::transform>(node->transforms_count);
|
||||||
|
node_instance.externalTransform = false;
|
||||||
|
|
||||||
initialize_node_transforms(node_instance);
|
initialize_node_transforms(node_instance);
|
||||||
}
|
}
|
||||||
@ -109,6 +110,10 @@ namespace collada::node_state {
|
|||||||
|
|
||||||
void state::update_node_world_transform(instance_types::node & node_instance)
|
void state::update_node_world_transform(instance_types::node & node_instance)
|
||||||
{
|
{
|
||||||
|
if (node_instance.externalTransform) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
XMMATRIX world;
|
XMMATRIX world;
|
||||||
|
|
||||||
if (node_instance.node->parent_index >= 0)
|
if (node_instance.node->parent_index >= 0)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "collada/scene.h"
|
#include "collada/scene.h"
|
||||||
#include "collada/animate.h"
|
#include "collada/animate.h"
|
||||||
@ -76,4 +77,42 @@ namespace collada::scene {
|
|||||||
{
|
{
|
||||||
node_state.deallocate_node_instances(descriptor->nodes_count);
|
node_state.deallocate_node_instances(descriptor->nodes_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void state::mouse_motion(int eyeIndex, int targetIndex, float xrel, float yrel, int mode)
|
||||||
|
{
|
||||||
|
assert(descriptor->nodes[eyeIndex]);
|
||||||
|
instance_types::node & eye = node_state.node_instances[eyeIndex];
|
||||||
|
instance_types::node & target = node_state.node_instances[targetIndex];
|
||||||
|
|
||||||
|
eye.externalTransform = true;
|
||||||
|
//target.externalTransform = true;
|
||||||
|
|
||||||
|
XMVECTOR eyePosition = XMVector3Transform(XMVectorZero(), eye.world);
|
||||||
|
XMVECTOR targetPosition = XMVector3Transform(XMVectorZero(), target.world);
|
||||||
|
|
||||||
|
XMVECTOR viewDirection = eyePosition - targetPosition;
|
||||||
|
XMVECTOR viewNormal = XMVector3Normalize(viewDirection);
|
||||||
|
XMVECTOR length = XMVector3Length(viewDirection);
|
||||||
|
|
||||||
|
XMVECTOR up = XMVectorSet(0, 0, 1, 0);
|
||||||
|
XMVECTOR crossNormal = XMVector3Normalize(XMVector3Cross(viewNormal, up));
|
||||||
|
|
||||||
|
|
||||||
|
XMVECTOR newPosition;
|
||||||
|
if (mode == 0) {
|
||||||
|
XMMATRIX rz = XMMatrixRotationZ(xrel * 0.02);
|
||||||
|
XMMATRIX mrn = XMMatrixRotationAxis(crossNormal, yrel * 0.02);
|
||||||
|
XMVECTOR newNormal = XMVector3TransformNormal(viewNormal, rz * mrn);
|
||||||
|
newPosition = targetPosition + newNormal * length;
|
||||||
|
} else {
|
||||||
|
float scale = (xrel + yrel) * 0.02;
|
||||||
|
newPosition = targetPosition + viewNormal * length * (1.0f - scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
eye.world = XMMatrixTranslationFromVector(newPosition);
|
||||||
|
|
||||||
|
//printf("[%f %f %f] ", XMVectorGetX(viewDirection), XMVectorGetY(viewDirection), XMVectorGetZ(viewDirection));
|
||||||
|
//printf("[%f %f %f] ", XMVectorGetX(eyePosition), XMVectorGetY(eyePosition), XMVectorGetZ(eyePosition));
|
||||||
|
//printf("[%f %f %f]\n", XMVectorGetX(targetPosition), XMVectorGetY(targetPosition), XMVectorGetZ(targetPosition));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
src/main.cpp
16
src/main.cpp
@ -608,12 +608,14 @@ int main()
|
|||||||
SDL_GetCurrentTime(&start_time);
|
SDL_GetCurrentTime(&start_time);
|
||||||
|
|
||||||
int cameraIndex = collada_state.find_node_index_by_name("Camera001");
|
int cameraIndex = collada_state.find_node_index_by_name("Camera001");
|
||||||
int cameraTargetIndex = collada_state.find_node_index_by_name("Camera001.Target");
|
int cameraTargetIndex = collada_state.find_node_index_by_name("EidelwindRigPelvis");
|
||||||
int lightIndex = collada_state.find_node_index_by_name("Camera001");
|
int lightIndex = collada_state.find_node_index_by_name("Camera001");
|
||||||
int lightTargetIndex = collada_state.find_node_index_by_name("Torso");
|
int lightTargetIndex = collada_state.find_node_index_by_name("EidelwindRigPelvis");
|
||||||
//int lightMaterialIndex = collada_state.find_material_index_by_name("LightMaterial");
|
//int lightMaterialIndex = collada_state.find_material_index_by_name("LightMaterial");
|
||||||
int lightMaterialIndex = -1;
|
int lightMaterialIndex = -1;
|
||||||
|
|
||||||
|
collada_state.update(0);
|
||||||
|
|
||||||
while (quit == false) {
|
while (quit == false) {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
@ -639,6 +641,14 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (event.type == SDL_EVENT_MOUSE_MOTION) {
|
||||||
|
if (event.motion.state & SDL_BUTTON_LMASK) {
|
||||||
|
collada_state.mouse_motion(cameraIndex, cameraTargetIndex, event.motion.xrel, event.motion.yrel, 0);
|
||||||
|
}
|
||||||
|
if (event.motion.state & SDL_BUTTON_RMASK) {
|
||||||
|
collada_state.mouse_motion(cameraIndex, cameraTargetIndex, event.motion.xrel, event.motion.yrel, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (event.type == SDL_EVENT_WINDOW_RESIZED) {
|
if (event.type == SDL_EVENT_WINDOW_RESIZED) {
|
||||||
SDL_CHECK(SDL_GetWindowSize(window, &windowSize.x, &windowSize.y));
|
SDL_CHECK(SDL_GetWindowSize(window, &windowSize.x, &windowSize.y));
|
||||||
}
|
}
|
||||||
@ -681,7 +691,7 @@ int main()
|
|||||||
XMMATRIX projection = currentProjection();
|
XMMATRIX projection = currentProjection();
|
||||||
XMMATRIX view = currentView(collada_state.node_state.node_instances[cameraIndex],
|
XMMATRIX view = currentView(collada_state.node_state.node_instances[cameraIndex],
|
||||||
collada_state.node_state.node_instances[cameraTargetIndex]);
|
collada_state.node_state.node_instances[cameraTargetIndex]);
|
||||||
XMMATRIX shadowProjection = XMMatrixOrthographicLH(300, 300, 0.1, 500);
|
XMMATRIX shadowProjection = XMMatrixOrthographicLH(150, 150, -1000, 1000);
|
||||||
XMMATRIX shadowView = currentView(collada_state.node_state.node_instances[lightIndex],
|
XMMATRIX shadowView = currentView(collada_state.node_state.node_instances[lightIndex],
|
||||||
collada_state.node_state.node_instances[lightTargetIndex]);
|
collada_state.node_state.node_instances[lightTargetIndex]);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user