Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Enerjak

Member Since 08 Nov 2007
Offline Last Active Jan 14 2015 10:25 PM

Topics I've Started

Checking the equality of objects in C#

14 January 2015 - 03:46 PM

I don't think the title explains my problem quite well, but.... What I'm having problems with is this: 

 

I have a class named Person.cs:

class Person : Object
    {
        protected Name m_personName;
        protected string m_state;
        protected string m_zipCode;
        protected string m_PhoneNumber;
        protected string m_address;
        protected string m_age;
        public Person()
        {
            m_personName = new Name();
            m_state = "New Jersey";
            m_zipCode = "08731";
            m_PhoneNumber = "(609)-255-1122";
            m_address = "316 Bridge Drive";
            m_age = "30";
        }

        public Person(string firstName,
            string lastName,
            string state,
            string zipCode,
            string phoneNumber,
            string address,
            string age)
        {
            m_personName = new Name(firstName, lastName);
            m_state = state;
            m_zipCode = zipCode;
            m_PhoneNumber = phoneNumber;
            m_address = address;
            m_age = age;
        }

        public void setName(string firstName, string lastName)
        {
            m_personName.setFirstName(firstName);
            m_personName.setLastName(lastName);
        }

        public void setName(Name name)
        {
            m_personName = name;
        }

        public Name getName()
        {
            return m_personName;
        }

        public void setAddress(string address)
        {
            m_address = address;
        }

        public string getAddress()
        {
            return m_address;
        }

        public void setPhoneNumber(string phoneNumber)
        {
            m_PhoneNumber = phoneNumber;
        }

        public string getPhoneNumber()
        {
            return m_PhoneNumber;
        }

        public void setState(string state)
        {
            m_state = state;
        }

        public string getState()
        {
            return m_state;
        }

        public void setZipCode(string ZipCode)
        {
            m_zipCode = ZipCode;
        }

        public string getZipCode()
        {
            return m_zipCode;
        }

        public void setAge(string age)
        {
            m_age = age;
        }

        public string getAge()
        {
            return m_age;
        }
        public bool CompareTo(Person p)
        {
            if(this.getName() == p.getName() &&
               this.getAddress() == p.getAddress() &&
               this.getAge() == p.getAge() &&
                this.getState() == p.getState() &&
                this.getPhoneNumber() == p.getPhoneNumber() &&
                this.getZipCode() == p.getZipCode())
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }

I also have a class named - fittingly - Name.cs

 class Name
    {
        protected string FirstName;
        protected string LastName;

        public Name()
        {
            FirstName = "";
            LastName = "";
        }

        public Name(string firstName, string lastName)
        {
            FirstName = firstName;
            LastName = lastName;
        }
        public void setFirstName(string fName)
        {
            FirstName = fName;
        }

        public String getFirstName()
        {
            return FirstName;
        }

        public void setLastName(string lName)
        {
            LastName = lName;
        }

        public string getLastName()
        {
            return LastName;
        }

    }

Now I have a List<Person> variable used to add a new person to the array that is List<Person>, the entry is added to the array, that's not the problem, the problem is searching the array for a specific value:

     String firstName = TBFirstNameSearch.Text;
            String lastName = TBLastNameSearch.Text;
            String Age = TBAgeSearch.Text;
            String Address = TBAddressSearch.Text;
            String State = TBStateSearch.Text;
            String PhoneNumber = TBPhoneNumberSearch.Text;
            String ZipCode = TBZipCodeSearch.Text;
            Person pSearch = new Person(firstName, lastName, State, ZipCode, PhoneNumber, Address, Age);

            if (m_people.Count > 0)
            {
                MessageBox.Show("people count: " + m_people.Count);
                for (int i = 0; i < m_people.Count; i++)
                {
                   if(pSearch.getName().getFirstName() == m_people[i].getName().getFirstName() &&
                       pSearch.getName().getLastName() == m_people[i].getName().getLastName() &&
                       pSearch.getAge() == m_people[i].getAge() &&
                       pSearch.getAddress() == m_people[i].getAddress() &&
                       pSearch.getState() == m_people[i].getState() &&
                       pSearch.getZipCode() == m_people[i].getZipCode() &&
                       pSearch.getPhoneNumber() == m_people[i].getPhoneNumber())
                   {
                       Person p = m_people[i];
                       String person = "";
                       person += "First Name: " + p.getName().getFirstName() + "\n"
                                + "Last Name: " + p.getName().getLastName() + "\n"
                                + "Age: " + p.getAge() + "\n"
                                + "Address: " + p.getAddress() + "\n"
                                + "State: " + p.getState() + "\n"
                                + "Phone Number: " + p.getPhoneNumber() + "\n"
                                + "Zip Code: " + p.getZipCode() + "\n";
                       MessageBox.Show(person, "Found", MessageBoxButtons.OK);
                   }
                   else
                   {
                       MessageBox.Show("Could not find entry");
                   }
                }
                TBFirstNameSearch.Text = "";
                TBLastNameSearch.Text = "";
                TBAgeSearch.Text = "";
                TBZipCodeSearch.Text = "";
                TBAddressSearch.Text = "";
                TBStateSearch.Text = "";
                TBPhoneNumberSearch.Text = "";
            }
            else
            {
                MessageBox.Show("There's nothing in the list. Size: " + m_people.Count);
            }

This is inside of button click event. Basically, after I add a new entry to the array, I search the list for that same item but it isn't found. The item is added, as I said. One quick print of the list/array. Getting the count of the list/array shows a number of 1 meaning the entry has been added. If you do a for-loop of the list / array, it'll print all entries. Searching is......not working. Please let me know how to fix this. This is from a simple address book GUI I decided to make since it's never a bad thing to know more than one language. 

 

EDIT: Sorry, went on a rant there....


Some help using vertex buffer with std::vector.

17 December 2014 - 10:18 PM

I'm trying to use a vector to create a vertex array and copy it into a vertex buffer, but so far, it is not working as well as I would have hoped.... Only one vertex is being copied into the vertex buffer and not the rest of vertices. I wonder , what I am doing wrong? Here's my code:

 

Renderable.h:

#ifndef RENDERABLE_H
#define RENDERABLE_H

#include "EnginePrerequisites.h"
#include "VertexP.h"
#include "VertexPC.h"
#include "VertexPT.h"

namespace DemEngine
{
	using namespace DemMath;
	using namespace DemGeometry;

	typedef std::vector<VertexP> VertexPos;
	typedef std::vector<VertexPC> VertexPosColor;
	typedef std::vector<VertexPT> VertexPosTexture;

	typedef enum DEM_VERTEX_TYPE
	{
		DVT_POSITION_ONLY = 0,
		DVT_POSITION_COLOR = 1,
		DVT_POSITION_TEXTURE = 2
	} DEM_VERTEX_TYPE;
	class Renderable
	{
	protected:
		DemString m_renderableName;
		Material* m_renMat;
		HardwareVertexBuffer* m_vertBuffer;
		VertexDeclaration*    m_vertDecl;
		RenderSystem*		  m_renderSystem;
		VertexPos             m_posVector;
		VertexPosColor		  m_posColor;
		VertexPosTexture      m_posTexture;
		DEM_VERTEX_TYPE       m_vertType;
		DEM_PRIMITIVE_TYPE    m_primitiveType;
		DemUINT				  m_numVertices;
		DemUINT				  m_firstVertex;
	public:
		Renderable(DemString renName);

		virtual ~Renderable();

		// used to create the renderable.
		virtual bool createRenderable(DemString name) = 0;

		// virtual draw function.
		virtual void draw() = 0;

		// set vertex.
		// this only sets the position of the vertex.
		void setVertex(DemReal x, DemReal y, DemReal z);
		
		// set vertex.
		// this sets position and texture.
		void setVertex(DemReal x, DemReal y, DemReal z, DemReal u, DemReal v);

		// set vertex.
		// this sets position and color.
		void setVertex(DemReal x, DemReal y, DemReal z, DemDWORD color);

		// get number of vertices.
		DemUINT getNumVertices() const; 

		// get Primitive type.
		DEM_PRIMITIVE_TYPE getPrimitiveType() const;

		// set primitive type.
		void setPrimitiveType(DEM_PRIMITIVE_TYPE pType);

		// set the vertex type.
		void setVertexType(DEM_VERTEX_TYPE vType);

		// get the vertex type.
		DEM_VERTEX_TYPE getVertexType() const;

		HardwareVertexBuffer* getVertexBuffer() const { return m_vertBuffer; }
	};
}

#endif

Renderable.cpp

#include "Renderable.h"
#include "RenderSystem.h"
#include "RenderSystemManager.h"

namespace DemEngine
{
	Renderable::Renderable(DemString renName)
		: m_renderableName(renName)
	{
		m_numVertices = 0;		// set number of vertices to 0.
		//m_vertType = DVT_POSITION_ONLY; // position only.
		m_vertType = DVT_POSITION_COLOR;
		m_primitiveType = DPT_TRIANGLELIST; // draw triangle list.
		m_vertDecl = NULL;				// vertex declaration.
		m_vertBuffer = NULL;			// vertex buffer.
		m_renderSystem = RenderSystemManager::getInstancePtr()->getActiveRenderSystem();
	}

	Renderable::~Renderable()
	{

	}

	bool Renderable::createRenderable(DemString name)
	{
		return true;
	}

	void Renderable::draw()
	{

	}

	void Renderable::setPrimitiveType(DEM_PRIMITIVE_TYPE pType)
	{
		m_primitiveType = pType; 
	}

	DEM_PRIMITIVE_TYPE Renderable::getPrimitiveType() const
	{
		return m_primitiveType;
	}

	void Renderable::setVertexType(DEM_VERTEX_TYPE vType)
	{
		m_vertType = vType;
	}

	DEM_VERTEX_TYPE Renderable::getVertexType() const
	{
		return m_vertType;
	}

	void Renderable::setVertex(DemReal x, DemReal y, DemReal z)
	{
		VertexP vert;
		vert.setVertex(x, y, z);
		m_posVector.push_back(vert);
		m_numVertices += 1;
	}

	void Renderable::setVertex(DemReal x, DemReal y, DemReal z, DemDWORD color)
	{
		VertexPC vertColor;
		vertColor.setVertex(x, y, z, color);
		m_posColor.push_back(vertColor);
		m_numVertices += 1;
	}

	void Renderable::setVertex(DemReal x, DemReal y, DemReal z, DemReal u, DemReal v)
	{
		VertexPT vertTex;
		vertTex.setVertex(x, y, z, u, v);
		m_posTexture.push_back(vertTex);
		m_numVertices += 1;
	}

	DemUINT Renderable::getNumVertices() const
	{
		return m_numVertices;
	}
}

Triangle.h

#ifndef TRIANGLE_H
#define TRIANGLE_H

#include "EnginePrerequisites.h"
#include "Renderable.h"

namespace DemEngine
{
namespace DemMath
{
namespace DemGeometry
{
	class Triangle : public Renderable
	{
	public:
		Triangle(DemString name);

		~Triangle();

		bool createRenderable(DemString name);

		bool createTriangle(DemReal x1, DemReal y1, DemReal z1,
			DemReal x2, DemReal y2, DemReal z2,
			DemReal x3, DemReal y3, DemReal z3);

		bool createTriangle(DemReal x1, DemReal y1, DemReal z1, DemDWORD color1,
			DemReal x2, DemReal y2, DemReal z2, DemDWORD color2,
			DemReal x3, DemReal y3, DemReal z3, DemDWORD color3);

		void draw();
	};
}
}
}
#endif

and....

 

Triangle.cpp:

#include "Triangle.h"
#include "RenderSystem.h"
#include "RenderSystemManager.h"
#include "VertexDeclaration.h"
#include "HardwareVertexBuffer.h"
namespace DemEngine
{
namespace DemMath
{
namespace DemGeometry
{
	Triangle::Triangle(DemString name)
		:Renderable(name)
	{

	}

	Triangle::~Triangle()
	{

	}

	bool Triangle::createRenderable(DemString name)
	{
		return true;
	}

	bool Triangle::createTriangle(DemReal x1, DemReal y1, DemReal z1, DemDWORD color1, DemReal x2, DemReal y2, DemReal z2, DemDWORD color2, DemReal x3, DemReal y3, DemReal z3, DemDWORD color3)
	{
		this->setVertex(x1, y1, z1, color1);
		this->setVertex(x2, y2, z2, color2);
		this->setVertex(x3, y3, z3, color3);

		DWORD bufferSize = static_cast<DWORD>(m_posColor.size()) * sizeof(VertexPC);
		this->m_vertBuffer = m_renderSystem->createHardwareVertexBuffer(bufferSize,
			0,
			0,
			0);

		
		VertexPC verts;
		for (DemUINT x = 0; x < m_numVertices; ++x)
		{
			verts = m_posColor[x];
		}
		void* data = 0;
		m_vertBuffer->lock(0, 0, (void**)&data, 0);
		memcpy(data, &verts, sizeof(VertexPC));
		m_vertBuffer->unlock();

		m_vertDecl = m_renderSystem->createVertexDeclaration(m_renderableName);
		m_vertDecl->setElement(0, 0, DVD_FLOAT3, DDM_DEFAULT, DDU_POSITION, 0);
		m_vertDecl->setElement(0, 12, DVD_DEMCOLOR, DDM_DEFAULT, DDU_COLOR, 0);
		m_vertDecl->updateDeclaration();

		return true;
	}

	void Triangle::draw()
	{
		m_renderSystem->setHardwareVertexBuffer(0, this->m_vertBuffer, 0, sizeof(VertexPC));
		m_renderSystem->setVertexDeclaration();
		m_renderSystem->renderPrimitive(this);
	}
}
}
}

I have no idea what to do.....I print out the values in the vector and only one vertex seems to have been copied. What am I doing wrong?


Generating a checkered pattern via dynamic textures in D3D9

22 October 2014 - 03:36 PM

I haven't been on here in awhile, anyways, I need some assistance with creating a checkered pattern texture to use as a default texture when textures can't be loaded from disk. I am using this code:

D3DLOCKED_RECT lockRect;
		d3dText->LockRect(0, &lockRect, 0, D3DLOCK_DISCARD);

		for (unsigned int i = 1; i <= d3dText->Width / 64; ++i)
		{
			for (unsigned int j = 1; j <= d3dText->Height / 64; ++j)
			{
				BYTE* data = (BYTE*)lockRect.pBits;
				int index = i * lockRect.Pitch / 4 + j;

				if ((i + j % 2) == 1)
				{
					data[index++] = 255;
					data[index++] = 0;
					data[index++] = 0;
					data[index++] = 255;
				}
				else
				{
					data[index++] = 255;
					data[index++] = 255;
					data[index++] = 255;
					data[index++] = 255;
				}
			}
		}
		d3dText->UnlockRect(0);

the texture is dynamic and everything but when I try to save it for debugging purposes, the texture's just......white. Nothing wrong with that but I need a checkered pattern to use as a default texture.


Having a problem getting data from .obj file to render (index / Vertex buffer prob)

09 July 2014 - 06:19 PM

I've tried everything I could think of, every possible thing and yet, I can't get the .obj mesh to render. It gets all the vertices and indices (I think.) But when I try to pass it on to DIrect3D9's vertex and index buffers, it.....doesn't go well. Here's a few links and my explanation.

 

meshobj.cpp file:

 

(note: to keep this post short, I'll be using pastbin for code.)

 

http://pastebin.com/BJMRFHJQ

 

mesh.obj file:

 

http://pastebin.com/mPtbENV9

 

and finally: a screen shot of what PIX shows.....

 

http://puu.sh/a4oEB/429942ff81.png

 

as you can see, the vertices don't seem to be pushed through the pipeline right...I've given all I can give to explain this problem. If you could help me out, I'd appreciate it. let me know if you need to see something else.

 

 


Having trouble with my Vertex Element Class

03 May 2014 - 12:43 AM

OK, I'm trying to make it so all you have to do to add a new vertex element is this:

void Shape::setVertexElement(string semanticName, unsigned int semanticIndex, unsigned int format, unsigned int inputSlot, unsigned int inputSlotClass, unsigned int alignedByteOffset, unsigned int instanceDataStepRate)
{
	VertexElement* vertElem = new VertexElement(semanticName, semanticIndex, format, inputSlot, inputSlotClass, alignedByteOffset, instanceDataStepRate);
	
	m_vertexElements.push_back(*vertElem);
}

than, updating them like this:

void Shape::createInputlayout()
{
	D3D11_INPUT_ELEMENT_DESC* elemDesc = new D3D11_INPUT_ELEMENT_DESC[this->m_vertexElements.size() - 1];

	VertexElements::iterator i;
	unsigned int x;
	for (x = 0, i = m_vertexElements.begin(); i != m_vertexElements.end(); ++i, ++x)
	{
		elemDesc[x].SemanticName = static_cast<LPCSTR>(i->getSemanticName().c_str());
		elemDesc[x].SemanticIndex = i->getSemanticIndex();
		elemDesc[x].Format = static_cast<DXGI_FORMAT>(i->getFormat());
		elemDesc[x].InputSlot = i->getInputslot();
		elemDesc[x].InputSlotClass = static_cast<D3D11_INPUT_CLASSIFICATION>(i->getInputSlotClass());
		elemDesc[x].InstanceDataStepRate = i->getInstanceDataStepRate();
		elemDesc[x].AlignedByteOffset = i->getAlignedByteOffset();
		
	
	}
	if (m_hardwareMaterial != NULL)
	{
		HRESULT hr = m_device->CreateInputLayout(elemDesc, (unsigned int)m_vertexElements.size(), m_hardwareMaterial->getVertexShaderBlob()->GetBufferPointer(), m_hardwareMaterial->getVertexShaderBlob()->GetBufferSize(), &m_inputlayout);

		if (FAILED(hr))
		{
			const char* err = DXGetErrorDescriptionA(hr);

			MessageBoxA(NULL, err, NULL, MB_OK);
			return;
		}
		m_devContext->IASetInputLayout(m_inputlayout);
	}

	
}

How ever, for some reason, Direct3D says this:

D3D11 ERROR: ID3D11Device::CreateInputLayout: Element[1] and Element[0] have the same Semantic ( 0).  All Semantics in the Input Layout must be unique.  This error is only printed on the first occurence detected. [ STATE_CREATION ERROR #160: CREATEINPUTLAYOUT_DUPLICATESEMANTIC]

It seems like the string from the class isn't updating right. I wonder if I'm doing it wrong or you can't do it this way. (I was trying to do it like Ogre's vertex declaration, but they do it with Direct3D9. I thought it would be the same concept, since all you'd have to do is iterator through the vector and set the elements[x] to what ever the iterator holds.)


PARTNERS