• Advertisement
Sign in to follow this  

Trying to make a camera move

This topic is 554 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to make a camera that moves. I've drawn a triangle to the screen and I want to use wasd to look at the triangle from different angles. When I press a movement key, nothing happens. I have created a world, view and projection matrix but what should I do after that. I've looked at tuts from everywhere but I cant figure it out.

Here is the full code + shader, I hope its not too long.

#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
#include <d3d11.h>
#include <assert.h>
#include <DirectXMath.h>
#include <d3dx11effect.h>
#include <d3dcompiler.h>
#include <DirectXColors.h>
#include <time.h>

using namespace DirectX;

/*
********************************************************************************************************
*
* WINDOW STUFF
*
********************************************************************************************************
*/
HWND main_window;
HINSTANCE hInst;
int window_width = 800;
int window_height = 600;
LARGE_INTEGER curr_time;
LARGE_INTEGER prev_time;
LARGE_INTEGER frequency;
float delta_time = 0;

/*
********************************************************************************************************
*
* DIRECTX STUFF
*
********************************************************************************************************
*/

ID3D11Device* device;
ID3D11DeviceContext* immediate_context;
IDXGISwapChain* swap_chain;
ID3D11RenderTargetView* render_target_view;
ID3D11DepthStencilView* depth_stencil_view;
ID3D11Texture2D* depth_stencil_buffer;
ID3D11InputLayout* input_layout;
ID3DX11Effect* effect;
ID3DX11EffectTechnique* technique;
ID3D11Buffer* tri_vertex_buffer;
ID3D11VertexShader* vertex_shader;
ID3D11PixelShader* pixel_shader;

D3D_FEATURE_LEVEL feature_level;
DXGI_SWAP_CHAIN_DESC swap_chain_desc;
D3D11_TEXTURE2D_DESC texture_desc;
D3D11_VIEWPORT view_port;

struct cb_per_frame
{
	XMMATRIX world_view_proj;
};

ID3D11Buffer* const_per_frame_buffer;
cb_per_frame const_per_frame;

struct vertex
{
	XMFLOAT3 Pos;
};

D3D11_INPUT_ELEMENT_DESC input_desc[] =
{
	{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};

vertex tri_verts[] =
{
	XMFLOAT3(0.0f, 0.5f, 0.5f),
	XMFLOAT3(0.5f, -0.5f, 0.5f),
	XMFLOAT3(-0.5f, -0.5f, 0.5f),
};

/*
********************************************************************************************************
*
* CLASS DECLARATIONS
*
********************************************************************************************************
*/

class camera
{
public:
	XMFLOAT3 position_vector;
	XMFLOAT3 right_vector;
	XMFLOAT3 up_vector;
	XMFLOAT3 look_vector;
	XMFLOAT4X4 view_matrix;
	XMFLOAT4X4 projection_matrix;
	XMFLOAT4X4 world_matrix;
	XMMATRIX world_view_proj;

	camera();
	void walk(float);
	void strafe(float);
	void update_view_matrix();
	void set_perspective_matrix(float, float, float, float);
	XMMATRIX get_world_view_proj();
};

camera my_camera;

/*
********************************************************************************************************
*
* FORWARD FUNCTION DECLARATIONS
*
********************************************************************************************************
*/

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
bool InitDirectX();
void time_tick();
void set_buffers();
void render();
void create_shaders_and_input_layout();
void update();
float get_aspect_ratio();
void create_effect();


/*
********************************************************************************************************
*
* MAIN FUNCTION
*
********************************************************************************************************
*/

int WINAPI WinMain(HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPSTR lpCmdLine,
	int nCmdShow)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);
	wcex.style = CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc = WndProc;
	wcex.cbClsExtra = 0;
	wcex.cbWndExtra = 0;
	wcex.hInstance = hInstance;
	wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
	wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
	wcex.lpszMenuName = NULL;
	wcex.lpszClassName = L"A Window";
	wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));

	if (!RegisterClassEx(&wcex))
	{
		MessageBox(NULL,
			_T("Call to RegisterClassEx failed!"),
			_T("Win32 Guided Tour"),
			NULL);

		return 1;
	}

	hInst = hInstance; 

					
	main_window = CreateWindow(
		L"A Window",
		L"Win32 Engine",
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT,
		window_width, window_height,
		NULL,
		NULL,
		hInstance,
		NULL
	);

	if (!main_window)
	{
		MessageBox(NULL,
			_T("Call to CreateWindow failed!"),
			_T("Win32 Guided Tour"),
			NULL);

		return 1;
	}

	ShowWindow(main_window,
		nCmdShow);
	UpdateWindow(main_window);

	InitDirectX();
	set_buffers();
	create_shaders_and_input_layout();
	create_effect();

	MSG msg = { 0 };
	while (msg.message != WM_QUIT)
	{
		PeekMessage(&msg, 0, 0, 0, PM_REMOVE);

		time_tick();
		update();
		render();

		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return (int)msg.wParam;
}

/*
********************************************************************************************************
*
* WINDOWS MESSAGE HANDLING
*
********************************************************************************************************
*/

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
		break;
	}

	return 0;
}

/*
********************************************************************************************************
*
* INIT DIRECTX
*
********************************************************************************************************
*/
bool InitDirectX()
{
	HRESULT hr = D3D11CreateDevice(NULL,
		D3D_DRIVER_TYPE_HARDWARE,
		NULL,
		NULL,
		NULL,
		0,
		D3D11_SDK_VERSION,
		&device,
		&feature_level,
		&immediate_context);

	if (FAILED(hr))
	{
		MessageBox(0, L"Create Device failed.", L"Error", MB_OK);
		return false;
	}

	if (feature_level != D3D_FEATURE_LEVEL_11_0)
	{
		MessageBox(0, L"D3D11 not supported.", L"Error", MB_OK);
		return false;
	}

	swap_chain_desc.BufferDesc.Width = window_width;
	swap_chain_desc.BufferDesc.Height = window_height;
	swap_chain_desc.BufferDesc.RefreshRate.Numerator = 60;
	swap_chain_desc.BufferDesc.RefreshRate.Denominator = 1;
	swap_chain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	swap_chain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
	swap_chain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

	swap_chain_desc.SampleDesc.Count = 1;
	swap_chain_desc.SampleDesc.Quality = 0;

	swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	swap_chain_desc.BufferCount = 1;
	swap_chain_desc.OutputWindow = main_window;
	swap_chain_desc.Windowed = true;
	swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
	swap_chain_desc.Flags = 0;

	IDXGIDevice * pDXGIDevice = nullptr;
	hr = device->QueryInterface(__uuidof(IDXGIDevice), (void **)&pDXGIDevice);

	if (FAILED(hr))
	{
		MessageBox(0, L"QueryInterface() failed.", L"Error", MB_OK);
	}

	IDXGIAdapter * pDXGIAdapter = nullptr;
	hr = pDXGIDevice->GetAdapter(&pDXGIAdapter);

	if (FAILED(hr))
	{
		MessageBox(0, L"GetAdapter failed", L"Error", MB_OK);
	}

	IDXGIFactory * pIDXGIFactory = nullptr;
	pDXGIAdapter->GetParent(__uuidof(IDXGIFactory), (void **)&pIDXGIFactory);

	pIDXGIFactory->CreateSwapChain(device, &swap_chain_desc, &swap_chain);

	pDXGIDevice->Release();
	pDXGIAdapter->Release();
	pIDXGIFactory->Release();

	ID3D11Texture2D* back_buffer;

	hr = swap_chain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&back_buffer));

	if (FAILED(hr))
	{
		MessageBox(0, L"GetBuffer() failed.", L"Error", MB_OK);
	}

	hr = device->CreateRenderTargetView(back_buffer, NULL, &render_target_view);

	if (FAILED(hr))
	{
		MessageBox(0, L"CreateRenderTargetView() failed", L"Error", MB_OK);
	}
	back_buffer->Release();

	ZeroMemory(&texture_desc, sizeof(texture_desc));
	texture_desc.Width = window_width;
	texture_desc.Height = window_height;
	texture_desc.MipLevels = 1;
	texture_desc.ArraySize = 1;
	texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;

	texture_desc.SampleDesc.Count = 1;
	texture_desc.SampleDesc.Quality = 0;
	texture_desc.Usage = D3D11_USAGE_DEFAULT;
	texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
	texture_desc.CPUAccessFlags = 0;
	texture_desc.MiscFlags = 0;

	hr = device->CreateTexture2D(&texture_desc, NULL, &depth_stencil_buffer);

	if (FAILED(hr))
	{
		MessageBox(0, L"CreateTexture2d() failed.", L"Error", MB_OK);
	}

	D3D11_DEPTH_STENCIL_VIEW_DESC depth_stencil_view_desc;
	ZeroMemory(&depth_stencil_view_desc, sizeof(depth_stencil_view_desc));
	depth_stencil_view_desc.Format = texture_desc.Format;
	depth_stencil_view_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
	depth_stencil_view_desc.Texture2D.MipSlice = 0;

	hr = device->CreateDepthStencilView(depth_stencil_buffer, &depth_stencil_view_desc, &depth_stencil_view);

	if (FAILED(hr))
	{
		MessageBox(0, L"CreateDepthStencilView() failed.", L"Error", MB_OK);
	}

	immediate_context->OMSetRenderTargets(1, &render_target_view, depth_stencil_view);

	view_port.TopLeftX = 0;
	view_port.TopLeftY = 0;
	view_port.Width = static_cast<float>(window_width);
	view_port.Height = static_cast<float>(window_height);
	view_port.MinDepth = 0.0f;
	view_port.MaxDepth = 1.0f;

	immediate_context->RSSetViewports(1, &view_port);
}

/*
********************************************************************************************************
*
* SET BUFFERS
*
********************************************************************************************************
*/

void set_buffers()
{
	D3D11_BUFFER_DESC vertex_buffer_desc;
	vertex_buffer_desc.Usage = D3D11_USAGE_DEFAULT;
	vertex_buffer_desc.ByteWidth = sizeof(vertex) * 3;
	vertex_buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vertex_buffer_desc.CPUAccessFlags = 0;
	vertex_buffer_desc.MiscFlags = 0;
	vertex_buffer_desc.StructureByteStride = 0;

	D3D11_SUBRESOURCE_DATA vertex_init_data;
	ZeroMemory(&vertex_init_data, sizeof(vertex_init_data));
	vertex_init_data.pSysMem = tri_verts;

	HRESULT hr = device->CreateBuffer(&vertex_buffer_desc, &vertex_init_data, &tri_vertex_buffer);

	if (FAILED(hr))
	{
		MessageBox(NULL, L"Create Vertex Buffer Failed", L"Error", MB_OK);
	}

	UINT stride = sizeof(vertex);
	UINT offset = 0;
	immediate_context->IASetVertexBuffers(0, 1, &tri_vertex_buffer, &stride, &offset);

	/*D3D11_BUFFER_DESC constant_buffer_desc;
	ZeroMemory(&constant_buffer_desc, sizeof(D3D11_BUFFER_DESC));

	constant_buffer_desc.Usage = D3D11_USAGE_DEFAULT;
	constant_buffer_desc.ByteWidth = sizeof(cb_per_frame);
	constant_buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	constant_buffer_desc.CPUAccessFlags = 0;
	constant_buffer_desc.MiscFlags = 0;

	D3D11_SUBRESOURCE_DATA const_buf_init_data;
	const_buf_init_data.pSysMem = &const_per_frame;
	const_buf_init_data.SysMemPitch = 0;
	const_buf_init_data.SysMemSlicePitch = 0;

	hr = device->CreateBuffer(&constant_buffer_desc, &const_buf_init_data, &const_per_frame_buffer);

	if (FAILED(hr))
	{
		MessageBox(NULL, L"Failed to create constant buffer", L"Error", MB_OK);
	}

	immediate_context->VSSetConstantBuffers(0, 1, &const_per_frame_buffer);*/
}

