Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Clark Lin
PracticeDx
Commits
140b1eca
Commit
140b1eca
authored
Mar 18, 2023
by
Administrator
Browse files
made camera moving. init multiple boxes.
parent
0f114ee2
Changes
3
Hide whitespace changes
Inline
Side-by-side
PracticeDx/Box.cpp
View file @
140b1eca
...
...
@@ -128,11 +128,19 @@ void Box::Update(float dt) noexcept
theta += dtheta * dt;
phi += dphi * dt;
chi += dchi * dt;*/
dx
=
dt
;
dy
=
dt
;
dz
=
dt
;
//
dx = dt;
//
dy = dt;
//
dz = dt
* 10.0f
;
}
void
Box
::
UpdateCamera
(
float
sin
,
float
cos
)
noexcept
{
using
namespace
DirectX
;
upDirection
=
XMVectorSet
(
0.0
f
,
1.0
f
,
0.0
f
,
1.0
f
);
focusPosition
=
XMVectorZero
();
eyePosition
=
XMVectorSet
(
20.0
f
*
sin
,
10.0
f
,
-
20.0
f
*
cos
,
1.0
f
);
};
DirectX
::
XMMATRIX
Box
::
GetTransformXM
()
const
noexcept
{
/*return DirectX::XMMatrixRotationRollPitchYaw(pitch, yaw, roll) *
...
...
@@ -140,14 +148,6 @@ DirectX::XMMATRIX Box::GetTransformXM() const noexcept
DirectX::XMMatrixRotationRollPitchYaw(theta, phi, chi) *
DirectX::XMMatrixTranslation(0.0f, 0.0f, 20.0f);*/
using
namespace
DirectX
;
XMVECTOR
upDirection
,
eyePosition
,
focusPosition
;
// Setup the vector that points upwards.
upDirection
=
XMVectorSet
(
0.0
f
,
1.0
f
,
0.0
f
,
1.0
f
);
focusPosition
=
XMVectorZero
();
eyePosition
=
XMVectorSet
(
5.0
f
,
5.0
f
,
-
5.0
f
,
1.0
f
);
return
DirectX
::
XMMatrixTranslation
(
dx
,
dy
,
dz
)
*
DirectX
::
XMMatrixLookAtLH
(
eyePosition
,
focusPosition
,
upDirection
);
...
...
PracticeDx/Box.h
View file @
140b1eca
...
...
@@ -7,6 +7,7 @@ class Box : public Drawable
public:
Box
(
Graphics
&
gfx
,
float
position
[][
3
],
float
color
[][
3
],
Logger
&
logger
);
void
Update
(
float
dt
)
noexcept
override
;
void
UpdateCamera
(
float
sin
,
float
cos
)
noexcept
;
DirectX
::
XMMATRIX
GetTransformXM
()
const
noexcept
override
;
private:
// positional
...
...
@@ -17,4 +18,8 @@ private:
float
dx
=
0.0
f
;
float
dy
=
0.0
f
;
float
dz
=
0.0
f
;
// for camera
DirectX
::
XMVECTOR
upDirection
;
DirectX
::
XMVECTOR
eyePosition
;
DirectX
::
XMVECTOR
focusPosition
;
};
\ No newline at end of file
PracticeDx/WinMain.cpp
View file @
140b1eca
...
...
@@ -703,36 +703,43 @@ int WINAPI WinMain(HINSTANCE hInstance,
};
Triangle
tri
(
gfx
,
triPos
,
triCol
,
logger
);
float
boxPos
[
8
][
3
]
=
std
::
vector
<
std
::
unique_ptr
<
Box
>>
boxes
;
for
(
int
i
=
-
5
;
i
<
6
;
i
++
)
{
// left bottom back
{
-
1.0
f
,
-
1.0
f
,
-
1.0
f
},
// right bottom back
{
1.0
f
,
-
1.0
f
,
-
1.0
f
},
// left top back
{
-
1.0
f
,
1.0
f
,
-
1.0
f
},
// right top back
{
1.0
f
,
1.0
f
,
-
1.0
f
},
// left bottom front
{
-
1.0
f
,
-
1.0
f
,
1.0
f
},
// right bottom front
{
1.0
f
,
-
1.0
f
,
1.0
f
},
// left top front
{
-
1.0
f
,
1.0
f
,
1.0
f
},
// right top front
{
1.0
f
,
1.0
f
,
1.0
f
},
};
float
boxCol
[
6
][
3
]
=
{
{
0.0
f
,
1.0
f
,
0.0
f
},
// Green
{
1.0
f
,
1.0
f
,
0.0
f
},
// Yellow
{
1.0
f
,
0.0
f
,
0.0
f
},
// Red
{
0.0
f
,
0.0
f
,
1.0
f
},
// Blue
{
0.0
f
,
1.0
f
,
1.0
f
},
// Cyan
{
1.0
f
,
0.0
f
,
1.0
f
},
// Magenta
};
Box
box
(
gfx
,
boxPos
,
boxCol
,
logger
);
for
(
int
j
=
-
5
;
j
<
6
;
j
++
)
{
float
boxPos
[
8
][
3
]
=
{
// left bottom back
{
-
1.0
f
+
i
,
-
1.0
f
,
-
1.0
f
+
j
},
// right bottom back
{
1.0
f
+
i
,
-
1.0
f
,
-
1.0
f
+
j
},
// left top back
{
-
1.0
f
+
i
,
1.0
f
,
-
1.0
f
+
j
},
// right top back
{
1.0
f
+
i
,
1.0
f
,
-
1.0
f
+
j
},
// left bottom front
{
-
1.0
f
+
i
,
-
1.0
f
,
1.0
f
+
j
},
// right bottom front
{
1.0
f
+
i
,
-
1.0
f
,
1.0
f
+
j
},
// left top front
{
-
1.0
f
+
i
,
1.0
f
,
1.0
f
+
j
},
// right top front
{
1.0
f
+
i
,
1.0
f
,
1.0
f
+
j
},
};
float
boxCol
[
6
][
3
]
=
{
{
0.0
f
,
1.0
f
,
0.0
f
},
// Green
{
1.0
f
,
1.0
f
,
0.0
f
},
// Yellow
{
1.0
f
,
0.0
f
,
0.0
f
},
// Red
{
0.0
f
,
0.0
f
,
1.0
f
},
// Blue
{
0.0
f
,
1.0
f
,
1.0
f
},
// Cyan
{
1.0
f
,
0.0
f
,
1.0
f
},
// Magenta
};
boxes
.
push_back
(
std
::
make_unique
<
Box
>
(
gfx
,
boxPos
,
boxCol
,
logger
));
}
}
double
seed
=
0
;
seed
=
int
(
seed
)
%
10000
;
...
...
@@ -765,13 +772,20 @@ int WINAPI WinMain(HINSTANCE hInstance,
gfx
.
RendorFrame
();
seed
++
;
auto
dt
=
sin
(
seed
/
2
000
);
auto
dt
=
sin
(
seed
/
5
000
);
logger
.
PutLog
(
"seed"
,
std
::
to_string
(
seed
));
logger
.
PutLog
(
"dt"
,
std
::
to_string
(
dt
));
box
.
Update
(
dt
);
box
.
ExecuteBind
(
gfx
,
logger
);
box
.
Draw
(
gfx
,
logger
);
auto
sinValue
=
sin
(
seed
/
5000
);
auto
cosValue
=
cos
(
seed
/
5000
);
for
(
auto
&
box
:
boxes
)
{
box
->
Update
(
dt
);
box
->
UpdateCamera
(
sinValue
,
cosValue
);
box
->
ExecuteBind
(
gfx
,
logger
);
box
->
Draw
(
gfx
,
logger
);
}
//tri.Update(dt);
//tri.ExecuteBind(gfx, logger);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment