'object' does not contain a constructor that takes 3 arguments - constructor

I'm trying my hand at generating spherical terrain in XNA 4.0, and am using an Icosahedron to achieve a sphere with evenly-distributed vertices. I'm fairly new to Xna, and I'm running into this problem trying to create a class that will handle defining all the vertices for the sphere.
here's the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Icosahedron_Test
{
class Icosahedron
{
public Icosahedron(int radius, int refinement, Vector3[] vertices)
: base(radius, refinement, vertices)
{
}
}
}
also, if anyone knows how to create an icosahedron, or can direct me to a tutorial, I'd be really grateful XD

In your code example, you are defining a new class called Icosahedron.
The code you provided is called a Constructor, which is a special method that is used to instantiate new objects.
public Icosahedron(int radius, int refinement, Vector3[] vertices)
: base(radius, refinement, vertices)
When writing
: base( .... )
You are attempting to call a base call of the current class you're defining.
C# supports a mechanism called Inheritance, which allows extending an object's behavior by extending another class. This can be used for adding/overriding some of the parent object's behavior and abilities.
In C#, all objects are derived from System.Object, and so, in your code you are attempting to call System.Object's constructor with 3 parameters, but this constructor method does not exist for System.Object.
You need to get a good reading on C# to get a grip on the basics :)

Your Icosahedron inherits object.
As the error message clearly states, you can't call base(...), since object doesn't have such a constructor.

Related

Problem with trigger in OntTriggerEnter2D in unity

I have a two objects, both of them have : rigidbody2D of type dynamic, collider2D set to trigger, same layer, same Z position. But they do not collider with each other. One of them has a simple script attached, which contains function OnTriggerEnter2D, which just debug.log some message. As you can guess the console doesn't print the message. No errors tho. Please help! I've also tried to restart unity, even the PC - doesn't work as well.
function :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
private void OnTriggerEnter2D(Collider2D collision)
{
Debug.Log("DUOA");
}
}
Have a look at the Collision action matrix, you will not receive a trigger call from two dynamic Rigidbodies that both have a trigger collider component.
Change one of the Rigidbody types to Kinematic, which should resolve your issue.

Why things are so different in a driver class ("static void main") and a class definition?

I know some of the terms I use are confusing. To clarify, a driver class is basically one built on a class definition (starting with public class...) but is a method itself with the header public static void main (String args[]).
The point of this post is to resolve my serious confusion. (I am a beginner in programming)
to me, since a driver class is a method, all it does is to implement itself. But things kinda turn out to be the opposite . For example:
to implement a constructor in a driver class, you simply put down the constructor heading, like public Rectangle(), with its name being the same as that of the class. but in a class definition, to creat a object/ implement a constructor, you also have to write down happen inside that constructor, so you use the expression "type name = new type name ()".
PS: I might have used some terms wrongly, correct me thanks. Or some concept
I'll try to answer this the best way that I can.
Let's look at each of the keywords in a "driver class method" and determine the meaning.
public - this method is publicly callable by a class outside of it
static - this method is callable WITHOUT an instance of the class. In Java, look at the Math class. You don't need to instantiate an instance of the Math class to use the sqrt function (Math m = New Math(); m.sqrt(25);), you can just use Math.sqrt(25).
void - this method returns nothing
main - name of the method
Now that we have that cleared up, let's ask ourselves why these things have to be here for a "driver class"
The Virtual Machine (the program that runs your custom programs) is hard coded to look for a method named main that is public and can also be called WITHOUT CREATING AN INSTANCE OF YOUR CLASS.
So this means that when your program first runs, there is no instance of it.
To counter this, you can either create all of your methods and properties as static (generally considered bad practice) OR you can create an instance of your own class inside of it's own entry method, and begin to call the non-static methods and properties that belong to the instance.
I hope this makes sense.

CX view of C++ classes

I'm writing a program that has a portable C++ backend that we want to create a WinRT Xaml frontend for. I want to keep our models in pure C++ code and create a view in C++/CX that mirrors the C++ model that we can pass around and consume on the frontend. Is there any standard method for this?
For example:
class Person
{
public:
const std::wstring GetName() const;
void SetName(const std::wstring& value);
private:
std::wstring m_Name;
}
ref class PersonMirror : INotifyPropertyChanged
{
public:
property Platform::String^ Name
{
Platform::String^ get();
void set(Platform::String^ value);
}
private:
std::shared_ptr<Person> m_Person;
}
Some things I don't know how to do in this are:
How I get the associated ref mirror class from the native class. can I convert a void* to a PersonMirror^ and talk to the GC about holding a reference to the object?
Are there C++ implementations for triggering events? Or I guess if I can maintain that this is a 1-to-1 relationship, I can just use a function pointer perhaps?
You cannot simply convert a void* to a PersonMirror^. You have to use "ref new" to create a WinRT instance of the class and then copy the data (or a pointer to it) from Person into the PersonMirror. You can have a PersonMirror constructor that copies individual fields from the ISO C++ class, or you can just copy a shared_ptr as you have done, and provide public accessors for it in your ref class. This is a nice approach. Note: There is no "GC" in C++/CX; a ref class is basically just a smart pointer.
• You can use whatever eventing mechanism you like between a ref class and an ISO C++ class in the same process. The only restriction is that any public types in the ref class must be WinRT compatible. To expose a callback or function object event handler in PersonMirror, give it internal accessibilty so that it is invisible to the WinRT interface, but your ISO code can still access it.
The Reversi sample on MSDN demonstrates an ISO C++ class that is wrapped by a C++/CX wrapper class.

Calling C# method from C++ code in WP8

I'm interested in calling a C# method from C++ code in Windows Phone 8. I have already learned how to pass a callback function to C++ code from C# via delegate declarations in my C++ code, but I am looking to see if I can do any of the following:
Call certain methods directly from the C++ code. This would involve somehow inspecting the C# object makeup from C++, and seems unlikely to me, but I thought I'd ask you all anyway
Trigger events in the C# code, which can then be handled by C# methods
Use a dispatcher to call C# callbacks in the Main UI thread so that the callbacks can modify UI elements
Use a dispatcher to trigger events in the C# code, (Essentially a merging of the above two points)
In short, I am looking for as many C++ -->C# communication tips as you guys can throw me, I want to learn it all. :)
By getting an object in C# code to implement a Windows RT interface, and passing down a reference to this object, it is possible to do all of the above with a bit of set-up (if I understand correctly - not sure about exactly what you want to do with your Dispatcher examples - you might want to wrap the Dispatcher on the C# side).
Create a Windows Runtime component library.
Define a public interface class in a C++/CX header for the C# to implement (C++ to call) (e.g. ICallback).
Define a public ref class in a C++/CX header for the C++ to implement (C# to call) (e.g. CppCxClass).
Add a method in CppCxClass that passes and stores an ICallback. (A C++ global variable is shown for consiseness, I recommend you review this to see if you can find a better place to store this in your code-base).
ICallback^ globalCallback;
...
void CppCxClass::SetCallback(ICallback ^callback)
{
globalCallback = callback;
}
Reference the WinRT library in your C# code.
C# code: create an instance of CppCxClass using var cppObject = new CppCxClass().
C# code: create a class which implements ICallback (e.g. CSharpCallbackObject).
C# code: pass an instance of CSharpCallbackObject down to C++. E.g. cppObject.SetCallback(new CSharpCallbackObject()).
You can now call C# with globalCallback->CallCsharp(L"Hello C#");. You should be able to extend either ICallback and/or CppCxObject to do the rest of your tasks.
After a lot of headaches trying to figure out the required code, I think it's worth posting the final version here
C++/CX
//.h
[Windows::Foundation::Metadata::WebHostHidden]
public interface class ICallback
{
public:
virtual void Exec( Platform::String ^Command, Platform::String ^Param);
};
//.cpp
ICallback ^CSCallback = nullptr;
void Direct3DInterop::SetCallback( ICallback ^Callback)
{
CSCallback = Callback;
}
//...
if (CSCallback != nullptr)
CSCallback->Exec( "Command", "Param" );
C#
public class CallbackImpl : ICallback
{
public void Exec(String Command, String Param)
{
//Execute some C# code, if you call UI stuff you will need to call this too
//Deployment.Current.Dispatcher.BeginInvoke(() => {
// //Lambda code
//}
}
}
//...
CallbackImpl CI = new CallbackImpl();
D3DComponent.SetCallback( CI);

Is it possible to intercept attribute getting/setting in ActionScript 3?

When developing in ActionScript 3, I often find myself looking for a way to achieve something similar to what is offered by python's __getattr__ / __setattr__ magic methods i.e. to be able to intercept attribute lookup on an instance, and do something custom.
Is there some acceptable way to achieve this in ActionScript 3? In AS3 attribute lookup behaves a little differently for normal (sealed) and dynamic classes -- ideally this would work in the same way for both cases. In python this works beautifully for all kinds of objects (of course!) even for subclasses of dict itself!
Look a the flash.utils.Proxy object.
The Proxy class lets you override the
default behavior of ActionScript
operations (such as retrieving and
modifying properties) on an object.
In AS3 you can code explicit variables accessors.
Example Class1:
private var __myvar:String;
public function get myvar():String { return __myvar; }
public function set myvar(value:String):void { __myvar = value; }
Now as you create an instance of Class1 you can access __myvar through the accessor functions.
if you want to set bindable that var you have to put the [Bindable] keyword upon one of its accessors.
Further, you can also implement the getter or the setter only, so your var will be read or write only.
I hope it helps.