/*
********************************************************************************************************
*
* CREATE SHADERS + INPUT LAYOUT
*
********************************************************************************************************
*/

void create_shaders_and_input_layout()
{
	ID3DBlob* vs_blob = NULL;
	ID3DBlob* error_blob = NULL;
	HRESULT hr = D3DCompileFromFile(L"my_shader.fx", NULL, NULL, "VS", "vs_5_0", NULL, 0, &vs_blob, &error_blob);

	if (FAILED(hr))
	{
		MessageBox(NULL,
			L"The FX file (VS) cannot be compiled.  Please run this executable from the directory that contains the FX file.", L"Error", MB_OK);
		return;
	}

	hr = device->CreateVertexShader(vs_blob->GetBufferPointer(), vs_blob->GetBufferSize(), NULL, &vertex_shader);

	if (FAILED(hr))
	{
		MessageBox(NULL, L"Cannot create vertex shader", L"Error", MB_OK);
		return;
	}

	ID3DBlob* ps_error_blob;
	ID3DBlob* ps_blob;
	hr = D3DCompileFromFile(L"my_shader.fx", NULL, NULL, "PS", "ps_5_0", NULL, 0, &ps_blob, &ps_error_blob);

	if (FAILED(hr))
	{
		MessageBox(NULL,
			L"The FX file (PS) cannot be compiled.  Please run this executable from the directory that contains the FX file.", L"Error", MB_OK);
		return;
	}

	hr = device->CreatePixelShader(ps_blob->GetBufferPointer(), ps_blob->GetBufferSize(), NULL, &pixel_shader);

	if (FAILED(hr))
	{
		MessageBox(NULL, L"Cannot create Pixel shader", L"Error", MB_OK);
	}
	UINT num_elements = ARRAYSIZE(input_desc);

	hr = device->CreateInputLayout(input_desc, num_elements, vs_blob->GetBufferPointer(), vs_blob->GetBufferSize(),
		&input_layout);

	if (FAILED(hr))
	{
		MessageBox(NULL, L"Create Input Layout Failed", L"Error", MB_OK);
		return;
	}

	immediate_context->IASetInputLayout(input_layout);

	immediate_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
}

/*
********************************************************************************************************
*
* RENDERING STUFF
*
********************************************************************************************************
*/

void render()
{
	immediate_context->ClearRenderTargetView(render_target_view, Colors::MidnightBlue);
	immediate_context->ClearDepthStencilView(depth_stencil_view, D3D11_CLEAR_DEPTH, 1.0f, 0);

	immediate_context->VSSetShader(vertex_shader, NULL, 0);
	immediate_context->PSSetShader(pixel_shader, NULL, 0);

	immediate_context->Draw(3, 0);

	swap_chain->Present(0, 0);
}

/*
********************************************************************************************************
*
* CHECK FOR INPUT (UPDATE)
*
********************************************************************************************************
*/

void update()
{
	

	if (GetAsyncKeyState('W') & 0x8000)
		my_camera.walk(5.0f);

	if (GetAsyncKeyState('A') & 0x8000)
		my_camera.strafe(-5.0f);

	if (GetAsyncKeyState('S') & 0x8000)
		my_camera.walk(-5.0f);

	if (GetAsyncKeyState('D') & 0x8000)
		my_camera.strafe(5.0f);
}

/*
********************************************************************************************************
*
* TIME TICK
*
********************************************************************************************************
*/

void time_tick()
{
	QueryPerformanceCounter(&curr_time);
	if (frequency.QuadPart == NULL)
		QueryPerformanceFrequency(&frequency);

	if (prev_time.QuadPart == NULL)
		prev_time.QuadPart = 0;

	delta_time = (curr_time.QuadPart - prev_time.QuadPart) / frequency.QuadPart;

	prev_time = curr_time;
}

/*
********************************************************************************************************
*
* ASPECT RATIO
*
********************************************************************************************************
*/

float get_aspect_ratio()
{
	return (float)window_width / window_height;
}

/*
********************************************************************************************************
*
* EFFECTS
*
********************************************************************************************************
*/

void create_effect()
{
	ID3DBlob* effect_blob;
	ID3DBlob* error_blob;
	HRESULT hr = D3DCompileFromFile(L"my_shader.fx", NULL, NULL, 0, "fx_5_0", 0, 0, &effect_blob, &error_blob);

	if (FAILED(hr))
	{
		MessageBox(NULL, L"D3DCompileFromFile failed", L"Error", MB_OK);
	}

	hr = D3DX11CreateEffectFromMemory(effect_blob->GetBufferPointer(), effect_blob->GetBufferSize(), 0, device, &effect);

	if (FAILED(hr))
		MessageBox(NULL, L"CreateEffectFromMemory failed", L"Error", MB_OK);
}

/*
********************************************************************************************************
*
* CAMERA CLASS
*
********************************************************************************************************
*/

camera::camera()
	: position_vector(0.0f, 0.0f, 0.0f),
	right_vector(1.0f, 0.0f, 0.0f),
	up_vector(0.0f, 0.1f, 0.0f),
	look_vector(0.0f, 0.0f, 1.0f)
{
	XMMATRIX identity = XMMatrixIdentity();
	XMStoreFloat4x4(&world_matrix, identity);

	set_perspective_matrix(0.25*XM_PI, get_aspect_ratio(), 1.0f, 1000.0f);
	update_view_matrix();
}

void camera::set_perspective_matrix(float fov, float aspect_ratio, float near_z, float far_z)
{
	XMMATRIX perspective = XMMatrixPerspectiveFovLH(fov, aspect_ratio, near_z, far_z);
	XMStoreFloat4x4(&projection_matrix, perspective);
}

void camera::update_view_matrix()
{
	XMVECTOR right = XMLoadFloat3(&right_vector);
	XMVECTOR up = XMLoadFloat3(&up_vector);
	XMVECTOR look = XMLoadFloat3(&look_vector);
	XMVECTOR position = XMLoadFloat3(&position_vector);

	look = XMVector3Normalize(look);
	up = XMVector3Normalize(XMVector3Cross(look, right));

	right = XMVector3Cross(up, look);

	XMStoreFloat3(&right_vector, right);
	XMStoreFloat3(&up_vector, up);
	XMStoreFloat3(&look_vector, look);

	XMMATRIX view = XMMatrixLookAtLH(position, look, up);
	XMStoreFloat4x4(&view_matrix, view);
}

void camera::walk(float move_speed)
{
	XMVECTOR speed = XMVectorReplicate(move_speed);
	XMVECTOR look = XMLoadFloat3(&look_vector);
	XMVECTOR position = XMLoadFloat3(&position_vector);

	XMStoreFloat3(&position_vector, XMVectorMultiplyAdd(speed, look, position));
}

void camera::strafe(float move_speed)
{
	XMVECTOR speed = XMVectorReplicate(move_speed);
	XMVECTOR right = XMLoadFloat3(&right_vector);
	XMVECTOR position = XMLoadFloat3(&position_vector);

	XMStoreFloat3(&position_vector, XMVectorMultiplyAdd(speed, right, position));
}

XMMATRIX camera::get_world_view_proj()
{
	XMMATRIX world = XMLoadFloat4x4(&world_matrix);
	XMMATRIX view = XMLoadFloat4x4(&view_matrix);
	XMMATRIX proj = XMLoadFloat4x4(&projection_matrix);

	return world*view*proj;
}
cbuffer cb_per_frame : register(b0)
{
	float4x4 world_view_proj;
};


float4 VS(float4 Pos : POSITION) : SV_POSITION
{
	return Pos;
}


float4 PS(float4 Pos : SV_POSITION) : SV_Target
{
	return float4(1.0f, 0.0f, 1.0f, 1.0f); 
}

Share this post


Link to post
Share on other sites
Advertisement

The answer is that the View matrix is your camera, so move the view matrix. Keep in mind that it is inversed. So if you translate it, invert the translation matrix before combining it with the view matrix. In your case, you're building the View matrix every frame using LookAt. In that case, just change the position.

 

The problem as to why you aren't seeing any movement is your shader. You need a shader that takes a world, view, and projection matrix and combines them through multiplication.

 

Try starting by multiplying your vertex position in your vertex shader (VS) with the world_view_proj matrix. See if that alone works.

 

You might want to watch my HLSL video series to learn more about programming shaders. The third video in the series covers a shader similar to the one you have here. The series builds on the same shader throughout to make the shader more and more complicated (and capable). The shader at the end of the series is the foundation for shaders you will use most with all your projects. I multiply the View, Projection, and World matrix together in the shader. You appear to multiply them outside the shader, which is fine for some things and actually more efficient than repeating the same operation in the shader over and over. But in latter videos I use some of the info from the separate matrices. Either way, you need to multiply them times the vertex position in the shader.

 

The shader you have above will draw the model in the place where it was created every frame and does not allow for movement of the camera. It assumes you are drawing in Normalized Device Coordinates.

 

You may also want to check out my DX11 sample code on my website at VirtuallyProgramming.com. The Essential DX example keeps things relatively simple. But it has a working simple shader and code. Again, each project there builds on the last where I'm adding more and more complexity and capability. That way you can see how to just get things working, before trying the more complex and capable code. I believe Essential DX will just allow you to place very simply colored objects in the scene and move the camera around the scene and little more. Texturing allows you to add DDS photographs as textures on the objects rather than coloring them with vertex colors. These are all hand coded objects and so they are simple cubes and such. Even a cube takes a lot of time to model by hand like this. The SkyBox example makes a sky for your scene. And then I never fully completed the series, but the final examples use Python scripts to export data from Blender (where you can make far more complex models) and import it into DX to create a Model class for complex 3D models. I think the final code there is mostly finished. My main computer crashed and I lost everything. I can't remember if that last example has the code completely cleaned up and ready or not, but it's at least a version that's very close. It just may not be commented as much as it should be. But it's done function wise. It turned out to be my "backup" of the code and what I have on my computer now is a copy that I downloaded from my own website.

 

I might mention that the example programs are a very basic game engine designed to be much like XNA where you modify the Game class to create the game and all the rest of the classes are engine code that stays the same for every project. The Game class's Initialize is for startup code, Load is for loading art assets, Draw is for any code that draws in the current frame, and the Update method is for all other game code this frame that runs in the game loop. Generally, you would write your own classes and call them from the Game class as appropriate. The Game class inherits from the DirectX11Game class to gain it's functionality and the structure of the Game class. But all the other classes are only 1 level deep with no inheritance. Notice that there is no camera class. You could create one, but I move the camera just by manipulating the View matrix.

 

And then I decided I was going to do OpenGL instead. :-) So, that's as far as I went with it. Now I'm working on rewriting the same engine in OGL with the same shader in GLSL.

Edited by BBeck

Share this post


Link to post
Share on other sites

1. You never call update_view_matrix so the view matrix is never updated based on position_vector.

2. You never update the cb_per_frame constant buffer.

3. Your shader doesn't even use the world_view_proj matrix.

Share this post


Link to post
Share on other sites

Thanks for the replies guys. And Syntac, I tried all of that before I posted but I wasn't sure how to do it and maybe a mistake was made because I couldn't get the camera to move.

 

Could one of you guys add in what I need and post the code? That would help alot.   :D

Share this post


Link to post
Share on other sites

Thanks for the replies guys. And Syntac, I tried all of that before I posted but I wasn't sure how to do it and maybe a mistake was made because I couldn't get the camera to move.

 

Could one of you guys add in what I need and post the code? That would help alot.   :D

 

Why don't you show us what you had before?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement